Search code examples
springspring-bootgitlabgitlab-api

Fork project gitlab


I am trying to get a copy of project from specific subgroup and create new project with this copy in another subgroup under the same group. note:- I suppose to know the path for the target project to be created from variables I will get from database so I cannot use subgroup id directly.

var project = gitLabApi.getGroupApi().getGroup("parent-group/subgroup1/sub2/sub3/lastSubgroup").getProjects().get(0);

Here I got the project correctly. my issue with copying it in another subgroup path

gitLabApi.getProjectApi().createProject("testname",gitLabApi.getGroupApi().getGroup("parent-group/targetsubgroup1/targetsub2/../targetlastSubgroup").getPath()).setForkedFromProject(project);

It runs the command but I cannot see any forked project created. when I add the path as string path I get validation error in path.

Itried also

Project newProject = gitLabApi.getProjectApi().forkProject(project.getId(),gitLabApi.getGroupApi().getGroup("parent-group/targetsubgroup1/targetsub2/../targetlastSubgroup").getProjects().get(0).getNamespace().getName(),gitLabApi.getGroupApi().getGroup("parent-group/targetsubgroup1/targetsub2/../targetlastSubgroup","projnameSara");

I got 404 not found namespace


Solution

  • I find the solution for my issue.

    • first you have to make sure that the user you use in Gitlab has a maintainer permission.
    • then I got the project as I want from group or from project path with var called "project".
    • then used gitLabApi.getProjectApi().forkProject(project.getId(),gitLabApi.getGroupApi().getGroup("parentGroup/subgroup1/subgroup2/lastSubgroup").getId().toString(),"testFromPortal","testFromPortal");
    • notice that "testFromPortal" is refering to path and name for forked project.