Mercurial > kallithea
annotate kallithea/model/changeset_status.py @ 4187:d1addaf7a91e kallithea-2.2.5-rebrand
Second step in two-part process to rename directories.
This is the actual directory rename.
author | Bradley M. Kuhn <bkuhn@sfconservancy.org> |
---|---|
date | Wed, 02 Jul 2014 19:04:33 -0400 |
parents | rhodecode/model/changeset_status.py@7e5f8c12a3fc |
children | ad38f9f93b3b |
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 """ |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
3 kallithea.model.changeset_status |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4097
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4097
diff
changeset
|
6 Changeset status conttroller |
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4097
diff
changeset
|
8 :created_on: Apr 30, 2012 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4097
diff
changeset
|
9 :author: marcink |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4097
diff
changeset
|
10 :copyright: (c) 2013 RhodeCode GmbH. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4097
diff
changeset
|
11 :license: GPLv3, see LICENSE for more details. |
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 """ |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 # 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
|
14 # 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
|
15 # the Free Software Foundation, either version 3 of the License, or |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 # (at your option) any later version. |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 # |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # 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
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # GNU General Public License for more details. |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 # |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # 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
|
24 # 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
|
25 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 import logging |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
28 from collections import defaultdict |
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
30 from kallithea.model import BaseModel |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
31 from kallithea.model.db import ChangesetStatus, PullRequest |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
32 from kallithea.lib.exceptions import StatusChangeOnClosedPullRequestError |
2216
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 log = logging.getLogger(__name__) |
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 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 class ChangesetStatusModel(BaseModel): |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 |
2522
17893d61792a
Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents:
2481
diff
changeset
|
39 cls = ChangesetStatus |
17893d61792a
Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents:
2481
diff
changeset
|
40 |
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 def __get_changeset_status(self, changeset_status): |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 return self._get_instance(ChangesetStatus, changeset_status) |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
44 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
|
45 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
|
46 |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
47 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
|
48 with_revisions=False): |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
49 repo = self._get_repo(repo) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
50 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
51 q = ChangesetStatus.query()\ |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
52 .filter(ChangesetStatus.repo == repo) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
53 if not with_revisions: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
54 q = q.filter(ChangesetStatus.version == 0) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
55 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
56 if revision: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
57 q = q.filter(ChangesetStatus.revision == revision) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
58 elif pull_request: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
59 pull_request = self.__get_pull_request(pull_request) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
60 q = q.filter(ChangesetStatus.pull_request == pull_request) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
61 else: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
62 raise Exception('Please specify revision or pull_request') |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
63 q.order_by(ChangesetStatus.version.asc()) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
64 return q |
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 def calculate_status(self, statuses_by_reviewers): |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
67 """ |
4053
3625fd19b201
pull requests: add a 'Calculated' comment on current_changeset_status
Mads Kiilerich <madski@unity3d.com>
parents:
3260
diff
changeset
|
68 approved if consensus |
3625fd19b201
pull requests: add a 'Calculated' comment on current_changeset_status
Mads Kiilerich <madski@unity3d.com>
parents:
3260
diff
changeset
|
69 (old description: leading one wins, if number of occurrences are equal than weaker wins) |
2481
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 :param statuses_by_reviewers: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
72 """ |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
73 votes = defaultdict(int) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
74 reviewers_number = len(statuses_by_reviewers) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
75 for user, statuses in statuses_by_reviewers: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
76 if statuses: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
77 ver, latest = statuses[0] |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
78 votes[latest.status] += 1 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
79 else: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
80 votes[ChangesetStatus.DEFAULT] += 1 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
81 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
82 if votes.get(ChangesetStatus.STATUS_APPROVED) == reviewers_number: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
83 return ChangesetStatus.STATUS_APPROVED |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
84 else: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
85 return ChangesetStatus.STATUS_UNDER_REVIEW |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
86 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
87 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
|
88 with_revisions=False): |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
89 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
|
90 with_revisions) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
91 return q.all() |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
92 |
3176
7ec5f9c1df45
show comments from pull requests into associated changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3175
diff
changeset
|
93 def get_status(self, repo, revision=None, pull_request=None, as_str=True): |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
94 """ |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
99 :param 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 |
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
101 :param pull_request: pull_request reference |
3176
7ec5f9c1df45
show comments from pull requests into associated changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3175
diff
changeset
|
102 :param as_str: return status as string not object |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
103 """ |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
104 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
|
105 |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
106 # 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
|
107 # returned from pull_request |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
108 status = q.first() |
3176
7ec5f9c1df45
show comments from pull requests into associated changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3175
diff
changeset
|
109 if as_str: |
7ec5f9c1df45
show comments from pull requests into associated changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3175
diff
changeset
|
110 status = status.status if status else status |
7ec5f9c1df45
show comments from pull requests into associated changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3175
diff
changeset
|
111 st = status or ChangesetStatus.DEFAULT |
7ec5f9c1df45
show comments from pull requests into associated changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3175
diff
changeset
|
112 return str(st) |
7ec5f9c1df45
show comments from pull requests into associated changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3175
diff
changeset
|
113 return status |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
114 |
3175
5d1d25c1c700
set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents:
2803
diff
changeset
|
115 def set_status(self, repo, status, user, comment=None, 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
|
116 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
|
117 """ |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
118 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
|
119 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
|
120 |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
121 :param 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 :param status: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
124 :param user: |
2286
9265958e33bb
Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2217
diff
changeset
|
125 :param 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
|
126 :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
|
127 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
|
128 mess around this manually |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
129 """ |
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
|
130 repo = self._get_repo(repo) |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
131 |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
132 q = ChangesetStatus.query() |
3175
5d1d25c1c700
set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents:
2803
diff
changeset
|
133 if not comment: |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
134 from kallithea.model.comment import ChangesetCommentsModel |
3175
5d1d25c1c700
set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents:
2803
diff
changeset
|
135 comment = ChangesetCommentsModel().create( |
4097
7baea802f739
fixes issue #884 Pull Request fails when setting the lang=ja
Marcin Kuzminski <marcin@python-works.com>
parents:
4053
diff
changeset
|
136 text=u'Auto status change to %s' % (ChangesetStatus.get_status_lbl(status)), |
3175
5d1d25c1c700
set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents:
2803
diff
changeset
|
137 repo=repo, |
5d1d25c1c700
set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents:
2803
diff
changeset
|
138 user=user, |
5d1d25c1c700
set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents:
2803
diff
changeset
|
139 pull_request=pull_request, |
3257
32a283e5fd0d
Don't send notification email for auto-status changes
Marcin Kuzminski <marcin@python-works.com>
parents:
3176
diff
changeset
|
140 send_email=False |
3175
5d1d25c1c700
set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents:
2803
diff
changeset
|
141 ) |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
142 if revision: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
143 q = q.filter(ChangesetStatus.repo == repo) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
144 q = q.filter(ChangesetStatus.revision == revision) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
145 elif pull_request: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
146 pull_request = self.__get_pull_request(pull_request) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
147 q = q.filter(ChangesetStatus.repo == pull_request.org_repo) |
3175
5d1d25c1c700
set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents:
2803
diff
changeset
|
148 q = q.filter(ChangesetStatus.revision.in_(pull_request.revisions)) |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
149 cur_statuses = q.all() |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
150 |
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
|
151 #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
|
152 # we need to check if we can allow this status change |
2771
9640c1c6399b
really check if last status is from pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2677
diff
changeset
|
153 if (dont_allow_on_closed_pull_request and cur_statuses |
9640c1c6399b
really check if last status is from pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2677
diff
changeset
|
154 and getattr(cur_statuses[0].pull_request, 'status', '') |
9640c1c6399b
really check if last status is from pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2677
diff
changeset
|
155 == PullRequest.STATUS_CLOSED): |
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
|
156 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
|
157 '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
|
158 ) |
4fbbc65e8cd5
Forbid changing changset status when it is associated with a closed pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
159 |
3175
5d1d25c1c700
set the status of changesets initially on pull request, and make sure we care of version collisions.
Marcin Kuzminski <marcin@python-works.com>
parents:
2803
diff
changeset
|
160 #update all current statuses with older version |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
161 if cur_statuses: |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
162 for st in cur_statuses: |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
163 st.version += 1 |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
164 self.sa.add(st) |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
165 |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
166 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
|
167 new_status = ChangesetStatus() |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
168 new_status.author = self._get_user(user) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
169 new_status.repo = self._get_repo(repo) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
170 new_status.status = status |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
171 new_status.comment = comment |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
172 new_status.revision = revision |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
173 new_status.pull_request = pull_request |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
174 return new_status |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
175 |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
176 if revision: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
177 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
|
178 comment=comment, revision=revision, |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
179 pull_request=None) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
180 self.sa.add(new_status) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
181 return new_status |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
182 elif pull_request: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
183 #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
|
184 #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
|
185 new_statuses = [] |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
186 repo = pull_request.org_repo |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
187 for rev in pull_request.revisions: |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
188 new_status = _create_status(user=user, repo=repo, |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
189 status=status, comment=comment, |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
190 revision=rev, |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
191 pull_request=pull_request) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
192 new_statuses.append(new_status) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
193 self.sa.add(new_status) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
194 return new_statuses |