Commit 03350be3ab0253af48ea92ddd31dd2e59046a5b9
Committed by
Sergio Oliveira
1 parent
af1917f2
Exists in
master
and in
39 other branches
Added field to model and updated data_api based on the new elements in model.
Signed-off-by: Gustavo Jaruga <darksshades@gmail.com>
Showing
2 changed files
with
107 additions
and
11 deletions
Show diff stats
colab/proxy/gitlab/data_api.py
| @@ -59,7 +59,6 @@ class GitlabDataAPI(ProxyDataAPI): | @@ -59,7 +59,6 @@ class GitlabDataAPI(ProxyDataAPI): | ||
| 59 | 59 | ||
| 60 | def fetch_merge_request(self, projects): | 60 | def fetch_merge_request(self, projects): |
| 61 | all_merge_request = [] | 61 | all_merge_request = [] |
| 62 | - | ||
| 63 | # Iterate under all projects | 62 | # Iterate under all projects |
| 64 | for project in projects: | 63 | for project in projects: |
| 65 | page = 1 | 64 | page = 1 |
| @@ -92,7 +91,7 @@ class GitlabDataAPI(ProxyDataAPI): | @@ -92,7 +91,7 @@ class GitlabDataAPI(ProxyDataAPI): | ||
| 92 | continue | 91 | continue |
| 93 | 92 | ||
| 94 | if isinstance(field, DateTimeField): | 93 | if isinstance(field, DateTimeField): |
| 95 | - value = parse(element[field.name]) | 94 | + value = parse(element["created_at"]) |
| 96 | else: | 95 | else: |
| 97 | value = element[field.name] | 96 | value = element[field.name] |
| 98 | 97 | ||
| @@ -135,7 +134,7 @@ class GitlabDataAPI(ProxyDataAPI): | @@ -135,7 +134,7 @@ class GitlabDataAPI(ProxyDataAPI): | ||
| 135 | continue | 134 | continue |
| 136 | 135 | ||
| 137 | if isinstance(field, DateTimeField): | 136 | if isinstance(field, DateTimeField): |
| 138 | - value = parse(element[field.name]) | 137 | + value = parse(element["created_at"]) |
| 139 | else: | 138 | else: |
| 140 | value = element[field.name] | 139 | value = element[field.name] |
| 141 | 140 | ||
| @@ -184,9 +183,19 @@ class GitlabDataAPI(ProxyDataAPI): | @@ -184,9 +183,19 @@ class GitlabDataAPI(ProxyDataAPI): | ||
| 184 | single_comment.update_user( | 183 | single_comment.update_user( |
| 185 | element["author"]["username"]) | 184 | element["author"]["username"]) |
| 186 | continue | 185 | continue |
| 186 | + if field.name == "project": | ||
| 187 | + single_comment.project = \ | ||
| 188 | + merge_request.project | ||
| 189 | + continue | ||
| 190 | + if field.name == "issue_comment": | ||
| 191 | + single_comment.issue_comment = False | ||
| 192 | + continue | ||
| 193 | + if field.name == "parent_id": | ||
| 194 | + single_comment.parent_id = merge_request.id | ||
| 195 | + continue | ||
| 187 | 196 | ||
| 188 | if isinstance(field, DateTimeField): | 197 | if isinstance(field, DateTimeField): |
| 189 | - value = parse(element[field.name]) | 198 | + value = parse(element["created_at"]) |
| 190 | else: | 199 | else: |
| 191 | value = element[field.name] | 200 | value = element[field.name] |
| 192 | 201 | ||
| @@ -227,9 +236,19 @@ class GitlabDataAPI(ProxyDataAPI): | @@ -227,9 +236,19 @@ class GitlabDataAPI(ProxyDataAPI): | ||
| 227 | single_comment.update_user( | 236 | single_comment.update_user( |
| 228 | element["author"]["username"]) | 237 | element["author"]["username"]) |
| 229 | continue | 238 | continue |
| 239 | + if field.name == "project": | ||
| 240 | + single_comment.project = \ | ||
| 241 | + issue.project | ||
| 242 | + continue | ||
| 243 | + if field.name == "issue_comment": | ||
| 244 | + single_comment.issue_comment = True | ||
| 245 | + continue | ||
| 246 | + if field.name == "parent_id": | ||
| 247 | + single_comment.parent_id = issue.id | ||
| 248 | + continue | ||
| 230 | 249 | ||
| 231 | if isinstance(field, DateTimeField): | 250 | if isinstance(field, DateTimeField): |
| 232 | - value = parse(element[field.name]) | 251 | + value = parse(element["created_at"]) |
| 233 | else: | 252 | else: |
| 234 | value = element[field.name] | 253 | value = element[field.name] |
| 235 | 254 | ||
| @@ -240,18 +259,22 @@ class GitlabDataAPI(ProxyDataAPI): | @@ -240,18 +259,22 @@ class GitlabDataAPI(ProxyDataAPI): | ||
| 240 | return all_comments | 259 | return all_comments |
| 241 | 260 | ||
| 242 | def fetch_data(self): | 261 | def fetch_data(self): |
| 262 | + print "projects" | ||
| 243 | projects = self.fetch_projects() | 263 | projects = self.fetch_projects() |
| 244 | for datum in projects: | 264 | for datum in projects: |
| 245 | datum.save() | 265 | datum.save() |
| 246 | 266 | ||
| 247 | -# merge_request_list = self.fetch_merge_request(projects) | ||
| 248 | -# for datum in merge_request_list: | ||
| 249 | -# datum.save() | 267 | + print "MR" |
| 268 | + merge_request_list = self.fetch_merge_request(projects) | ||
| 269 | + for datum in merge_request_list: | ||
| 270 | + datum.save() | ||
| 250 | 271 | ||
| 272 | + print "issues" | ||
| 251 | issue_list = self.fetch_issue(projects) | 273 | issue_list = self.fetch_issue(projects) |
| 252 | for datum in issue_list: | 274 | for datum in issue_list: |
| 253 | datum.save() | 275 | datum.save() |
| 254 | 276 | ||
| 277 | + print "comments" | ||
| 255 | comments_list = self.fetch_comments() | 278 | comments_list = self.fetch_comments() |
| 256 | for datum in comments_list: | 279 | for datum in comments_list: |
| 257 | datum.save() | 280 | datum.save() |
colab/proxy/gitlab/models.py
| 1 | from django.db import models | 1 | from django.db import models |
| 2 | from django.utils.translation import ugettext_lazy as _ | 2 | from django.utils.translation import ugettext_lazy as _ |
| 3 | from colab.proxy.utils.models import Collaboration | 3 | from colab.proxy.utils.models import Collaboration |
| 4 | +from hitcounter.models import HitCounterModelMixin | ||
| 4 | 5 | ||
| 6 | +import datetime | ||
| 5 | 7 | ||
| 6 | -class GitlabProject(models.Model): | 8 | +class GitlabProject(models.Model, HitCounterModelMixin): |
| 7 | 9 | ||
| 8 | id = models.IntegerField(primary_key=True) | 10 | id = models.IntegerField(primary_key=True) |
| 9 | description = models.TextField() | 11 | description = models.TextField() |
| @@ -12,6 +14,11 @@ class GitlabProject(models.Model): | @@ -12,6 +14,11 @@ class GitlabProject(models.Model): | ||
| 12 | name_with_namespace = models.TextField() | 14 | name_with_namespace = models.TextField() |
| 13 | created_at = models.DateTimeField(blank=True) | 15 | created_at = models.DateTimeField(blank=True) |
| 14 | last_activity_at = models.DateTimeField(blank=True) | 16 | last_activity_at = models.DateTimeField(blank=True) |
| 17 | + path_with_namespace = models.TextField(blank=True, null=True) | ||
| 18 | + | ||
| 19 | + @property | ||
| 20 | + def url(self): | ||
| 21 | + return u'/gitlab/{}'.format(self.path_with_namespace) | ||
| 15 | 22 | ||
| 16 | class Meta: | 23 | class Meta: |
| 17 | verbose_name = _('Gitlab Project') | 24 | verbose_name = _('Gitlab Project') |
| @@ -28,6 +35,21 @@ class GitlabMergeRequest(Collaboration): | @@ -28,6 +35,21 @@ class GitlabMergeRequest(Collaboration): | ||
| 28 | description = models.TextField() | 35 | description = models.TextField() |
| 29 | title = models.TextField() | 36 | title = models.TextField() |
| 30 | state = models.TextField() | 37 | state = models.TextField() |
| 38 | + modified = models.DateTimeField(blank=True, null=True) | ||
| 39 | + | ||
| 40 | + @property | ||
| 41 | + def tag(self): | ||
| 42 | + return self.state | ||
| 43 | + | ||
| 44 | + type = u'merge_request' | ||
| 45 | + icon_name = u'file' | ||
| 46 | + | ||
| 47 | + @property | ||
| 48 | + def url(self): | ||
| 49 | + return u'/gitlab/{}/merge_requests/{}'.format(self.project.path_with_namespace, self.id) | ||
| 50 | + | ||
| 51 | + def get_author(self): | ||
| 52 | + return user | ||
| 31 | 53 | ||
| 32 | class Meta: | 54 | class Meta: |
| 33 | verbose_name = _('Gitlab Merge Request') | 55 | verbose_name = _('Gitlab Merge Request') |
| @@ -43,10 +65,19 @@ class GitlabIssue(Collaboration): | @@ -43,10 +65,19 @@ class GitlabIssue(Collaboration): | ||
| 43 | description = models.TextField() | 65 | description = models.TextField() |
| 44 | 66 | ||
| 45 | state = models.TextField() | 67 | state = models.TextField() |
| 68 | + modified = models.DateTimeField(blank=True, null=True) | ||
| 69 | + | ||
| 70 | + icon_name = u'align-right' | ||
| 71 | + type = u'gitlab_issue' | ||
| 72 | + | ||
| 73 | + @property | ||
| 74 | + def url(self): | ||
| 75 | + return u'/gitlab/{}/issues/{}'.format(self.project.path_with_namespace, self.id) | ||
| 76 | + | ||
| 46 | 77 | ||
| 47 | class Meta: | 78 | class Meta: |
| 48 | - verbose_name = _('Gitlab Collaboration') | ||
| 49 | - verbose_name_plural = _('Gitlab Collaborations') | 79 | + verbose_name = _('Gitlab Issue') |
| 80 | + verbose_name_plural = _('Gitlab Issues') | ||
| 50 | 81 | ||
| 51 | 82 | ||
| 52 | class GitlabComment(Collaboration): | 83 | class GitlabComment(Collaboration): |
| @@ -54,6 +85,48 @@ class GitlabComment(Collaboration): | @@ -54,6 +85,48 @@ class GitlabComment(Collaboration): | ||
| 54 | id = models.IntegerField(primary_key=True) | 85 | id = models.IntegerField(primary_key=True) |
| 55 | body = models.TextField() | 86 | body = models.TextField() |
| 56 | created_at = models.DateTimeField(blank=True) | 87 | created_at = models.DateTimeField(blank=True) |
| 88 | + modified = models.DateTimeField(blank=True, null=True) | ||
| 89 | + issue_comment = models.BooleanField(default=True) | ||
| 90 | + | ||
| 91 | + project = models.ForeignKey(GitlabProject, null=True, | ||
| 92 | + on_delete=models.SET_NULL) | ||
| 93 | + | ||
| 94 | + parent_id = models.IntegerField(null=True) | ||
| 95 | + type = u'comment' | ||
| 96 | + | ||
| 97 | + @property | ||
| 98 | + def title(self): | ||
| 99 | + if self.issue_comment: | ||
| 100 | + issue = GitlabIssue.objects.get(id=self.parent_id) | ||
| 101 | + return issue.title | ||
| 102 | + else: | ||
| 103 | + merge_request = GitlabMergeRequest.objects.get(id=self.parent_id) | ||
| 104 | + return merge_request.title | ||
| 105 | + | ||
| 106 | + icon_name = u'align-right' | ||
| 107 | + | ||
| 108 | + @property | ||
| 109 | + def description(self): | ||
| 110 | + return self.body | ||
| 111 | + | ||
| 112 | + @property | ||
| 113 | + def tag(self): | ||
| 114 | + if self.issue_comment: | ||
| 115 | + issue = GitlabIssue.objects.get(id=self.parent_id) | ||
| 116 | + return issue.state | ||
| 117 | + else: | ||
| 118 | + merge_request = GitlabMergeRequest.objects.get(id=self.parent_id) | ||
| 119 | + return merge_request.state | ||
| 120 | + | ||
| 121 | + @property | ||
| 122 | + def url(self): | ||
| 123 | + if self.issue_comment: | ||
| 124 | + return u'/gitlab/{}/issues/{}#notes_{}'.format( | ||
| 125 | + self.project.path_with_namespace, self.parent_id, self.id) | ||
| 126 | + else: | ||
| 127 | + return u'/gitlab/{}/merge_requests/{}#notes_{}'.format( | ||
| 128 | + self.project.path_with_namespace, self.parent_id, self.id) | ||
| 129 | + | ||
| 57 | 130 | ||
| 58 | class Meta: | 131 | class Meta: |
| 59 | verbose_name = _('Gitlab Comments') | 132 | verbose_name = _('Gitlab Comments') |