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 | 59 | |
| 60 | 60 | def fetch_merge_request(self, projects): |
| 61 | 61 | all_merge_request = [] |
| 62 | - | |
| 63 | 62 | # Iterate under all projects |
| 64 | 63 | for project in projects: |
| 65 | 64 | page = 1 |
| ... | ... | @@ -92,7 +91,7 @@ class GitlabDataAPI(ProxyDataAPI): |
| 92 | 91 | continue |
| 93 | 92 | |
| 94 | 93 | if isinstance(field, DateTimeField): |
| 95 | - value = parse(element[field.name]) | |
| 94 | + value = parse(element["created_at"]) | |
| 96 | 95 | else: |
| 97 | 96 | value = element[field.name] |
| 98 | 97 | |
| ... | ... | @@ -135,7 +134,7 @@ class GitlabDataAPI(ProxyDataAPI): |
| 135 | 134 | continue |
| 136 | 135 | |
| 137 | 136 | if isinstance(field, DateTimeField): |
| 138 | - value = parse(element[field.name]) | |
| 137 | + value = parse(element["created_at"]) | |
| 139 | 138 | else: |
| 140 | 139 | value = element[field.name] |
| 141 | 140 | |
| ... | ... | @@ -184,9 +183,19 @@ class GitlabDataAPI(ProxyDataAPI): |
| 184 | 183 | single_comment.update_user( |
| 185 | 184 | element["author"]["username"]) |
| 186 | 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 | 197 | if isinstance(field, DateTimeField): |
| 189 | - value = parse(element[field.name]) | |
| 198 | + value = parse(element["created_at"]) | |
| 190 | 199 | else: |
| 191 | 200 | value = element[field.name] |
| 192 | 201 | |
| ... | ... | @@ -227,9 +236,19 @@ class GitlabDataAPI(ProxyDataAPI): |
| 227 | 236 | single_comment.update_user( |
| 228 | 237 | element["author"]["username"]) |
| 229 | 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 | 250 | if isinstance(field, DateTimeField): |
| 232 | - value = parse(element[field.name]) | |
| 251 | + value = parse(element["created_at"]) | |
| 233 | 252 | else: |
| 234 | 253 | value = element[field.name] |
| 235 | 254 | |
| ... | ... | @@ -240,18 +259,22 @@ class GitlabDataAPI(ProxyDataAPI): |
| 240 | 259 | return all_comments |
| 241 | 260 | |
| 242 | 261 | def fetch_data(self): |
| 262 | + print "projects" | |
| 243 | 263 | projects = self.fetch_projects() |
| 244 | 264 | for datum in projects: |
| 245 | 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 | 273 | issue_list = self.fetch_issue(projects) |
| 252 | 274 | for datum in issue_list: |
| 253 | 275 | datum.save() |
| 254 | 276 | |
| 277 | + print "comments" | |
| 255 | 278 | comments_list = self.fetch_comments() |
| 256 | 279 | for datum in comments_list: |
| 257 | 280 | datum.save() | ... | ... |
colab/proxy/gitlab/models.py
| 1 | 1 | from django.db import models |
| 2 | 2 | from django.utils.translation import ugettext_lazy as _ |
| 3 | 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 | 10 | id = models.IntegerField(primary_key=True) |
| 9 | 11 | description = models.TextField() |
| ... | ... | @@ -12,6 +14,11 @@ class GitlabProject(models.Model): |
| 12 | 14 | name_with_namespace = models.TextField() |
| 13 | 15 | created_at = models.DateTimeField(blank=True) |
| 14 | 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 | 23 | class Meta: |
| 17 | 24 | verbose_name = _('Gitlab Project') |
| ... | ... | @@ -28,6 +35,21 @@ class GitlabMergeRequest(Collaboration): |
| 28 | 35 | description = models.TextField() |
| 29 | 36 | title = models.TextField() |
| 30 | 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 | 54 | class Meta: |
| 33 | 55 | verbose_name = _('Gitlab Merge Request') |
| ... | ... | @@ -43,10 +65,19 @@ class GitlabIssue(Collaboration): |
| 43 | 65 | description = models.TextField() |
| 44 | 66 | |
| 45 | 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 | 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 | 83 | class GitlabComment(Collaboration): |
| ... | ... | @@ -54,6 +85,48 @@ class GitlabComment(Collaboration): |
| 54 | 85 | id = models.IntegerField(primary_key=True) |
| 55 | 86 | body = models.TextField() |
| 56 | 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 | 131 | class Meta: |
| 59 | 132 | verbose_name = _('Gitlab Comments') | ... | ... |