infoclogged
infoclogged

Reputation: 3997

gitlab api fork projects as root

I am logged in as root using gitlab-api with Python. On the server, I have a git repository which consists of my template ( example ) code. This template code is however not under Adminstrator, but under my own namespace ( teacher/template) . I want to distribute this template project to 25 students as an assignment i.e fork this template to 25 additional projects, but in a different namespace/group such as StudentsGroup/assignment1, StudentsGroup/assignment2... and soforth.

Can anyone tell me what is the best way to achieve it?

In the gitlab api, I have seen two possibilities:

First option:

Admin fork relation

Allows modification of the forked relationship between existing projects. Available only for admins. Create a forked from/to relation between existing projects.

POST /projects/:id/fork/:forked_from_id

Parameters:

id (required) - The ID of the project
forked_from_id: (required) - The ID of the project that was forked from

Second option:

Fork project

Forks a project into the user namespace of the authenticated user.

POST /projects/fork/:id

Parameters:

id (required) - The ID of the project to be forked

Upvotes: 0

Views: 917

Answers (2)

infoclogged
infoclogged

Reputation: 3997

As of today 06, Sep, 2015, no solution is available. So, I found a workaround.

  1. Clone the Teacher/template.git into the local disk.

Begin a for loop:

  1. Create empty Students/jobs_{count}.git in using the normal create project API

  2. In the local disk, keep changing the remote origin in a script file, like git remote set-url origin git@server:Students/jobs_{count}.git

  3. Push the files git push origin master

End of for loop

If anyone is interested in the script, you can ping me or will upload it later after removing the credentials.

Upvotes: 0

Tobias Weber
Tobias Weber

Reputation: 21

If you have gitlab-admin rights, the first option is at the moment the only way to achieve this.

But there is an issue (https://gitlab.com/gitlab-org/gitlab-ce/issues/21591) and a merge request (https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6213) to add a namespace_id param to the second option. If we are lucky, the next gitlab version (8.12) will add this feature (gitlab normally releases each 22nd of a month).

Upvotes: 2

Related Questions