Mercurial > kallithea
annotate kallithea/model/changeset_status.py @ 8685:dff9658bdd98
model: don't import Session from db - import meta and get it from the real source
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Mon, 12 Oct 2020 01:44:10 +0200 |
parents | 0a277465fddf |
children | 5e46f73f0d1c |
rev | line source |
---|---|
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
5376
0ad053c172fa
cleanup: make module self-naming consistent
Mads Kiilerich <madski@unity3d.com>
parents:
5047
diff
changeset
|
2 # This program is free software: you can redistribute it and/or modify |
0ad053c172fa
cleanup: make module self-naming consistent
Mads Kiilerich <madski@unity3d.com>
parents:
5047
diff
changeset
|
3 # it under the terms of the GNU General Public License as published by |
0ad053c172fa
cleanup: make module self-naming consistent
Mads Kiilerich <madski@unity3d.com>
parents:
5047
diff
changeset
|
4 # the Free Software Foundation, either version 3 of the License, or |
0ad053c172fa
cleanup: make module self-naming consistent
Mads Kiilerich <madski@unity3d.com>
parents:
5047
diff
changeset
|
5 # (at your option) any later version. |
0ad053c172fa
cleanup: make module self-naming consistent
Mads Kiilerich <madski@unity3d.com>
parents:
5047
diff
changeset
|
6 # |
0ad053c172fa
cleanup: make module self-naming consistent
Mads Kiilerich <madski@unity3d.com>
parents:
5047
diff
changeset
|
7 # This program is distributed in the hope that it will be useful, |
0ad053c172fa
cleanup: make module self-naming consistent
Mads Kiilerich <madski@unity3d.com>
parents:
5047
diff
changeset
|
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
0ad053c172fa
cleanup: make module self-naming consistent
Mads Kiilerich <madski@unity3d.com>
parents:
5047
diff
changeset
|
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0ad053c172fa
cleanup: make module self-naming consistent
Mads Kiilerich <madski@unity3d.com>
parents:
5047
diff
changeset
|
10 # GNU General Public License for more details. |
0ad053c172fa
cleanup: make module self-naming consistent
Mads Kiilerich <madski@unity3d.com>
parents:
5047
diff
changeset
|
11 # |
0ad053c172fa
cleanup: make module self-naming consistent
Mads Kiilerich <madski@unity3d.com>
parents:
5047
diff
changeset
|
12 # You should have received a copy of the GNU General Public License |
0ad053c172fa
cleanup: make module self-naming consistent
Mads Kiilerich <madski@unity3d.com>
parents:
5047
diff
changeset
|
13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 """ |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
15 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
|
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 |
4919
494b04a84a49
model: trivial typo fixes
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
4750
diff
changeset
|
18 Changeset status controller |
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 |
4211
1948ede028ef
RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4208
diff
changeset
|
20 This file was forked by the Kallithea project in July 2014. |
1948ede028ef
RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4208
diff
changeset
|
21 Original author and date, and relevant copyright and licensing information is below: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4097
diff
changeset
|
22 :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
|
23 :author: marcink |
4211
1948ede028ef
RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4208
diff
changeset
|
24 :copyright: (c) 2013 RhodeCode GmbH, and others. |
4208
ad38f9f93b3b
Correct licensing information in individual files.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4187
diff
changeset
|
25 :license: GPLv3, see LICENSE.md for more details. |
2216
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 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 import logging |
7811
0a277465fddf
scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents:
7429
diff
changeset
|
29 |
4750
3752cf4972a7
status: explicitly use joinedload of authors instead of relying on lazy=join
Mads Kiilerich <madski@unity3d.com>
parents:
4526
diff
changeset
|
30 from sqlalchemy.orm import joinedload |
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 |
8685
dff9658bdd98
model: don't import Session from db - import meta and get it from the real source
Mads Kiilerich <mads@kiilerich.com>
parents:
7811
diff
changeset
|
32 from kallithea.model import meta |
dff9658bdd98
model: don't import Session from db - import meta and get it from the real source
Mads Kiilerich <mads@kiilerich.com>
parents:
7811
diff
changeset
|
33 from kallithea.model.db import ChangesetStatus, PullRequest, Repository, User |
7811
0a277465fddf
scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents:
7429
diff
changeset
|
34 |
2216
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 log = logging.getLogger(__name__) |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 |
6523
3760df6251e0
model: remove BaseModel class
Søren Løvborg <sorenl@unity3d.com>
parents:
6522
diff
changeset
|
39 class ChangesetStatusModel(object): |
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
41 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
|
42 with_revisions=False): |
6464
d7d1e0a3850a
model: inline calls to BaseModel._get_repo
Søren Løvborg <sorenl@unity3d.com>
parents:
6463
diff
changeset
|
43 repo = Repository.guess_instance(repo) |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
44 |
5598
edb24bc0f71a
cleanup: consistent space before line continuation backslash
Mads Kiilerich <madski@unity3d.com>
parents:
5397
diff
changeset
|
45 q = ChangesetStatus.query() \ |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
46 .filter(ChangesetStatus.repo == repo) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
47 if not with_revisions: |
5926
133686b535d1
pullrequests: clarifying comment about how weird status versioning is
Mads Kiilerich <madski@unity3d.com>
parents:
5925
diff
changeset
|
48 # only report the latest vote across all users! TODO: be smarter! |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
49 q = q.filter(ChangesetStatus.version == 0) |
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 if revision: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
52 q = q.filter(ChangesetStatus.revision == revision) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
53 elif pull_request: |
6119
91b38dc6d891
model: refactor and simplify _get_instance
Søren Løvborg <sorenl@unity3d.com>
parents:
6118
diff
changeset
|
54 pull_request = PullRequest.guess_instance(pull_request) |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
55 q = q.filter(ChangesetStatus.pull_request == pull_request) |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
56 else: |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
57 raise Exception('Please specify revision or pull_request') |
4355
ab38e825d303
pull requests: fix sorting of votes - the result of the method call was not used like other method calls are
Mads Kiilerich <madski@unity3d.com>
parents:
4329
diff
changeset
|
58 q = q.order_by(ChangesetStatus.version.asc()) |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
59 return q |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
60 |
5039
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
4919
diff
changeset
|
61 def _calculate_status(self, statuses): |
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
4919
diff
changeset
|
62 """ |
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
4919
diff
changeset
|
63 Given a list of statuses, calculate the resulting status, according to |
5041
6b1e1437c026
changeset status: set status to rejected if at least one reviewer rejected
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5040
diff
changeset
|
64 the policy: approve if consensus, reject when at least one reject. |
5039
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
4919
diff
changeset
|
65 """ |
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
4919
diff
changeset
|
66 |
5040
930caa6a4e5f
changeset status: simplify status calculation logic
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5039
diff
changeset
|
67 if not statuses: |
930caa6a4e5f
changeset status: simplify status calculation logic
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5039
diff
changeset
|
68 return ChangesetStatus.STATUS_UNDER_REVIEW |
5039
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
4919
diff
changeset
|
69 |
5047
99f090563f5f
changeset status: fix common case where a reviewer did not yet review anything
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5041
diff
changeset
|
70 if all(st and st.status == ChangesetStatus.STATUS_APPROVED for st in statuses): |
5040
930caa6a4e5f
changeset status: simplify status calculation logic
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5039
diff
changeset
|
71 return ChangesetStatus.STATUS_APPROVED |
5039
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
4919
diff
changeset
|
72 |
5047
99f090563f5f
changeset status: fix common case where a reviewer did not yet review anything
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5041
diff
changeset
|
73 if any(st and st.status == ChangesetStatus.STATUS_REJECTED for st in statuses): |
5041
6b1e1437c026
changeset status: set status to rejected if at least one reviewer rejected
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5040
diff
changeset
|
74 return ChangesetStatus.STATUS_REJECTED |
6b1e1437c026
changeset status: set status to rejected if at least one reviewer rejected
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5040
diff
changeset
|
75 |
5040
930caa6a4e5f
changeset status: simplify status calculation logic
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
5039
diff
changeset
|
76 return ChangesetStatus.STATUS_UNDER_REVIEW |
5039
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
4919
diff
changeset
|
77 |
4359
cfd9115db2a5
pull requests: cleanup of PR status voting calculation
Mads Kiilerich <madski@unity3d.com>
parents:
4355
diff
changeset
|
78 def calculate_pull_request_result(self, pull_request): |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
79 """ |
5039
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
4919
diff
changeset
|
80 Return a tuple (reviewers, pending reviewers, pull request status) |
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
4919
diff
changeset
|
81 Only approve and reject counts as valid votes. |
2481
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 |
4359
cfd9115db2a5
pull requests: cleanup of PR status voting calculation
Mads Kiilerich <madski@unity3d.com>
parents:
4355
diff
changeset
|
84 # collect latest votes from all voters |
cfd9115db2a5
pull requests: cleanup of PR status voting calculation
Mads Kiilerich <madski@unity3d.com>
parents:
4355
diff
changeset
|
85 cs_statuses = dict() |
cfd9115db2a5
pull requests: cleanup of PR status voting calculation
Mads Kiilerich <madski@unity3d.com>
parents:
4355
diff
changeset
|
86 for st in reversed(self.get_statuses(pull_request.org_repo, |
cfd9115db2a5
pull requests: cleanup of PR status voting calculation
Mads Kiilerich <madski@unity3d.com>
parents:
4355
diff
changeset
|
87 pull_request=pull_request, |
cfd9115db2a5
pull requests: cleanup of PR status voting calculation
Mads Kiilerich <madski@unity3d.com>
parents:
4355
diff
changeset
|
88 with_revisions=True)): |
cfd9115db2a5
pull requests: cleanup of PR status voting calculation
Mads Kiilerich <madski@unity3d.com>
parents:
4355
diff
changeset
|
89 cs_statuses[st.author.username] = st |
5039
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
4919
diff
changeset
|
90 |
4359
cfd9115db2a5
pull requests: cleanup of PR status voting calculation
Mads Kiilerich <madski@unity3d.com>
parents:
4355
diff
changeset
|
91 # collect votes from official reviewers |
cfd9115db2a5
pull requests: cleanup of PR status voting calculation
Mads Kiilerich <madski@unity3d.com>
parents:
4355
diff
changeset
|
92 pull_request_reviewers = [] |
cfd9115db2a5
pull requests: cleanup of PR status voting calculation
Mads Kiilerich <madski@unity3d.com>
parents:
4355
diff
changeset
|
93 pull_request_pending_reviewers = [] |
5039
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
4919
diff
changeset
|
94 relevant_statuses = [] |
5763
20a094053606
pullrequests: optimize iteration over reviewers - avoid fetching users one by one
Mads Kiilerich <madski@unity3d.com>
parents:
5598
diff
changeset
|
95 for user in pull_request.get_reviewer_users(): |
20a094053606
pullrequests: optimize iteration over reviewers - avoid fetching users one by one
Mads Kiilerich <madski@unity3d.com>
parents:
5598
diff
changeset
|
96 st = cs_statuses.get(user.username) |
5039
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
4919
diff
changeset
|
97 relevant_statuses.append(st) |
5925
0590e974ac35
pullrequests: refactor how reviewer status is passed around internally
Mads Kiilerich <madski@unity3d.com>
parents:
5763
diff
changeset
|
98 status = ChangesetStatus.STATUS_NOT_REVIEWED if st is None else st.status |
0590e974ac35
pullrequests: refactor how reviewer status is passed around internally
Mads Kiilerich <madski@unity3d.com>
parents:
5763
diff
changeset
|
99 if status in (ChangesetStatus.STATUS_NOT_REVIEWED, |
0590e974ac35
pullrequests: refactor how reviewer status is passed around internally
Mads Kiilerich <madski@unity3d.com>
parents:
5763
diff
changeset
|
100 ChangesetStatus.STATUS_UNDER_REVIEW): |
5763
20a094053606
pullrequests: optimize iteration over reviewers - avoid fetching users one by one
Mads Kiilerich <madski@unity3d.com>
parents:
5598
diff
changeset
|
101 pull_request_pending_reviewers.append(user) |
5925
0590e974ac35
pullrequests: refactor how reviewer status is passed around internally
Mads Kiilerich <madski@unity3d.com>
parents:
5763
diff
changeset
|
102 pull_request_reviewers.append((user, status)) |
4359
cfd9115db2a5
pull requests: cleanup of PR status voting calculation
Mads Kiilerich <madski@unity3d.com>
parents:
4355
diff
changeset
|
103 |
5039
36d81185efe4
changeset_status: add unit tests for calculation of overall status
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
4919
diff
changeset
|
104 result = self._calculate_status(relevant_statuses) |
4359
cfd9115db2a5
pull requests: cleanup of PR status voting calculation
Mads Kiilerich <madski@unity3d.com>
parents:
4355
diff
changeset
|
105 |
cfd9115db2a5
pull requests: cleanup of PR status voting calculation
Mads Kiilerich <madski@unity3d.com>
parents:
4355
diff
changeset
|
106 return (pull_request_reviewers, |
cfd9115db2a5
pull requests: cleanup of PR status voting calculation
Mads Kiilerich <madski@unity3d.com>
parents:
4355
diff
changeset
|
107 pull_request_pending_reviewers, |
cfd9115db2a5
pull requests: cleanup of PR status voting calculation
Mads Kiilerich <madski@unity3d.com>
parents:
4355
diff
changeset
|
108 result) |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
109 |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
110 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
|
111 with_revisions=False): |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
112 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
|
113 with_revisions) |
4750
3752cf4972a7
status: explicitly use joinedload of authors instead of relying on lazy=join
Mads Kiilerich <madski@unity3d.com>
parents:
4526
diff
changeset
|
114 q = q.options(joinedload('author')) |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
115 return q.all() |
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
116 |
3176
7ec5f9c1df45
show comments from pull requests into associated changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3175
diff
changeset
|
117 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
|
118 """ |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
119 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
|
120 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
|
121 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
|
122 |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
123 :param repo: |
2440
1bc579bcd67a
- pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
124 :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
|
125 :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
|
126 :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
|
127 """ |
2481
4d3032431d4f
Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents:
2478
diff
changeset
|
128 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
|
129 |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
130 # 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
|
131 # returned from pull_request |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
132 status = q.first() |
3176
7ec5f9c1df45
show comments from pull requests into associated changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3175
diff
changeset
|
133 if as_str: |
4318
afbd43437237
pull requests: cleanup of messages and code
Mads Kiilerich <madski@unity3d.com>
parents:
4211
diff
changeset
|
134 return str(status.status) if status else ChangesetStatus.DEFAULT |
3176
7ec5f9c1df45
show comments from pull requests into associated changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
3175
diff
changeset
|
135 return status |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
136 |
4329
f54dca244402
changeset: refactor set_status so a comment always must be specified
Mads Kiilerich <madski@unity3d.com>
parents:
4318
diff
changeset
|
137 def set_status(self, repo, status, user, comment, revision=None, |
7429
471b29a2f302
model: changeset_status: remove support for 'dont_allow_on_closed_pull_request' and 'StatusChangeOnClosedPullRequestError'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
6864
diff
changeset
|
138 pull_request=None): |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
139 """ |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
140 Creates new status for changeset or updates the old ones bumping their |
4526
1f94dd1e2757
Fix readability issues in comments
Na'Tosha Bard <natosha@unity3d.com>
parents:
4360
diff
changeset
|
141 version, leaving the current status at the value of 'status'. |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
142 |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
143 :param repo: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
144 :param status: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
145 :param user: |
2286
9265958e33bb
Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2217
diff
changeset
|
146 :param comment: |
4360
05af189da2ae
pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents:
4359
diff
changeset
|
147 :param revision: |
05af189da2ae
pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents:
4359
diff
changeset
|
148 :param pull_request: |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
149 """ |
6464
d7d1e0a3850a
model: inline calls to BaseModel._get_repo
Søren Løvborg <sorenl@unity3d.com>
parents:
6463
diff
changeset
|
150 repo = Repository.guess_instance(repo) |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
151 |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
152 q = ChangesetStatus.query() |
4360
05af189da2ae
pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents:
4359
diff
changeset
|
153 if revision is not None: |
05af189da2ae
pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents:
4359
diff
changeset
|
154 assert pull_request is None |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
155 q = q.filter(ChangesetStatus.repo == repo) |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
156 q = q.filter(ChangesetStatus.revision == revision) |
4360
05af189da2ae
pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents:
4359
diff
changeset
|
157 revisions = [revision] |
05af189da2ae
pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents:
4359
diff
changeset
|
158 else: |
05af189da2ae
pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents:
4359
diff
changeset
|
159 assert pull_request is not None |
6119
91b38dc6d891
model: refactor and simplify _get_instance
Søren Løvborg <sorenl@unity3d.com>
parents:
6118
diff
changeset
|
160 pull_request = PullRequest.guess_instance(pull_request) |
4360
05af189da2ae
pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents:
4359
diff
changeset
|
161 repo = pull_request.org_repo |
05af189da2ae
pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents:
4359
diff
changeset
|
162 q = q.filter(ChangesetStatus.repo == 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
|
163 q = q.filter(ChangesetStatus.revision.in_(pull_request.revisions)) |
4360
05af189da2ae
pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents:
4359
diff
changeset
|
164 revisions = pull_request.revisions |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
165 cur_statuses = q.all() |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
166 |
6864
7691290837d2
codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents:
6523
diff
changeset
|
167 # update all current statuses with older version |
4360
05af189da2ae
pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents:
4359
diff
changeset
|
168 for st in cur_statuses: |
05af189da2ae
pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents:
4359
diff
changeset
|
169 st.version += 1 |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
170 |
4360
05af189da2ae
pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents:
4359
diff
changeset
|
171 new_statuses = [] |
05af189da2ae
pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents:
4359
diff
changeset
|
172 for rev in revisions: |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
173 new_status = ChangesetStatus() |
4359
cfd9115db2a5
pull requests: cleanup of PR status voting calculation
Mads Kiilerich <madski@unity3d.com>
parents:
4355
diff
changeset
|
174 new_status.version = 0 # default |
6463
eb1a4c3cb76c
model: inline BaseModel._get_user calls
Søren Løvborg <sorenl@unity3d.com>
parents:
6242
diff
changeset
|
175 new_status.author = User.guess_instance(user) |
6464
d7d1e0a3850a
model: inline calls to BaseModel._get_repo
Søren Løvborg <sorenl@unity3d.com>
parents:
6463
diff
changeset
|
176 new_status.repo = Repository.guess_instance(repo) |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
177 new_status.status = status |
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
178 new_status.comment = comment |
4360
05af189da2ae
pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents:
4359
diff
changeset
|
179 new_status.revision = rev |
2443
fd0a822481ec
- added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents:
2440
diff
changeset
|
180 new_status.pull_request = pull_request |
4360
05af189da2ae
pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents:
4359
diff
changeset
|
181 new_statuses.append(new_status) |
8685
dff9658bdd98
model: don't import Session from db - import meta and get it from the real source
Mads Kiilerich <mads@kiilerich.com>
parents:
7811
diff
changeset
|
182 meta.Session().add(new_status) |
4360
05af189da2ae
pull requests: refactor ChangesetStatus set_status and ChangesetComment create
Mads Kiilerich <madski@unity3d.com>
parents:
4359
diff
changeset
|
183 return new_statuses |