Mercurial > kallithea
annotate rhodecode/model/changeset_status.py @ 2520:a1e156503afe beta
Fixed calls to Session in db model
- added inject_ui method that should be later used for all injections of extra parameters into ui
- fixed naming conflict of `comments` functions and relationship that had the same name
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 01 Jul 2012 02:44:23 +0200 |
parents | 4d3032431d4f |
children | 17893d61792a |
rev | line source |
---|---|
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 """ |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 rhodecode.model.changeset_status |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 :created_on: Apr 30, 2012 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 :author: marcink |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 :copyright: (C) 2011-2012 Marcin Kuzminski <marcin@python-works.com> |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 :license: GPLv3, see COPYING for more details. |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 """ |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 # This program is free software: you can redistribute it and/or modify |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 # it under the terms of the GNU General Public License as published by |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 # the Free Software Foundation, either version 3 of the License, or |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 # (at your option) any later version. |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 # |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 # This program is distributed in the hope that it will be useful, |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 # GNU General Public License for more details. |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 # You should have received a copy of the GNU General Public License |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 import logging |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
27 from collections import defaultdict |
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 from rhodecode.model import BaseModel |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
30 from rhodecode.model.db import ChangesetStatus, PullRequest |
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 log = logging.getLogger(__name__) |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 class ChangesetStatusModel(BaseModel): |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 def __get_changeset_status(self, changeset_status): |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 return self._get_instance(ChangesetStatus, changeset_status) |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
40 def __get_pull_request(self, pull_request): |
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
41 return self._get_instance(PullRequest, pull_request) |
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
42 |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
43 def _get_status_query(self, repo, revision, pull_request, |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
44 with_revisions=False): |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
45 repo = self._get_repo(repo) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
46 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
47 q = ChangesetStatus.query()\ |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
48 .filter(ChangesetStatus.repo == repo) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
49 if not with_revisions: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
50 q = q.filter(ChangesetStatus.version == 0) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
51 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
52 if revision: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
53 q = q.filter(ChangesetStatus.revision == revision) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
54 elif pull_request: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
55 pull_request = self.__get_pull_request(pull_request) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
56 q = q.filter(ChangesetStatus.pull_request == pull_request) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
57 else: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
58 raise Exception('Please specify revision or pull_request') |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
59 q.order_by(ChangesetStatus.version.asc()) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
60 return q |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
61 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
62 def calculate_status(self, statuses_by_reviewers): |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
63 """ |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
64 leading one wins, if number of occurences are equal than weaker wins |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
65 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
66 :param statuses_by_reviewers: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
67 """ |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
68 status = None |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
69 votes = defaultdict(int) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
70 reviewers_number = len(statuses_by_reviewers) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
71 for user, statuses in statuses_by_reviewers: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
72 if statuses: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
73 ver, latest = statuses[0] |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
74 votes[latest.status] += 1 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
75 else: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
76 votes[ChangesetStatus.DEFAULT] += 1 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
77 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
78 if votes.get(ChangesetStatus.STATUS_APPROVED) == reviewers_number: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
79 return ChangesetStatus.STATUS_APPROVED |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
80 else: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
81 return ChangesetStatus.STATUS_UNDER_REVIEW |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
82 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
83 def get_statuses(self, repo, revision=None, pull_request=None, |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
84 with_revisions=False): |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
85 q = self._get_status_query(repo, revision, pull_request, |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
86 with_revisions) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
87 return q.all() |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
88 |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
89 def get_status(self, repo, revision=None, pull_request=None): |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
90 """ |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
91 Returns latest status of changeset for given revision or for given |
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
92 pull request. Statuses are versioned inside a table itself and |
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
93 version == 0 is always the current one |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
94 |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
95 :param repo: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
96 :type repo: |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
97 :param revision: 40char hash or None |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
98 :type revision: str |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
99 :param pull_request: pull_request reference |
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
100 :type: |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
101 """ |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
102 q = self._get_status_query(repo, revision, pull_request) |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
103 |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
104 # need to use first here since there can be multiple statuses |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
105 # returned from pull_request |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
106 status = q.first() |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
107 status = status.status if status else status |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
108 st = status or ChangesetStatus.DEFAULT |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
109 return str(st) |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
110 |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
111 def set_status(self, repo, status, user, comment, revision=None, |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
112 pull_request=None): |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
113 """ |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
114 Creates new status for changeset or updates the old ones bumping their |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
115 version, leaving the current status at |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
116 |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
117 :param repo: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
118 :type repo: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
119 :param revision: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
120 :type revision: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
121 :param status: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
122 :type status: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
123 :param user: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
124 :type user: |
2286
9265958e33bb
Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2217
diff
changeset
|
125 :param comment: |
9265958e33bb
Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2217
diff
changeset
|
126 :type comment: |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
127 """ |
2432
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
2287
diff
changeset
|
128 repo = self._get_repo(repo) |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
129 |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
130 q = ChangesetStatus.query() |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
131 |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
132 if revision: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
133 q = q.filter(ChangesetStatus.repo == repo) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
134 q = q.filter(ChangesetStatus.revision == revision) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
135 elif pull_request: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
136 pull_request = self.__get_pull_request(pull_request) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
137 q = q.filter(ChangesetStatus.repo == pull_request.org_repo) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
138 q = q.filter(ChangesetStatus.pull_request == pull_request) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
139 cur_statuses = q.all() |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
140 |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
141 if cur_statuses: |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
142 for st in cur_statuses: |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
143 st.version += 1 |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
144 self.sa.add(st) |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
145 |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
146 def _create_status(user, repo, status, comment, revision, pull_request): |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
147 new_status = ChangesetStatus() |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
148 new_status.author = self._get_user(user) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
149 new_status.repo = self._get_repo(repo) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
150 new_status.status = status |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
151 new_status.comment = comment |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
152 new_status.revision = revision |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
153 new_status.pull_request = pull_request |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
154 return new_status |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
155 |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
156 if revision: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
157 new_status = _create_status(user=user, repo=repo, status=status, |
2478
8eab81115660
white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2443
diff
changeset
|
158 comment=comment, revision=revision, |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
159 pull_request=None) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
160 self.sa.add(new_status) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
161 return new_status |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
162 elif pull_request: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
163 #pull request can have more than one revision associated to it |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
164 #we need to create new version for each one |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
165 new_statuses = [] |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
166 repo = pull_request.org_repo |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
167 for rev in pull_request.revisions: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
168 new_status = _create_status(user=user, repo=repo, |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
169 status=status, comment=comment, |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
170 revision=rev, |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
171 pull_request=pull_request) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
172 new_statuses.append(new_status) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
173 self.sa.add(new_status) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
174 return new_statuses |