Skip to content

Commit 69274d8

Browse files
committed
Merge branch 'development' release v0.5.2
2 parents 7efbb3f + 98e3e65 commit 69274d8

File tree

6 files changed

+50
-43
lines changed

6 files changed

+50
-43
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
---
2+
## gitlab-mirrors v0.5.2
3+
4+
* Certified compatibility with GitLab 8.1.4.
5+
* Documentation updates.
6+
* Fixes project transfer bug which is a regression introduced somewhere in
7+
GitLab 8.x. This prevented projects being properly created in GitLab under
8+
the mirror namespace.
9+
10+
---
111
## gitlab-mirrors v0.5.1
212

313
* Certified compatibility with GitLab 7.6.2.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Created by Sam Gleske under [MIT License](LICENSE).
7878
* Docs #26 [Glen Mailer](https://github.com/glenjamin)
7979
* Docs #54 [Martijn Vermaat](https://github.com/martijnvermaat)
8080
* Better logging #57 [Loic Dachary](https://github.com/dachary)
81+
* Fixed project transfer bug #78 [Corey Osman](https://github.com/logicminds)
8182

8283
[gitlab-api]: http://api.gitlab.org/
8384
[issues]: https://github.com/samrocketman/gitlab-mirrors/issues

docs/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ user instead of a dedicated administrator.
123123
group is owned by the user. This means that if you wish to mirror projects
124124
in namespaces other than your own username then you will have to first
125125
manually create the mirror in GitLab and then run the `add_mirror.sh` command
126-
(see Managing repositories).
127-
2. You user will include mirror pushes in your user statistics.
126+
(see Managing repositories). This bug has not been tested in GitLab 7.x/8.x.
127+
2. Your user will include mirror pushes in your user statistics.
128128

129129
---
130130
Next up is [Managing mirrored repositories](management.md)

docs/prerequisites.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
### Required software
44

5-
* [GitLab 6.x/7.x][gitlab]
5+
* [Tested with GitLab 6.x/7.x/8.x][gitlab]
66
* [pyapi-gitlab3 @ v0.5.4][python-gitlab3]
77
* [GNU coreutils][coreutils]
8-
* [git 1.6.5][git] or later (git 1.6.5 introduced transport helpers)
8+
* [git 1.8.0][git] or later
99

1010
If you plan on mirroring SVN repositories as well then you'll need the
1111
following additional options.

lib/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION="v0.5.1"
1+
VERSION="v0.5.2"

lib/manage_gitlab_project.py

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,11 @@
4848
else:
4949
git=gitlab.GitLab(gitlab_url=gitlab_url,token=token_secret,ssl_verify=True)
5050

51-
def findgroup(gname):
52-
#Locate the group
53-
page=1
54-
while len(git.groups(page=page)) > 0:
55-
for group in git.groups(page=page):
56-
if group.name == gname:
57-
return group
58-
page += 1
59-
else:
60-
print >> stderr, "Project namespace (user or group) not found or user does not have permission of existing group."
61-
print >> stderr, "gitlab-mirrors will not automatically create the project namespace."
62-
exit(1)
63-
64-
def findproject(gname,pname,user=False):
65-
page=1
66-
while len(git.projects(page=page,per_page=20)) > 0:
67-
for project in git.projects(page=page,per_page=20):
68-
if not user and project.namespace['name'] == gname and project.name == pname:
69-
return project
70-
elif user and project.namespace['path'] == gname and project.name == pname:
71-
return project
72-
page += 1
73-
else:
74-
return False
51+
# transfer the project from the source namespace to the specified group namespace
52+
def transfer_project(src_project, group):
53+
value = group.transfer_project(src_project.id)
54+
dest_project = git.find_project(name=src_project.name)
55+
return dest_project
7556

7657
def createproject(pname):
7758
if len(options.desc) == 0:
@@ -87,40 +68,55 @@ def createproject(pname):
8768
'merge_requests_enabled': options.merge,
8869
'wiki_enabled': options.wiki,
8970
'snippets_enabled': options.snippets,
90-
'public': options.public
71+
'public': options.public,
72+
'namespace_id': git.find_group(name=gitlab_namespace).id,
9173
}
9274
#make all project options lowercase boolean strings i.e. true instead of True
9375
for x in project_options.keys():
9476
project_options[x] = str(project_options[x]).lower()
95-
new_project=git.add_project(pname,description=description,**project_options)
96-
if gitlab_user != gitlab_namespace:
97-
new_project=findproject(gitlab_user,pname,user=True)
98-
new_project=git.group(found_group.id).transfer_project(new_project.id)
99-
if findproject(gitlab_namespace,pname):
100-
return findproject(gitlab_namespace,pname)
77+
print >> stderr, "Creating new project %s" % pname
78+
git.add_project(pname,description=description,**project_options)
79+
found_project = git.find_project(name=pname)
80+
if needs_transfer(gitlab_user, gitlab_namespace, found_project):
81+
found_project = transfer_project(found_project, found_group)
82+
return found_project
83+
84+
# returns a Bool True if the transfer is required
85+
def needs_transfer(user, groupname, project):
86+
namespace = False
87+
if groupname:
88+
namespace = groupname
10189
else:
102-
return False
90+
namespace = user
91+
return project.namespace['name'] != namespace
10392

10493
if options.create:
105-
found_group=findgroup(gitlab_namespace)
106-
found_project=findproject(gitlab_namespace,project_name)
107-
108-
if not found_project:
94+
found_group=git.find_group(name=gitlab_namespace)
95+
found_project = None
96+
# search the group namespace first
97+
found_project=git.find_project(name=project_name)
98+
if found_project:
99+
if needs_transfer(gitlab_user, gitlab_namespace, found_project):
100+
found_project = transfer_project(found_project, found_group)
101+
if not found_project:
102+
print >> stderr, "There was a problem transferring {group}/{project}. Did you give {user} user Admin rights in gitlab?".format(group=gitlab_namespace,project=project_name,user=gitlab_user)
103+
exit(1)
104+
else:
109105
found_project=createproject(project_name)
110106
if not found_project:
111107
print >> stderr, "There was a problem creating {group}/{project}. Did you give {user} user Admin rights in gitlab?".format(group=gitlab_namespace,project=project_name,user=gitlab_user)
112108
exit(1)
113-
114109
if options.http:
115110
print found_project.http_url_to_repo
116111
else:
117112
print found_project.ssh_url_to_repo
118113
elif options.delete:
119114
try:
120-
deleted_project=git.project(findproject(gitlab_namespace,project_name).id).delete()
115+
deleted_project=git.find_project(name=project_name).delete()
121116
except Exception as e:
122117
print >> stderr, e
123118
exit(1)
124119
else:
125120
print >> stderr, "No --create or --delete option added."
126121
exit(1)
122+

0 commit comments

Comments
 (0)