Forking and configuring project via API works very unreliable
Summary
I'm trying to use the API to create new projects from a template project. My current approach is to use the following workflow:
Prerequisites:
- I have a group called
Templates
where I added some projects that I would like to use as templates for other projects. - User provides the following data:
- Name of the new project
- Description of the new project
- Namespace where the new project should be added to
- Template he wants to use
My Script then works as follows:
- Fork the template into the desired group:
.../api/v3/projects/fork/Templates%2F<TemplateName>
with json-data containing the new namespace - Change name and description:
.../api/v3/projects/<projectId>
with json-data containing the new name and description - Add webhook:
.../api/v3/projects/<projectId>/hooks
(each project needs this for internal purposes) - Change project path: '.../api/v3/projects/' with json-data containing the name and new path
The above works in some cases, but more often it fails during a different step. Sometimes the project has no repo, other times the Path is not changed. Checking the log output everything works fine, all calls are answered with the expected results.
Steps to reproduce
See above, I tried to be as explicit as possible. If more info is needed I'll be happy to provide. I created a simple Python script with which the issue can be reproduced: https://gitlab.com/snippets/1630316 (at least on our local Gitlab, I'm currently not able to test on Gitlab.com)
What is the current bug behavior?
It seems as if some of the commands fail (internally?) and the results are not what expected.
What is the expected correct behavior?
- Template-Project is forked
- Name, description is changed
- Webhooks is created
- Path is changed
Relevant logs and/or screenshots
When executin the Python script the following log gets created:
Please enter your token: [...]
-----Fork----------
<Response [201]>
ProjectID: 341
{"id":341,"description":"Ein Python Modul inklusive Pip-Config und Tests","default_branch":null,"tag_list":[],"public":true,"archived":false,"visibility_level":20,"ssh_url_to_repo":"git@gitlab-sg1:Applications/PythonModule.git","http_url_to_repo":"http://gitlab-sg1/Applications/PythonModule.git","web_url":"http://gitlab-sg1/Applications/PythonModule","name":"PythonModule","name_with_namespace":"Applications / PythonModule","path":"PythonModule","path_with_namespace":"Applications/PythonModule","container_registry_enabled":true,"issues_enabled":true,"merge_requests_enabled":true,"wiki_enabled":true,"builds_enabled":true,"snippets_enabled":true,"created_at":"2017-02-23T12:58:57.505Z","last_activity_at":"2017-02-23T12:58:57.505Z","shared_runners_enabled":true,"lfs_enabled":true,"creator_id":2,"namespace":{"id":22,"name":"Applications","path":"Applications","kind":"group"},"forked_from_project":{"id":307,"http_url_to_repo":"http://gitlab-sg1/Templates/PythonModule.git","web_url":"http://gitlab-sg1/Templates/PythonModule","name":"PythonModule","name_with_namespace":"Templates / PythonModule","path":"PythonModule","path_with_namespace":"Templates/PythonModule"},"avatar_url":null,"star_count":0,"forks_count":0,"open_issues_count":0,"runners_token":"k4Gmo2kyYCQ-JgoyUD_Z","public_builds":true,"shared_with_groups":[],"only_allow_merge_if_build_succeeds":false,"request_access_enabled":false,"only_allow_merge_if_all_discussions_are_resolved":false}
-----Name and Desc----------
<Response [200]>
{"id":341,"description":"Lorem Ipsum Test123","default_branch":null,"tag_list":[],"public":true,"archived":false,"visibility_level":20,"ssh_url_to_repo":"git@gitlab-sg1:Applications/PythonModule.git","http_url_to_repo":"http://gitlab-sg1/Applications/PythonModule.git","web_url":"http://gitlab-sg1/Applications/PythonModule","name":"MyName2","name_with_namespace":"Applications / MyName2","path":"PythonModule","path_with_namespace":"Applications/PythonModule","container_registry_enabled":true,"issues_enabled":true,"merge_requests_enabled":true,"wiki_enabled":true,"builds_enabled":true,"snippets_enabled":true,"created_at":"2017-02-23T12:58:57.505Z","last_activity_at":"2017-02-23T12:58:57.505Z","shared_runners_enabled":true,"lfs_enabled":true,"creator_id":2,"namespace":{"id":22,"name":"Applications","path":"Applications","kind":"group"},"forked_from_project":{"id":307,"http_url_to_repo":"http://gitlab-sg1/Templates/PythonModule.git","web_url":"http://gitlab-sg1/Templates/PythonModule","name":"PythonModule","name_with_namespace":"Templates / PythonModule","path":"PythonModule","path_with_namespace":"Templates/PythonModule"},"avatar_url":null,"star_count":0,"forks_count":0,"open_issues_count":0,"runners_token":"k4Gmo2kyYCQ-JgoyUD_Z","public_builds":true,"shared_with_groups":[],"only_allow_merge_if_build_succeeds":false,"request_access_enabled":false,"only_allow_merge_if_all_discussions_are_resolved":false}
-----Webhook----------
<Response [201]>
{"id":230,"url":"http://conan-sg1:31336/updateDependencies","created_at":"2017-02-23T12:58:58.912Z","push_events":true,"tag_push_events":false,"enable_ssl_verification":true,"project_id":341,"issues_events":false,"merge_requests_events":false,"note_events":false,"build_events":false,"pipeline_events":false,"wiki_page_events":false}
-----Path----------
<Response [200]>
{"id":341,"description":"Lorem Ipsum Test123","default_branch":null,"tag_list":[],"public":true,"archived":false,"visibility_level":20,"ssh_url_to_repo":"git@gitlab-sg1:Applications/MyName2.git","http_url_to_repo":"http://gitlab-sg1/Applications/MyName2.git","web_url":"http://gitlab-sg1/Applications/MyName2","name":"MyName2","name_with_namespace":"Applications / MyName2","path":"MyName2","path_with_namespace":"Applications/MyName2","container_registry_enabled":true,"issues_enabled":true,"merge_requests_enabled":true,"wiki_enabled":true,"builds_enabled":true,"snippets_enabled":true,"created_at":"2017-02-23T12:58:57.505Z","last_activity_at":"2017-02-23T12:58:57.505Z","shared_runners_enabled":true,"lfs_enabled":true,"creator_id":2,"namespace":{"id":22,"name":"Applications","path":"Applications","kind":"group"},"forked_from_project":{"id":307,"http_url_to_repo":"http://gitlab-sg1/Templates/PythonModule.git","web_url":"http://gitlab-sg1/Templates/PythonModule","name":"PythonModule","name_with_namespace":"Templates / PythonModule","path":"PythonModule","path_with_namespace":"Templates/PythonModule"},"avatar_url":null,"star_count":0,"forks_count":0,"open_issues_count":0,"runners_token":"k4Gmo2kyYCQ-JgoyUD_Z","public_builds":true,"shared_with_groups":[],"only_allow_merge_if_build_succeeds":false,"request_access_enabled":false,"only_allow_merge_if_all_discussions_are_resolved":false}
Output of checks
Haven't tried this on Gitlab.com, due to proxy limitations it was easier to reproduce it locally.
Results of GitLab environment info
System information
System: Ubuntu 16.04
Current User: git
Using RVM: no
Ruby Version: 2.3.3p222
Gem Version: 2.6.6
Bundler Version:1.13.7
Rake Version: 10.5.0
Redis Version: 3.2.5
Sidekiq Version:4.2.7
GitLab information
Version: 8.17.0
Revision: 77254ab
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: postgresql
URL: http://gitlab-sg1
HTTP Clone URL: http://gitlab-sg1/some-group/some-project.git
SSH Clone URL: git@gitlab-sg1:some-group/some-project.git
Using LDAP: no
Using Omniauth: no
GitLab Shell
Version: 4.1.1
Repository storage paths:
- default: /repo/git-data/repositories
Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks/
Git: /opt/gitlab/embedded/bin/git
Results of GitLab application Check
I pasted the output into a snippet: https://gitlab.com/snippets/1629861