annotate rhodecode/model/changeset_status.py @ 3260:dadfcd30589f beta

use label for auto status change
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 29 Jan 2013 22:50:43 +0100
parents 32a283e5fd0d
children 3625fd19b201
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 """
2803
0b2214604c74 Fixed status of changesets in preview windows
Marcin Kuzminski <marcin@python-works.com>
parents: 2771
diff changeset
67 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
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
3176
7ec5f9c1df45 show comments from pull requests into associated changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3175
diff changeset
92 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
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:
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2432
diff changeset
99 :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
100 :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
101 :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
102 """
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
103 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
104
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
105 # 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
106 # returned from pull_request
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
107 status = q.first()
3176
7ec5f9c1df45 show comments from pull requests into associated changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3175
diff changeset
108 if as_str:
7ec5f9c1df45 show comments from pull requests into associated changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3175
diff changeset
109 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
110 st = status or ChangesetStatus.DEFAULT
7ec5f9c1df45 show comments from pull requests into associated changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3175
diff changeset
111 return str(st)
7ec5f9c1df45 show comments from pull requests into associated changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3175
diff changeset
112 return status
2217
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
113
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
114 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
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 :param revision:
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
122 :param status:
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
123 :param user:
2286
9265958e33bb Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents: 2217
diff changeset
124 :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
125 :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
126 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
127 mess around this manually
2217
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
128 """
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
129 repo = self._get_repo(repo)
2217
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
130
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
131 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
132 if not comment:
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 from rhodecode.model.comment import ChangesetCommentsModel
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
134 comment = ChangesetCommentsModel().create(
3260
dadfcd30589f use label for auto status change
Marcin Kuzminski <marcin@python-works.com>
parents: 3257
diff changeset
135 text='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
136 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
137 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
138 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
139 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
140 )
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
141 if revision:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
142 q = q.filter(ChangesetStatus.repo == repo)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
143 q = q.filter(ChangesetStatus.revision == revision)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
144 elif pull_request:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
145 pull_request = self.__get_pull_request(pull_request)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
146 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
147 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
148 cur_statuses = q.all()
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
149
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
150 #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
151 # 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
152 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
153 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
154 == 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
155 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
156 '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
157 )
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
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
159 #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
160 if cur_statuses:
8447d35b674e Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents: 2286
diff changeset
161 for st in cur_statuses:
8447d35b674e Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents: 2286
diff changeset
162 st.version += 1
8447d35b674e Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents: 2286
diff changeset
163 self.sa.add(st)
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
164
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
165 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
166 new_status = ChangesetStatus()
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
167 new_status.author = self._get_user(user)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
168 new_status.repo = self._get_repo(repo)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
169 new_status.status = status
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
170 new_status.comment = comment
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
171 new_status.revision = revision
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
172 new_status.pull_request = pull_request
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
173 return new_status
2217
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
174
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
175 if revision:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
176 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
177 comment=comment, revision=revision,
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
178 pull_request=None)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
179 self.sa.add(new_status)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
180 return new_status
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
181 elif pull_request:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
182 #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
183 #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
184 new_statuses = []
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
185 repo = pull_request.org_repo
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
186 for rev in pull_request.revisions:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
187 new_status = _create_status(user=user, repo=repo,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
188 status=status, comment=comment,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
189 revision=rev,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
190 pull_request=pull_request)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
191 new_statuses.append(new_status)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
192 self.sa.add(new_status)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
193 return new_statuses