|
@@
-51,7
+51,7
b' from rhodecode.model import BaseModel'
|
|
51
|
from rhodecode.model.changeset_status import ChangesetStatusModel
|
|
51
|
from rhodecode.model.changeset_status import ChangesetStatusModel
|
|
52
|
from rhodecode.model.comment import CommentsModel
|
|
52
|
from rhodecode.model.comment import CommentsModel
|
|
53
|
from rhodecode.model.db import (
|
|
53
|
from rhodecode.model.db import (
|
|
54
|
or_, PullRequest, PullRequestReviewers, ChangesetStatus,
|
|
54
|
or_, String, cast, PullRequest, PullRequestReviewers, ChangesetStatus,
|
|
55
|
PullRequestVersion, ChangesetComment, Repository, RepoReviewRule)
|
|
55
|
PullRequestVersion, ChangesetComment, Repository, RepoReviewRule)
|
|
56
|
from rhodecode.model.meta import Session
|
|
56
|
from rhodecode.model.meta import Session
|
|
57
|
from rhodecode.model.notification import NotificationModel, \
|
|
57
|
from rhodecode.model.notification import NotificationModel, \
|
|
@@
-137,8
+137,8
b' class PullRequestModel(BaseModel):'
|
|
137
|
def get(self, pull_request):
|
|
137
|
def get(self, pull_request):
|
|
138
|
return self.__get_pull_request(pull_request)
|
|
138
|
return self.__get_pull_request(pull_request)
|
|
139
|
|
|
139
|
|
|
140
|
def _prepare_get_all_query(self, repo_name, source=False, statuses=None,
|
|
140
|
def _prepare_get_all_query(self, repo_name, search_q=None, source=False,
|
|
141
|
opened_by=None, order_by=None,
|
|
141
|
statuses=None, opened_by=None, order_by=None,
|
|
142
|
order_dir='desc', only_created=False):
|
|
142
|
order_dir='desc', only_created=False):
|
|
143
|
repo = None
|
|
143
|
repo = None
|
|
144
|
if repo_name:
|
|
144
|
if repo_name:
|
|
@@
-146,6
+146,14
b' class PullRequestModel(BaseModel):'
|
|
146
|
|
|
146
|
|
|
147
|
q = PullRequest.query()
|
|
147
|
q = PullRequest.query()
|
|
148
|
|
|
148
|
|
|
|
|
|
149
|
if search_q:
|
|
|
|
|
150
|
like_expression = u'%{}%'.format(safe_unicode(search_q))
|
|
|
|
|
151
|
q = q.filter(or_(
|
|
|
|
|
152
|
cast(PullRequest.pull_request_id, String).ilike(like_expression),
|
|
|
|
|
153
|
PullRequest.title.ilike(like_expression),
|
|
|
|
|
154
|
PullRequest.description.ilike(like_expression),
|
|
|
|
|
155
|
))
|
|
|
|
|
156
|
|
|
149
|
# source or target
|
|
157
|
# source or target
|
|
150
|
if repo and source:
|
|
158
|
if repo and source:
|
|
151
|
q = q.filter(PullRequest.source_repo == repo)
|
|
159
|
q = q.filter(PullRequest.source_repo == repo)
|
|
@@
-179,28
+187,31
b' class PullRequestModel(BaseModel):'
|
|
179
|
|
|
187
|
|
|
180
|
return q
|
|
188
|
return q
|
|
181
|
|
|
189
|
|
|
182
|
def count_all(self, repo_name, source=False, statuses=None,
|
|
190
|
def count_all(self, repo_name, search_q=None, source=False, statuses=None,
|
|
183
|
opened_by=None):
|
|
191
|
opened_by=None):
|
|
184
|
"""
|
|
192
|
"""
|
|
185
|
Count the number of pull requests for a specific repository.
|
|
193
|
Count the number of pull requests for a specific repository.
|
|
186
|
|
|
194
|
|
|
187
|
:param repo_name: target or source repo
|
|
195
|
:param repo_name: target or source repo
|
|
|
|
|
196
|
:param search_q: filter by text
|
|
188
|
:param source: boolean flag to specify if repo_name refers to source
|
|
197
|
:param source: boolean flag to specify if repo_name refers to source
|
|
189
|
:param statuses: list of pull request statuses
|
|
198
|
:param statuses: list of pull request statuses
|
|
190
|
:param opened_by: author user of the pull request
|
|
199
|
:param opened_by: author user of the pull request
|
|
191
|
:returns: int number of pull requests
|
|
200
|
:returns: int number of pull requests
|
|
192
|
"""
|
|
201
|
"""
|
|
193
|
q = self._prepare_get_all_query(
|
|
202
|
q = self._prepare_get_all_query(
|
|
194
|
repo_name, source=source, statuses=statuses, opened_by=opened_by)
|
|
203
|
repo_name, search_q=search_q, source=source, statuses=statuses,
|
|
|
|
|
204
|
opened_by=opened_by)
|
|
195
|
|
|
205
|
|
|
196
|
return q.count()
|
|
206
|
return q.count()
|
|
197
|
|
|
207
|
|
|
198
|
def get_all(self, repo_name, source=False, statuses=None, opened_by=None,
|
|
208
|
def get_all(self, repo_name, search_q=None, source=False, statuses=None,
|
|
199
|
offset=0, length=None, order_by=None, order_dir='desc'):
|
|
209
|
opened_by=None, offset=0, length=None, order_by=None, order_dir='desc'):
|
|
200
|
"""
|
|
210
|
"""
|
|
201
|
Get all pull requests for a specific repository.
|
|
211
|
Get all pull requests for a specific repository.
|
|
202
|
|
|
212
|
|
|
203
|
:param repo_name: target or source repo
|
|
213
|
:param repo_name: target or source repo
|
|
|
|
|
214
|
:param search_q: filter by text
|
|
204
|
:param source: boolean flag to specify if repo_name refers to source
|
|
215
|
:param source: boolean flag to specify if repo_name refers to source
|
|
205
|
:param statuses: list of pull request statuses
|
|
216
|
:param statuses: list of pull request statuses
|
|
206
|
:param opened_by: author user of the pull request
|
|
217
|
:param opened_by: author user of the pull request
|
|
@@
-211,8
+222,8
b' class PullRequestModel(BaseModel):'
|
|
211
|
:returns: list of pull requests
|
|
222
|
:returns: list of pull requests
|
|
212
|
"""
|
|
223
|
"""
|
|
213
|
q = self._prepare_get_all_query(
|
|
224
|
q = self._prepare_get_all_query(
|
|
214
|
repo_name, source=source, statuses=statuses, opened_by=opened_by,
|
|
225
|
repo_name, search_q=search_q, source=source, statuses=statuses,
|
|
215
|
order_by=order_by, order_dir=order_dir)
|
|
226
|
opened_by=opened_by, order_by=order_by, order_dir=order_dir)
|
|
216
|
|
|
227
|
|
|
217
|
if length:
|
|
228
|
if length:
|
|
218
|
pull_requests = q.limit(length).offset(offset).all()
|
|
229
|
pull_requests = q.limit(length).offset(offset).all()
|
|
@@
-221,24
+232,25
b' class PullRequestModel(BaseModel):'
|
|
221
|
|
|
232
|
|
|
222
|
return pull_requests
|
|
233
|
return pull_requests
|
|
223
|
|
|
234
|
|
|
224
|
def count_awaiting_review(self, repo_name, source=False, statuses=None,
|
|
235
|
def count_awaiting_review(self, repo_name, search_q=None, source=False, statuses=None,
|
|
225
|
opened_by=None):
|
|
236
|
opened_by=None):
|
|
226
|
"""
|
|
237
|
"""
|
|
227
|
Count the number of pull requests for a specific repository that are
|
|
238
|
Count the number of pull requests for a specific repository that are
|
|
228
|
awaiting review.
|
|
239
|
awaiting review.
|
|
229
|
|
|
240
|
|
|
230
|
:param repo_name: target or source repo
|
|
241
|
:param repo_name: target or source repo
|
|
|
|
|
242
|
:param search_q: filter by text
|
|
231
|
:param source: boolean flag to specify if repo_name refers to source
|
|
243
|
:param source: boolean flag to specify if repo_name refers to source
|
|
232
|
:param statuses: list of pull request statuses
|
|
244
|
:param statuses: list of pull request statuses
|
|
233
|
:param opened_by: author user of the pull request
|
|
245
|
:param opened_by: author user of the pull request
|
|
234
|
:returns: int number of pull requests
|
|
246
|
:returns: int number of pull requests
|
|
235
|
"""
|
|
247
|
"""
|
|
236
|
pull_requests = self.get_awaiting_review(
|
|
248
|
pull_requests = self.get_awaiting_review(
|
|
237
|
repo_name, source=source, statuses=statuses, opened_by=opened_by)
|
|
249
|
repo_name, search_q=search_q, source=source, statuses=statuses, opened_by=opened_by)
|
|
238
|
|
|
250
|
|
|
239
|
return len(pull_requests)
|
|
251
|
return len(pull_requests)
|
|
240
|
|
|
252
|
|
|
241
|
def get_awaiting_review(self, repo_name, source=False, statuses=None,
|
|
253
|
def get_awaiting_review(self, repo_name, search_q=None, source=False, statuses=None,
|
|
242
|
opened_by=None, offset=0, length=None,
|
|
254
|
opened_by=None, offset=0, length=None,
|
|
243
|
order_by=None, order_dir='desc'):
|
|
255
|
order_by=None, order_dir='desc'):
|
|
244
|
"""
|
|
256
|
"""
|
|
@@
-246,6
+258,7
b' class PullRequestModel(BaseModel):'
|
|
246
|
review.
|
|
258
|
review.
|
|
247
|
|
|
259
|
|
|
248
|
:param repo_name: target or source repo
|
|
260
|
:param repo_name: target or source repo
|
|
|
|
|
261
|
:param search_q: filter by text
|
|
249
|
:param source: boolean flag to specify if repo_name refers to source
|
|
262
|
:param source: boolean flag to specify if repo_name refers to source
|
|
250
|
:param statuses: list of pull request statuses
|
|
263
|
:param statuses: list of pull request statuses
|
|
251
|
:param opened_by: author user of the pull request
|
|
264
|
:param opened_by: author user of the pull request
|
|
@@
-256,8
+269,8
b' class PullRequestModel(BaseModel):'
|
|
256
|
:returns: list of pull requests
|
|
269
|
:returns: list of pull requests
|
|
257
|
"""
|
|
270
|
"""
|
|
258
|
pull_requests = self.get_all(
|
|
271
|
pull_requests = self.get_all(
|
|
259
|
repo_name, source=source, statuses=statuses, opened_by=opened_by,
|
|
272
|
repo_name, search_q=search_q, source=source, statuses=statuses,
|
|
260
|
order_by=order_by, order_dir=order_dir)
|
|
273
|
opened_by=opened_by, order_by=order_by, order_dir=order_dir)
|
|
261
|
|
|
274
|
|
|
262
|
_filtered_pull_requests = []
|
|
275
|
_filtered_pull_requests = []
|
|
263
|
for pr in pull_requests:
|
|
276
|
for pr in pull_requests:
|
|
@@
-270,13
+283,14
b' class PullRequestModel(BaseModel):'
|
|
270
|
else:
|
|
283
|
else:
|
|
271
|
return _filtered_pull_requests
|
|
284
|
return _filtered_pull_requests
|
|
272
|
|
|
285
|
|
|
273
|
def count_awaiting_my_review(self, repo_name, source=False, statuses=None,
|
|
286
|
def count_awaiting_my_review(self, repo_name, search_q=None, source=False, statuses=None,
|
|
274
|
opened_by=None, user_id=None):
|
|
287
|
opened_by=None, user_id=None):
|
|
275
|
"""
|
|
288
|
"""
|
|
276
|
Count the number of pull requests for a specific repository that are
|
|
289
|
Count the number of pull requests for a specific repository that are
|
|
277
|
awaiting review from a specific user.
|
|
290
|
awaiting review from a specific user.
|
|
278
|
|
|
291
|
|
|
279
|
:param repo_name: target or source repo
|
|
292
|
:param repo_name: target or source repo
|
|
|
|
|
293
|
:param search_q: filter by text
|
|
280
|
:param source: boolean flag to specify if repo_name refers to source
|
|
294
|
:param source: boolean flag to specify if repo_name refers to source
|
|
281
|
:param statuses: list of pull request statuses
|
|
295
|
:param statuses: list of pull request statuses
|
|
282
|
:param opened_by: author user of the pull request
|
|
296
|
:param opened_by: author user of the pull request
|
|
@@
-284,12
+298,12
b' class PullRequestModel(BaseModel):'
|
|
284
|
:returns: int number of pull requests
|
|
298
|
:returns: int number of pull requests
|
|
285
|
"""
|
|
299
|
"""
|
|
286
|
pull_requests = self.get_awaiting_my_review(
|
|
300
|
pull_requests = self.get_awaiting_my_review(
|
|
287
|
repo_name, source=source, statuses=statuses, opened_by=opened_by,
|
|
301
|
repo_name, search_q=search_q, source=source, statuses=statuses,
|
|
288
|
user_id=user_id)
|
|
302
|
opened_by=opened_by, user_id=user_id)
|
|
289
|
|
|
303
|
|
|
290
|
return len(pull_requests)
|
|
304
|
return len(pull_requests)
|
|
291
|
|
|
305
|
|
|
292
|
def get_awaiting_my_review(self, repo_name, source=False, statuses=None,
|
|
306
|
def get_awaiting_my_review(self, repo_name, search_q=None, source=False, statuses=None,
|
|
293
|
opened_by=None, user_id=None, offset=0,
|
|
307
|
opened_by=None, user_id=None, offset=0,
|
|
294
|
length=None, order_by=None, order_dir='desc'):
|
|
308
|
length=None, order_by=None, order_dir='desc'):
|
|
295
|
"""
|
|
309
|
"""
|
|
@@
-297,6
+311,7
b' class PullRequestModel(BaseModel):'
|
|
297
|
review from a specific user.
|
|
311
|
review from a specific user.
|
|
298
|
|
|
312
|
|
|
299
|
:param repo_name: target or source repo
|
|
313
|
:param repo_name: target or source repo
|
|
|
|
|
314
|
:param search_q: filter by text
|
|
300
|
:param source: boolean flag to specify if repo_name refers to source
|
|
315
|
:param source: boolean flag to specify if repo_name refers to source
|
|
301
|
:param statuses: list of pull request statuses
|
|
316
|
:param statuses: list of pull request statuses
|
|
302
|
:param opened_by: author user of the pull request
|
|
317
|
:param opened_by: author user of the pull request
|
|
@@
-308,8
+323,8
b' class PullRequestModel(BaseModel):'
|
|
308
|
:returns: list of pull requests
|
|
323
|
:returns: list of pull requests
|
|
309
|
"""
|
|
324
|
"""
|
|
310
|
pull_requests = self.get_all(
|
|
325
|
pull_requests = self.get_all(
|
|
311
|
repo_name, source=source, statuses=statuses, opened_by=opened_by,
|
|
326
|
repo_name, search_q=search_q, source=source, statuses=statuses,
|
|
312
|
order_by=order_by, order_dir=order_dir)
|
|
327
|
opened_by=opened_by, order_by=order_by, order_dir=order_dir)
|
|
313
|
|
|
328
|
|
|
314
|
_my = PullRequestModel().get_not_reviewed(user_id)
|
|
329
|
_my = PullRequestModel().get_not_reviewed(user_id)
|
|
315
|
my_participation = []
|
|
330
|
my_participation = []
|