Mercurial > kallithea
annotate rhodecode/model/changeset_status.py @ 2729:e9e7c40b4f1a beta
added deque with maxlen for py2.5 compat
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 22 Aug 2012 12:09:49 +0200 |
parents | 4fbbc65e8cd5 |
children | 9640c1c6399b |
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 |
2677
4fbbc65e8cd5
Forbid changing changset status when it is associated with a closed pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
31 from rhodecode.lib.exceptions import StatusChangeOnClosedPullRequestError |
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 log = logging.getLogger(__name__) |
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 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 class ChangesetStatusModel(BaseModel): |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 |
2522
17893d61792a
Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents:
2481
diff
changeset
|
38 cls = ChangesetStatus |
17893d61792a
Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents:
2481
diff
changeset
|
39 |
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 def __get_changeset_status(self, changeset_status): |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 return self._get_instance(ChangesetStatus, changeset_status) |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
43 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
|
44 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
|
45 |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
46 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
|
47 with_revisions=False): |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
48 repo = self._get_repo(repo) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
49 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
50 q = ChangesetStatus.query()\ |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
51 .filter(ChangesetStatus.repo == repo) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
52 if not with_revisions: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
53 q = q.filter(ChangesetStatus.version == 0) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
54 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
55 if revision: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
56 q = q.filter(ChangesetStatus.revision == revision) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
57 elif pull_request: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
58 pull_request = self.__get_pull_request(pull_request) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
59 q = q.filter(ChangesetStatus.pull_request == pull_request) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
60 else: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
61 raise Exception('Please specify revision or pull_request') |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
62 q.order_by(ChangesetStatus.version.asc()) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
63 return q |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
64 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
65 def calculate_status(self, statuses_by_reviewers): |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
66 """ |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
67 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
|
68 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
69 :param statuses_by_reviewers: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
70 """ |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
71 status = None |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
72 votes = defaultdict(int) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
73 reviewers_number = len(statuses_by_reviewers) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
74 for user, statuses in statuses_by_reviewers: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
75 if statuses: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
76 ver, latest = statuses[0] |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
77 votes[latest.status] += 1 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
78 else: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
79 votes[ChangesetStatus.DEFAULT] += 1 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
80 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
81 if votes.get(ChangesetStatus.STATUS_APPROVED) == reviewers_number: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
82 return ChangesetStatus.STATUS_APPROVED |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
83 else: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
84 return ChangesetStatus.STATUS_UNDER_REVIEW |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
85 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
86 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
|
87 with_revisions=False): |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
88 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
|
89 with_revisions) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
90 return q.all() |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
91 |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
92 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
|
93 """ |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
94 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
|
95 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
|
96 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
|
97 |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
98 :param repo: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
99 :type repo: |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
100 :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
|
101 :type revision: str |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
102 :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
|
103 :type: |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
104 """ |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
105 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
|
106 |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
107 # 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
|
108 # returned from pull_request |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
109 status = q.first() |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
110 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
|
111 st = status or ChangesetStatus.DEFAULT |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
112 return str(st) |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
113 |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
114 def set_status(self, repo, status, user, comment, revision=None, |
2677
4fbbc65e8cd5
Forbid changing changset status when it is associated with a closed pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
115 pull_request=None, dont_allow_on_closed_pull_request=False): |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
116 """ |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
117 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
|
118 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
|
119 |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
120 :param repo: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
121 :type repo: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
122 :param revision: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
123 :type revision: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
124 :param status: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
125 :type status: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
126 :param user: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
127 :type user: |
2286
9265958e33bb
Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2217
diff
changeset
|
128 :param comment: |
9265958e33bb
Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2217
diff
changeset
|
129 :type comment: |
2677
4fbbc65e8cd5
Forbid changing changset status when it is associated with a closed pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
130 :param dont_allow_on_closed_pull_request: don't allow a status change |
4fbbc65e8cd5
Forbid changing changset status when it is associated with a closed pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
131 if last status was for pull request and it's closed. We shouldn't |
4fbbc65e8cd5
Forbid changing changset status when it is associated with a closed pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
132 mess around this manually |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
133 """ |
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
|
134 repo = self._get_repo(repo) |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
135 |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
136 q = ChangesetStatus.query() |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
137 |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
138 if revision: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
139 q = q.filter(ChangesetStatus.repo == repo) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
140 q = q.filter(ChangesetStatus.revision == revision) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
141 elif pull_request: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
142 pull_request = self.__get_pull_request(pull_request) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
143 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
|
144 q = q.filter(ChangesetStatus.pull_request == pull_request) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
145 cur_statuses = q.all() |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
146 |
2677
4fbbc65e8cd5
Forbid changing changset status when it is associated with a closed pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
147 #if statuses exists and last is associated with a closed pull request |
4fbbc65e8cd5
Forbid changing changset status when it is associated with a closed pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
148 # we need to check if we can allow this status change |
4fbbc65e8cd5
Forbid changing changset status when it is associated with a closed pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
149 if (dont_allow_on_closed_pull_request and cur_statuses |
4fbbc65e8cd5
Forbid changing changset status when it is associated with a closed pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
150 and cur_statuses[0].pull_request.status == PullRequest.STATUS_CLOSED): |
4fbbc65e8cd5
Forbid changing changset status when it is associated with a closed pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
151 raise StatusChangeOnClosedPullRequestError( |
4fbbc65e8cd5
Forbid changing changset status when it is associated with a closed pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
152 'Changing status on closed pull request is not allowed' |
4fbbc65e8cd5
Forbid changing changset status when it is associated with a closed pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
153 ) |
4fbbc65e8cd5
Forbid changing changset status when it is associated with a closed pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
154 |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
155 if cur_statuses: |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
156 for st in cur_statuses: |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
157 st.version += 1 |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
158 self.sa.add(st) |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
159 |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
160 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
|
161 new_status = ChangesetStatus() |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
162 new_status.author = self._get_user(user) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
163 new_status.repo = self._get_repo(repo) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
164 new_status.status = status |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
165 new_status.comment = comment |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
166 new_status.revision = revision |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
167 new_status.pull_request = pull_request |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
168 return new_status |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
169 |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
170 if revision: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
171 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
|
172 comment=comment, revision=revision, |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
173 pull_request=None) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
174 self.sa.add(new_status) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
175 return new_status |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
176 elif pull_request: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
177 #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
|
178 #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
|
179 new_statuses = [] |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
180 repo = pull_request.org_repo |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
181 for rev in pull_request.revisions: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
182 new_status = _create_status(user=user, repo=repo, |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
183 status=status, comment=comment, |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
184 revision=rev, |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
185 pull_request=pull_request) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
186 new_statuses.append(new_status) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
187 self.sa.add(new_status) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
188 return new_statuses |