Commit 5ec6e62b140f3e3d1dfecd523baea719073f6f0d
1 parent
7b82e8f3
Exists in
community_association
Added Gitlab Groups support to data_api
Signed-off-by: Matheus Fernandes <matheus.souza.fernandes@gmail.com> Signed-off-by: Lucas Moura <lucas.moura128@gmail.com>
Showing
2 changed files
with
49 additions
and
11 deletions
Show diff stats
colab/plugins/gitlab/data_api.py
... | ... | @@ -9,7 +9,8 @@ from django.conf import settings |
9 | 9 | from django.db.models.fields import DateTimeField |
10 | 10 | |
11 | 11 | from colab.plugins.gitlab.models import (GitlabProject, GitlabMergeRequest, |
12 | - GitlabComment, GitlabIssue) | |
12 | + GitlabComment, GitlabIssue, | |
13 | + GitlabGroup) | |
13 | 14 | from colab.plugins.utils.proxy_data_api import ProxyDataAPI |
14 | 15 | |
15 | 16 | LOGGER = logging.getLogger('colab.plugin.gitlab') |
... | ... | @@ -27,6 +28,7 @@ class GitlabDataAPI(ProxyDataAPI): |
27 | 28 | if upstream[-1] == '/': |
28 | 29 | upstream = upstream[:-1] |
29 | 30 | |
31 | + print u'{}{}?{}'.format(upstream, path, params) | |
30 | 32 | return u'{}{}?{}'.format(upstream, path, params) |
31 | 33 | |
32 | 34 | def get_json_data(self, api_url, page, pages=1000): |
... | ... | @@ -82,6 +84,24 @@ class GitlabDataAPI(ProxyDataAPI): |
82 | 84 | |
83 | 85 | return projects |
84 | 86 | |
87 | + def fetch_groups(self): | |
88 | + page = 1 | |
89 | + groups = [] | |
90 | + | |
91 | + while True: | |
92 | + json_data = self.get_json_data('/api/v3/groups', page) | |
93 | + page = page + 1 | |
94 | + | |
95 | + if not len(json_data): | |
96 | + break | |
97 | + | |
98 | + for element in json_data: | |
99 | + group = GitlabGroup() | |
100 | + self.fill_object_data(element, group) | |
101 | + groups.append(group) | |
102 | + | |
103 | + return groups | |
104 | + | |
85 | 105 | def fetch_merge_request(self, projects): |
86 | 106 | all_merge_request = [] |
87 | 107 | |
... | ... | @@ -182,22 +202,22 @@ class GitlabDataAPI(ProxyDataAPI): |
182 | 202 | def fetch_data(self): |
183 | 203 | LOGGER.info("Importing Projects") |
184 | 204 | projects = self.fetch_projects() |
185 | - for datum in projects: | |
186 | - datum.save() | |
187 | 205 | |
188 | 206 | LOGGER.info("Importing Merge Requests") |
189 | - merge_request_list = self.fetch_merge_request(projects) | |
190 | - for datum in merge_request_list: | |
191 | - datum.save() | |
207 | + merge_requests = self.fetch_merge_request(projects) | |
192 | 208 | |
193 | 209 | LOGGER.info("Importing Issues") |
194 | - issue_list = self.fetch_issue(projects) | |
195 | - for datum in issue_list: | |
196 | - datum.save() | |
210 | + issues = self.fetch_issue(projects) | |
197 | 211 | |
198 | 212 | LOGGER.info("Importing Comments") |
199 | - comments_list = self.fetch_comments() | |
200 | - for datum in comments_list: | |
213 | + comments = self.fetch_comments() | |
214 | + | |
215 | + LOGGER.info("Importing Groups") | |
216 | + groups = self.fetch_groups() | |
217 | + | |
218 | + save_list = projects + merge_requests + issues + comments + groups | |
219 | + | |
220 | + for datum in save_list: | |
201 | 221 | datum.save() |
202 | 222 | |
203 | 223 | @property | ... | ... |
colab/plugins/gitlab/models.py
... | ... | @@ -24,6 +24,24 @@ class GitlabProject(models.Model, HitCounterModelMixin): |
24 | 24 | verbose_name_plural = _('Gitlab Projects') |
25 | 25 | |
26 | 26 | |
27 | +class GitlabGroup(models.Model): | |
28 | + id = models.IntegerField(primary_key=True) | |
29 | + name = models.CharField(max_length=100) | |
30 | + path = models.CharField(max_length=100) | |
31 | + owner_id = models.IntegerField(null=True) | |
32 | + | |
33 | + def __unicode__(self): | |
34 | + return u'{}'.format(self.path) | |
35 | + | |
36 | + @property | |
37 | + def url(self): | |
38 | + return u'/gitlab/groups/{}'.format(self.id) | |
39 | + | |
40 | + class Meta: | |
41 | + verbose_name = _('Gitlab Group') | |
42 | + verbose_name_plural = _('Gitlab Groups') | |
43 | + | |
44 | + | |
27 | 45 | class GitlabMergeRequest(Collaboration): |
28 | 46 | |
29 | 47 | id = models.IntegerField(primary_key=True) | ... | ... |