Skip to content

Add possibility for minimal forks

Nataliia Radina requested to merge 24894-minimal-forking-fe-be into master

What does this MR do and why?

Add possibility for minimal forks

Add possibility to for projects with only default branch

Changelog: changed

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After
Screenshot_2023-08-31_at_11.51.23 Screenshot_2023-08-31_at_11.40.00

How to set up and validate locally

Frontend

  1. Go to any project
  2. Click on "Forks" button
  3. Observe the fork form
  4. Try different forking options(all branches, only main branch) and make sure that the created fork corresponds

Backend

  1. Create a new project, initialized with a README.md, I called mine lfs-mirror-test under the root name space - http://gdk.test:3000/root/lfs-mirror-test
  2. Visit http://gdk.test:3000/root/lfs-mirror-test/-/branches/new and create a new branch called wip based off main
  3. Test below using the Rails console and the API

Test via Rails console

  1. Visit http://gdk.test:3000/twitter/lfs-mirror-test to ensure it's a 404
  2. Bring in the Rails console by running gdk rails c
  3. Run the following
    name = 'lfs-mirror-test'
    current_user = User.find(1)
    project_to_fork = current_user.projects.where(name: name).first
    namespace_to_fork_into = Group.find_by_name('Twitter')
    
    fork_params = { namespace: namespace_to_fork_into, path: name, name: name, branch: 'main' }
    ::Projects::ForkService.new(project_to_fork, current_user, fork_params).execute
  4. You should now be able to visit http://gdk.test:3000/twitter/lfs-mirror-test/-/branches and only see the main branch listed

Test via API

  1. Visit http://gdk.test:3000/twitter/lfs-mirror-test to ensure it's a 404
  2. Ensure you have a PAT setup via http://gdk.test:3000/-/profile/personal_access_tokens with the api scope
  3. Run the following in a gdk rails c session to determine the necessary project IDS
    name = 'lfs-mirror-test'
    current_user = User.find(1)
    project_to_fork = current_user.projects.where(name: name).first
    namespace_to_fork_into = Group.find_by_name('Twitter')
    
    puts %Q{export SOURCE_PROJECT_ID="#{project_to_fork.id}"}
    puts %Q{export NAMESPACE_TO_FORK_INTO_ID="#{namespace_to_fork_into.id}"}
  4. Run the following from the command line:
    export TOKEN="glpat-<YOUR-TOKEN-VALUE>"
    export SOURCE_PROJECT_ID="<SEE-ABOVE>"
    export NAMESPACE_TO_FORK_INTO_ID="<SEE-ABOVE>"
    
    curl -qsv -X POST -H "PRIVATE-TOKEN: ${TOKEN}" -H "Content-Type: application/json" "http://gdk.test:3000/api/v4/projects/${SOURCE_PROJECT_ID}/fork?name=lfs-mirror-test&path=lfs-mirror-test&namespace_id=${NAMESPACE_TO_FORK_INTO_ID}&branch=main"
  5. You should now be able to visit http://gdk.test:3000/twitter/lfs-mirror-test/-/branches and only see the main branch listed

Removing forked project

Run the following to remove the forked project so you can test again:

  1. Bring in the Rails console by running gdk rails c
  2. Run the following
    name = 'lfs-mirror-test'
    current_user = User.find(1)
    project_to_fork = current_user.projects.where(name: name).first
    namespace_to_fork_into = Group.find_by_name('Twitter')
    
    ::Projects::DestroyService.new(namespace_to_fork_into.projects.where(name: name).first, current_user).execute

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #24894 (closed)

Edited by Ash McKenzie

Merge request reports