annotate rhodecode/controllers/pullrequests.py @ 3566:5068bb494129 beta

stay on repo after forking and show full path to new fork This helps not getting lost after forking.
author Mads Kiilerich <madski@unity3d.com>
date Wed, 20 Mar 2013 12:22:13 +0100
parents 5b3313a5c6fc
children 9bc052942640
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 """
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 rhodecode.controllers.pullrequests
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 pull requests controller for rhodecode for initializing pull requests
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 :created_on: May 7, 2012
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 :author: marcink
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 :license: GPLv3, see COPYING for more details.
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 """
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 # This program is free software: you can redistribute it and/or modify
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 # it under the terms of the GNU General Public License as published by
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 # the Free Software Foundation, either version 3 of the License, or
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 # (at your option) any later version.
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 #
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 # This program is distributed in the hope that it will be useful,
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 # GNU General Public License for more details.
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 #
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 # You should have received a copy of the GNU General Public License
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 import logging
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 import traceback
2711
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
27 import formencode
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
28
2489
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
29 from webob.exc import HTTPNotFound, HTTPForbidden
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
30 from collections import defaultdict
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
31 from itertools import groupby
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 from pylons import request, response, session, tmpl_context as c, url
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 from pylons.controllers.util import abort, redirect
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 from pylons.i18n.translation import _
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
37 from rhodecode.lib.compat import json
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 from rhodecode.lib.base import BaseRepoController, render
2612
9364776d1331 Added autocomplete widget for pull request reviewers, in exchange of 90s style
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
39 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator,\
9364776d1331 Added autocomplete widget for pull request reviewers, in exchange of 90s style
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
40 NotAnonymous
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
41 from rhodecode.lib import helpers as h
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
42 from rhodecode.lib import diffs
3061
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3023
diff changeset
43 from rhodecode.lib.utils import action_logger, jsonify
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3023
diff changeset
44 from rhodecode.lib.vcs.exceptions import EmptyRepositoryError
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3023
diff changeset
45 from rhodecode.lib.vcs.backends.base import EmptyChangeset
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3023
diff changeset
46 from rhodecode.lib.diffs import LimitedDiffContainer
2489
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
47 from rhodecode.model.db import User, PullRequest, ChangesetStatus,\
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
48 ChangesetComment
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
49 from rhodecode.model.pull_request import PullRequestModel
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
50 from rhodecode.model.meta import Session
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
51 from rhodecode.model.repo import RepoModel
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
52 from rhodecode.model.comment import ChangesetCommentsModel
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
53 from rhodecode.model.changeset_status import ChangesetStatusModel
2711
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
54 from rhodecode.model.forms import PullRequestForm
3515
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
55 from mercurial import scmutil
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 log = logging.getLogger(__name__)
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 class PullrequestsController(BaseRepoController):
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 @LoginRequired()
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 'repository.admin')
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 def __before__(self):
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 super(PullrequestsController, self).__before__()
2612
9364776d1331 Added autocomplete widget for pull request reviewers, in exchange of 90s style
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
67 repo_model = RepoModel()
9364776d1331 Added autocomplete widget for pull request reviewers, in exchange of 90s style
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
68 c.users_array = repo_model.get_users_js()
9364776d1331 Added autocomplete widget for pull request reviewers, in exchange of 90s style
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
69 c.users_groups_array = repo_model.get_users_groups_js()
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70
3515
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
71 def _get_repo_refs(self, repo, rev=None, branch_rev=None):
3444
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
72 """return a structure with repo's interesting changesets, suitable for
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
73 the selectors in pullrequest.html"""
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
74 branches = [('branch:%s:%s' % (k, v), k)
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
75 for k, v in repo.branches.iteritems()]
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
76 bookmarks = [('book:%s:%s' % (k, v), k)
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
77 for k, v in repo.bookmarks.iteritems()]
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
78 tags = [('tag:%s:%s' % (k, v), k)
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
79 for k, v in repo.tags.iteritems()
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
80 if k != 'tip']
3329
f8c55b487c9a pull request: select 'tip' by default ... and show what it means right now
Mads Kiilerich <madski@unity3d.com>
parents: 3328
diff changeset
81
f8c55b487c9a pull request: select 'tip' by default ... and show what it means right now
Mads Kiilerich <madski@unity3d.com>
parents: 3328
diff changeset
82 tip = repo.tags['tip']
f8c55b487c9a pull request: select 'tip' by default ... and show what it means right now
Mads Kiilerich <madski@unity3d.com>
parents: 3328
diff changeset
83 colontip = ':' + tip
3444
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
84 tips = [x[1] for x in branches + bookmarks + tags
3329
f8c55b487c9a pull request: select 'tip' by default ... and show what it means right now
Mads Kiilerich <madski@unity3d.com>
parents: 3328
diff changeset
85 if x[0].endswith(colontip)]
3444
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
86 selected = 'tag:tip:%s' % tip
3515
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
87 special = [(selected, 'tip: %s' % ', '.join(tips))]
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88
3444
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
89 if rev:
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
90 selected = 'rev:%s:%s' % (rev, rev)
3515
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
91 special.append((selected, '%s: %s' % (_("Selected"), rev[:12])))
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
92
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
93 # list named branches that has been merged to this named branch - it should probably merge back
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
94 if branch_rev:
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
95 # not restricting to merge() would also get branch point and be better
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
96 # (especially because it would get the branch point) ... but is currently too expensive
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
97 revs = ["sort(parents(branch(id('%s')) and merge()) - branch(id('%s')))" %
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
98 (branch_rev, branch_rev)]
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
99 otherbranches = {}
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
100 for i in scmutil.revrange(repo._repo, revs):
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
101 cs = repo.get_changeset(i)
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
102 otherbranches[cs.branch] = cs.raw_id
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
103 for branch, node in otherbranches.iteritems():
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
104 selected = 'branch:%s:%s' % (branch, node)
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
105 special.append((selected, '%s: %s' % (_('Peer'), branch)))
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106
3444
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
107 return [(special, _("Special")),
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
108 (bookmarks, _("Bookmarks")),
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
109 (branches, _("Branches")),
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
110 (tags, _("Tags")),
c12603d5ee13 pullrequests: refactor changeset selectors, tip is special and not a real tag
Mads Kiilerich <madski@unity3d.com>
parents: 3442
diff changeset
111 ], selected
2849
2b672f04bfd9 fixed few issues with autoselection of revisions on pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2803
diff changeset
112
3104
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
113 def _get_is_allowed_change_status(self, pull_request):
3149
68f9c216377d white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3141
diff changeset
114 owner = self.rhodecode_user.user_id == pull_request.user_id
3104
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
115 reviewer = self.rhodecode_user.user_id in [x.user_id for x in
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
116 pull_request.reviewers]
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
117 return (self.rhodecode_user.admin or owner or reviewer)
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
118
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
119 def show_all(self, repo_name):
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
120 c.pull_requests = PullRequestModel().get_all(repo_name)
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
121 c.repo_name = repo_name
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
122 return render('/pullrequests/pullrequest_show_all.html')
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
123
2627
6bd62617b99f Opening pull request shouldn't be accessible by anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
124 @NotAnonymous()
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
125 def index(self):
2395
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
126 org_repo = c.rhodecode_db_repo
2444
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
127
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
128 if org_repo.scm_instance.alias != 'hg':
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
129 log.error('Review not available for GIT REPOS')
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
130 raise HTTPNotFound
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
131
2874
95923493de9a protect agains pull requests on empty repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2849
diff changeset
132 try:
95923493de9a protect agains pull requests on empty repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2849
diff changeset
133 org_repo.scm_instance.get_changeset()
95923493de9a protect agains pull requests on empty repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2849
diff changeset
134 except EmptyRepositoryError, e:
95923493de9a protect agains pull requests on empty repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2849
diff changeset
135 h.flash(h.literal(_('There are no changesets yet')),
95923493de9a protect agains pull requests on empty repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2849
diff changeset
136 category='warning')
95923493de9a protect agains pull requests on empty repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2849
diff changeset
137 redirect(url('summary_home', repo_name=org_repo.repo_name))
95923493de9a protect agains pull requests on empty repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2849
diff changeset
138
3485
b19b1723ff10 pullrequest: pullrequest from changelog view
Mads Kiilerich <madski@unity3d.com>
parents: 3484
diff changeset
139 org_rev = request.GET.get('rev_end')
b19b1723ff10 pullrequest: pullrequest from changelog view
Mads Kiilerich <madski@unity3d.com>
parents: 3484
diff changeset
140 # rev_start is not directly useful - its parent could however be used
b19b1723ff10 pullrequest: pullrequest from changelog view
Mads Kiilerich <madski@unity3d.com>
parents: 3484
diff changeset
141 # as default for other and thus give a simple compare view
b19b1723ff10 pullrequest: pullrequest from changelog view
Mads Kiilerich <madski@unity3d.com>
parents: 3484
diff changeset
142 #other_rev = request.POST.get('rev_start')
b19b1723ff10 pullrequest: pullrequest from changelog view
Mads Kiilerich <madski@unity3d.com>
parents: 3484
diff changeset
143
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
144 other_repos_info = {}
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
145
2395
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
146 c.org_repos = []
3330
dcd1c159a132 pull request: don't show fake path with owner names - and owner avatars is also not relevant
Mads Kiilerich <madski@unity3d.com>
parents: 3329
diff changeset
147 c.org_repos.append((org_repo.repo_name, org_repo.repo_name))
3329
f8c55b487c9a pull request: select 'tip' by default ... and show what it means right now
Mads Kiilerich <madski@unity3d.com>
parents: 3328
diff changeset
148 c.default_org_repo = org_repo.repo_name
3485
b19b1723ff10 pullrequest: pullrequest from changelog view
Mads Kiilerich <madski@unity3d.com>
parents: 3484
diff changeset
149 c.org_refs, c.default_org_ref = self._get_repo_refs(org_repo.scm_instance, org_rev)
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
150
3327
f285faa3a602 pull request: move code around and rename default variables
Mads Kiilerich <madski@unity3d.com>
parents: 3324
diff changeset
151 c.other_repos = []
f285faa3a602 pull request: move code around and rename default variables
Mads Kiilerich <madski@unity3d.com>
parents: 3324
diff changeset
152 # add org repo to other so we can open pull request against itself
f285faa3a602 pull request: move code around and rename default variables
Mads Kiilerich <madski@unity3d.com>
parents: 3324
diff changeset
153 c.other_repos.extend(c.org_repos)
f285faa3a602 pull request: move code around and rename default variables
Mads Kiilerich <madski@unity3d.com>
parents: 3324
diff changeset
154 c.default_other_repo = org_repo.repo_name
3515
5b3313a5c6fc pullrequest selection list: emphasize named branches that are neighbours
Mads Kiilerich <madski@unity3d.com>
parents: 3486
diff changeset
155 c.default_other_refs, c.default_other_ref = self._get_repo_refs(org_repo.scm_instance, branch_rev=org_rev)
3388
cb40b3f6428c review members are dynamically changed based on selected other_repo owner
Marcin Kuzminski <marcin@python-works.com>
parents: 3357
diff changeset
156 usr_data = lambda usr: dict(user_id=usr.user_id,
cb40b3f6428c review members are dynamically changed based on selected other_repo owner
Marcin Kuzminski <marcin@python-works.com>
parents: 3357
diff changeset
157 username=usr.username,
cb40b3f6428c review members are dynamically changed based on selected other_repo owner
Marcin Kuzminski <marcin@python-works.com>
parents: 3357
diff changeset
158 firstname=usr.firstname,
cb40b3f6428c review members are dynamically changed based on selected other_repo owner
Marcin Kuzminski <marcin@python-works.com>
parents: 3357
diff changeset
159 lastname=usr.lastname,
cb40b3f6428c review members are dynamically changed based on selected other_repo owner
Marcin Kuzminski <marcin@python-works.com>
parents: 3357
diff changeset
160 gravatar_link=h.gravatar_url(usr.email, 14))
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
161 other_repos_info[org_repo.repo_name] = {
3388
cb40b3f6428c review members are dynamically changed based on selected other_repo owner
Marcin Kuzminski <marcin@python-works.com>
parents: 3357
diff changeset
162 'user': usr_data(org_repo.user),
2720
0f7355d3c196 Load generated revs while switching to other sources of pull-requests.
Marcin Kuzminski <marcin@python-works.com>
parents: 2712
diff changeset
163 'description': org_repo.description,
3388
cb40b3f6428c review members are dynamically changed based on selected other_repo owner
Marcin Kuzminski <marcin@python-works.com>
parents: 3357
diff changeset
164 'revs': h.select('other_ref', c.default_other_ref,
cb40b3f6428c review members are dynamically changed based on selected other_repo owner
Marcin Kuzminski <marcin@python-works.com>
parents: 3357
diff changeset
165 c.default_other_refs, class_='refs')
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
166 }
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
167
3394
fe2bb88bf7ac whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3388
diff changeset
168 # gather forks and add to this list ... even though it is rare to
3388
cb40b3f6428c review members are dynamically changed based on selected other_repo owner
Marcin Kuzminski <marcin@python-works.com>
parents: 3357
diff changeset
169 # request forks to pull their parent
2395
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
170 for fork in org_repo.forks:
3330
dcd1c159a132 pull request: don't show fake path with owner names - and owner avatars is also not relevant
Mads Kiilerich <madski@unity3d.com>
parents: 3329
diff changeset
171 c.other_repos.append((fork.repo_name, fork.repo_name))
3329
f8c55b487c9a pull request: select 'tip' by default ... and show what it means right now
Mads Kiilerich <madski@unity3d.com>
parents: 3328
diff changeset
172 refs, default_ref = self._get_repo_refs(fork.scm_instance)
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
173 other_repos_info[fork.repo_name] = {
3388
cb40b3f6428c review members are dynamically changed based on selected other_repo owner
Marcin Kuzminski <marcin@python-works.com>
parents: 3357
diff changeset
174 'user': usr_data(fork.user),
2720
0f7355d3c196 Load generated revs while switching to other sources of pull-requests.
Marcin Kuzminski <marcin@python-works.com>
parents: 2712
diff changeset
175 'description': fork.description,
3329
f8c55b487c9a pull request: select 'tip' by default ... and show what it means right now
Mads Kiilerich <madski@unity3d.com>
parents: 3328
diff changeset
176 'revs': h.select('other_ref', default_ref, refs, class_='refs')
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
177 }
3327
f285faa3a602 pull request: move code around and rename default variables
Mads Kiilerich <madski@unity3d.com>
parents: 3324
diff changeset
178
f285faa3a602 pull request: move code around and rename default variables
Mads Kiilerich <madski@unity3d.com>
parents: 3324
diff changeset
179 # add parents of this fork also, but only if it's not empty
2933
07d620f6db2e pull requests throw an error if parent of fork didn't have any changesets yet. Now it's filter out from list of available sources
Marcin Kuzminski <marcin@python-works.com>
parents: 2893
diff changeset
180 if org_repo.parent and org_repo.parent.scm_instance.revisions:
3327
f285faa3a602 pull request: move code around and rename default variables
Mads Kiilerich <madski@unity3d.com>
parents: 3324
diff changeset
181 c.default_other_repo = org_repo.parent.repo_name
3329
f8c55b487c9a pull request: select 'tip' by default ... and show what it means right now
Mads Kiilerich <madski@unity3d.com>
parents: 3328
diff changeset
182 c.default_other_refs, c.default_other_ref = self._get_repo_refs(org_repo.parent.scm_instance)
3330
dcd1c159a132 pull request: don't show fake path with owner names - and owner avatars is also not relevant
Mads Kiilerich <madski@unity3d.com>
parents: 3329
diff changeset
183 c.other_repos.append((org_repo.parent.repo_name, org_repo.parent.repo_name))
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
184 other_repos_info[org_repo.parent.repo_name] = {
3388
cb40b3f6428c review members are dynamically changed based on selected other_repo owner
Marcin Kuzminski <marcin@python-works.com>
parents: 3357
diff changeset
185 'user': usr_data(org_repo.parent.user),
2720
0f7355d3c196 Load generated revs while switching to other sources of pull-requests.
Marcin Kuzminski <marcin@python-works.com>
parents: 2712
diff changeset
186 'description': org_repo.parent.description,
3388
cb40b3f6428c review members are dynamically changed based on selected other_repo owner
Marcin Kuzminski <marcin@python-works.com>
parents: 3357
diff changeset
187 'revs': h.select('other_ref', c.default_other_ref,
cb40b3f6428c review members are dynamically changed based on selected other_repo owner
Marcin Kuzminski <marcin@python-works.com>
parents: 3357
diff changeset
188 c.default_other_refs, class_='refs')
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
189 }
2395
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
190
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
191 c.other_repos_info = json.dumps(other_repos_info)
3388
cb40b3f6428c review members are dynamically changed based on selected other_repo owner
Marcin Kuzminski <marcin@python-works.com>
parents: 3357
diff changeset
192 # other repo owner
cb40b3f6428c review members are dynamically changed based on selected other_repo owner
Marcin Kuzminski <marcin@python-works.com>
parents: 3357
diff changeset
193 c.review_members = []
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
194 return render('/pullrequests/pullrequest.html')
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
195
2612
9364776d1331 Added autocomplete widget for pull request reviewers, in exchange of 90s style
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
196 @NotAnonymous()
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
197 def create(self, repo_name):
2893
eb180eb16c18 Fixed #585, checks for status of revision where to strict, and made opening pull request with those revision impossible due to previosly set status.
Marcin Kuzminski <marcin@python-works.com>
parents: 2892
diff changeset
198 repo = RepoModel()._get_repo(repo_name)
2711
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
199 try:
2893
eb180eb16c18 Fixed #585, checks for status of revision where to strict, and made opening pull request with those revision impossible due to previosly set status.
Marcin Kuzminski <marcin@python-works.com>
parents: 2892
diff changeset
200 _form = PullRequestForm(repo.repo_id)().to_python(request.POST)
2711
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
201 except formencode.Invalid, errors:
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
202 log.error(traceback.format_exc())
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
203 if errors.error_dict.get('revisions'):
2720
0f7355d3c196 Load generated revs while switching to other sources of pull-requests.
Marcin Kuzminski <marcin@python-works.com>
parents: 2712
diff changeset
204 msg = 'Revisions: %s' % errors.error_dict['revisions']
2711
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
205 elif errors.error_dict.get('pullrequest_title'):
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
206 msg = _('Pull request requires a title with min. 3 chars')
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
207 else:
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
208 msg = _('error during creation of pull request')
2612
9364776d1331 Added autocomplete widget for pull request reviewers, in exchange of 90s style
Marcin Kuzminski <marcin@python-works.com>
parents: 2608
diff changeset
209
2711
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
210 h.flash(msg, 'error')
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
211 return redirect(url('pullrequest_home', repo_name=repo_name))
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
212
2711
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
213 org_repo = _form['org_repo']
3486
2053053e0882 compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents: 3485
diff changeset
214 org_ref = 'rev:merge:%s' % _form['merge_rev']
2711
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
215 other_repo = _form['other_repo']
3486
2053053e0882 compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents: 3485
diff changeset
216 other_ref = 'rev:ancestor:%s' % _form['ancestor_rev']
2711
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
217 revisions = _form['revisions']
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
218 reviewers = _form['review_members']
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
219
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
220 title = _form['pullrequest_title']
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
221 description = _form['pullrequest_desc']
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
222
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
223 try:
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
224 pull_request = PullRequestModel().create(
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
225 self.rhodecode_user.user_id, org_repo, org_ref, other_repo,
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
226 other_ref, revisions, reviewers, title, description
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
227 )
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
228 Session().commit()
2533
5a826060251f redirect to pull-request overview after creation
Marcin Kuzminski <marcin@python-works.com>
parents: 2496
diff changeset
229 h.flash(_('Successfully opened new pull request'),
5a826060251f redirect to pull-request overview after creation
Marcin Kuzminski <marcin@python-works.com>
parents: 2496
diff changeset
230 category='success')
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
231 except Exception:
2533
5a826060251f redirect to pull-request overview after creation
Marcin Kuzminski <marcin@python-works.com>
parents: 2496
diff changeset
232 h.flash(_('Error occurred during sending pull request'),
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
233 category='error')
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
234 log.error(traceback.format_exc())
2711
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
235 return redirect(url('pullrequest_home', repo_name=repo_name))
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
236
2533
5a826060251f redirect to pull-request overview after creation
Marcin Kuzminski <marcin@python-works.com>
parents: 2496
diff changeset
237 return redirect(url('pullrequest_show', repo_name=other_repo,
5a826060251f redirect to pull-request overview after creation
Marcin Kuzminski <marcin@python-works.com>
parents: 2496
diff changeset
238 pull_request_id=pull_request.pull_request_id))
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
239
2614
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2612
diff changeset
240 @NotAnonymous()
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2612
diff changeset
241 @jsonify
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2612
diff changeset
242 def update(self, repo_name, pull_request_id):
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2612
diff changeset
243 pull_request = PullRequest.get_or_404(pull_request_id)
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2612
diff changeset
244 if pull_request.is_closed():
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2612
diff changeset
245 raise HTTPForbidden()
2769
52617fb79010 typos+docs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
246 #only owner or admin can update it
52617fb79010 typos+docs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
247 owner = pull_request.author.user_id == c.rhodecode_user.user_id
52617fb79010 typos+docs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
248 if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner:
52617fb79010 typos+docs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
249 reviewers_ids = map(int, filter(lambda v: v not in [None, ''],
52617fb79010 typos+docs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
250 request.POST.get('reviewers_ids', '').split(',')))
2712
7224882c4059 new summary for opened pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2711
diff changeset
251
2769
52617fb79010 typos+docs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
252 PullRequestModel().update_reviewers(pull_request_id, reviewers_ids)
3023
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
253 Session().commit()
2769
52617fb79010 typos+docs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
254 return True
52617fb79010 typos+docs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
255 raise HTTPForbidden()
2614
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2612
diff changeset
256
2746
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2720
diff changeset
257 @NotAnonymous()
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2720
diff changeset
258 @jsonify
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2720
diff changeset
259 def delete(self, repo_name, pull_request_id):
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2720
diff changeset
260 pull_request = PullRequest.get_or_404(pull_request_id)
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2720
diff changeset
261 #only owner can delete it !
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2720
diff changeset
262 if pull_request.author.user_id == c.rhodecode_user.user_id:
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2720
diff changeset
263 PullRequestModel().delete(pull_request)
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2720
diff changeset
264 Session().commit()
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2720
diff changeset
265 h.flash(_('Successfully deleted pull request'),
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2720
diff changeset
266 category='success')
3023
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
267 return redirect(url('admin_settings_my_account', anchor='pullrequests'))
2769
52617fb79010 typos+docs.
Marcin Kuzminski <marcin@python-works.com>
parents: 2746
diff changeset
268 raise HTTPForbidden()
2746
49a4864b11c1 Authors of pull-requests can now delete them
Marcin Kuzminski <marcin@python-works.com>
parents: 2720
diff changeset
269
2608
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
270 def _load_compare_data(self, pull_request, enable_comments=True):
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
271 """
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
272 Load context data needed for generating compare diff
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
273
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
274 :param pull_request:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
275 :type pull_request:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
276 """
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
277 org_repo = pull_request.org_repo
2711
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
278 (org_ref_type,
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
279 org_ref_name,
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
280 org_ref_rev) = pull_request.org_ref.split(':')
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
281
3023
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
282 other_repo = org_repo
2711
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
283 (other_ref_type,
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
284 other_ref_name,
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
285 other_ref_rev) = pull_request.other_ref.split(':')
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
286
2720
0f7355d3c196 Load generated revs while switching to other sources of pull-requests.
Marcin Kuzminski <marcin@python-works.com>
parents: 2712
diff changeset
287 # despite opening revisions for bookmarks/branches/tags, we always
3484
75e563531350 compare: drop unused rev_start and rev_end
Mads Kiilerich <madski@unity3d.com>
parents: 3447
diff changeset
288 # convert this to rev to prevent changes after bookmark or branch change
2711
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
289 org_ref = ('rev', org_ref_rev)
1de45f582f9d added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents: 2627
diff changeset
290 other_ref = ('rev', other_ref_rev)
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
291
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
292 c.org_repo = org_repo
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
293 c.other_repo = other_repo
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
294
3023
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
295 c.fulldiff = fulldiff = request.GET.get('fulldiff')
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
296
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
297 c.cs_ranges = [org_repo.get_changeset(x) for x in pull_request.revisions]
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
298
2803
0b2214604c74 Fixed status of changesets in preview windows
Marcin Kuzminski <marcin@python-works.com>
parents: 2796
diff changeset
299 c.statuses = org_repo.statuses([x.raw_id for x in c.cs_ranges])
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
300
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
301 c.org_ref = org_ref[1]
3357
674a8fad3abc show links to files on compare data at other and org refs
Marcin Kuzminski <marcin@python-works.com>
parents: 3330
diff changeset
302 c.org_ref_type = org_ref[0]
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
303 c.other_ref = other_ref[1]
3357
674a8fad3abc show links to files on compare data at other and org refs
Marcin Kuzminski <marcin@python-works.com>
parents: 3330
diff changeset
304 c.other_ref_type = other_ref[0]
3023
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
305
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
306 diff_limit = self.cut_off_limit if not fulldiff else None
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
307
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
308 #we swap org/other ref since we run a simple diff on one repo
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
309 _diff = diffs.differ(org_repo, other_ref, other_repo, org_ref)
3015
16af24982e30 Multiple changes for compare system
Marcin Kuzminski <marcin@python-works.com>
parents: 2995
diff changeset
310
3023
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
311 diff_processor = diffs.DiffProcessor(_diff or '', format='gitdiff',
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
312 diff_limit=diff_limit)
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
313 _parsed = diff_processor.prepare()
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
314
3023
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
315 c.limited_diff = False
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
316 if isinstance(_parsed, LimitedDiffContainer):
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
317 c.limited_diff = True
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
318
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
319 c.files = []
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
320 c.changes = {}
3023
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
321 c.lines_added = 0
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
322 c.lines_deleted = 0
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
323 for f in _parsed:
3023
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
324 st = f['stats']
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
325 if st[0] != 'b':
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
326 c.lines_added += st[0]
c2a206162062 Basic implementation of cherry picking changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 3015
diff changeset
327 c.lines_deleted += st[1]
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
328 fid = h.FID('', f['filename'])
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
329 c.files.append([fid, f['operation'], f['filename'], f['stats']])
2608
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
330 diff = diff_processor.as_html(enable_comments=enable_comments,
2995
32471bd1f4ee Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents: 2933
diff changeset
331 parsed_lines=[f])
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
332 c.changes[fid] = [f['operation'], f['filename'], diff]
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
333
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
334 def show(self, repo_name, pull_request_id):
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
335 repo_model = RepoModel()
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
336 c.users_array = repo_model.get_users_js()
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
337 c.users_groups_array = repo_model.get_users_groups_js()
2496
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2489
diff changeset
338 c.pull_request = PullRequest.get_or_404(pull_request_id)
3104
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
339 c.allowed_to_change_status = self._get_is_allowed_change_status(c.pull_request)
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
340 cc_model = ChangesetCommentsModel()
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
341 cs_model = ChangesetStatusModel()
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
342 _cs_statuses = cs_model.get_statuses(c.pull_request.org_repo,
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
343 pull_request=c.pull_request,
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
344 with_revisions=True)
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
345
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
346 cs_statuses = defaultdict(list)
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
347 for st in _cs_statuses:
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
348 cs_statuses[st.author.username] += [st]
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
349
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
350 c.pull_request_reviewers = []
2712
7224882c4059 new summary for opened pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2711
diff changeset
351 c.pull_request_pending_reviewers = []
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
352 for o in c.pull_request.reviewers:
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
353 st = cs_statuses.get(o.user.username, None)
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
354 if st:
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
355 sorter = lambda k: k.version
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
356 st = [(x, list(y)[0])
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
357 for x, y in (groupby(sorted(st, key=sorter), sorter))]
2712
7224882c4059 new summary for opened pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2711
diff changeset
358 else:
7224882c4059 new summary for opened pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2711
diff changeset
359 c.pull_request_pending_reviewers.append(o.user)
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
360 c.pull_request_reviewers.append([o.user, st])
2444
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
361
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
362 # pull_requests repo_name we opened it against
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
363 # ie. other_repo must match
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
364 if repo_name != c.pull_request.other_repo.repo_name:
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
365 raise HTTPNotFound
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
366
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
367 # load compare data into template context
2608
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
368 enable_comments = not c.pull_request.is_closed()
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
369 self._load_compare_data(c.pull_request, enable_comments=enable_comments)
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
370
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
371 # inline comments
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
372 c.inline_cnt = 0
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
373 c.inline_comments = cc_model.get_inline_comments(
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
374 c.rhodecode_db_repo.repo_id,
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
375 pull_request=pull_request_id)
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
376 # count inline comments
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
377 for __, lines in c.inline_comments:
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
378 for comments in lines.values():
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
379 c.inline_cnt += len(comments)
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
380 # comments
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
381 c.comments = cc_model.get_comments(c.rhodecode_db_repo.repo_id,
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
382 pull_request=pull_request_id)
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
383
2803
0b2214604c74 Fixed status of changesets in preview windows
Marcin Kuzminski <marcin@python-works.com>
parents: 2796
diff changeset
384 try:
0b2214604c74 Fixed status of changesets in preview windows
Marcin Kuzminski <marcin@python-works.com>
parents: 2796
diff changeset
385 cur_status = c.statuses[c.pull_request.revisions[0]][0]
0b2214604c74 Fixed status of changesets in preview windows
Marcin Kuzminski <marcin@python-works.com>
parents: 2796
diff changeset
386 except:
0b2214604c74 Fixed status of changesets in preview windows
Marcin Kuzminski <marcin@python-works.com>
parents: 2796
diff changeset
387 log.error(traceback.format_exc())
0b2214604c74 Fixed status of changesets in preview windows
Marcin Kuzminski <marcin@python-works.com>
parents: 2796
diff changeset
388 cur_status = 'undefined'
0b2214604c74 Fixed status of changesets in preview windows
Marcin Kuzminski <marcin@python-works.com>
parents: 2796
diff changeset
389 if c.pull_request.is_closed() and 0:
0b2214604c74 Fixed status of changesets in preview windows
Marcin Kuzminski <marcin@python-works.com>
parents: 2796
diff changeset
390 c.current_changeset_status = cur_status
0b2214604c74 Fixed status of changesets in preview windows
Marcin Kuzminski <marcin@python-works.com>
parents: 2796
diff changeset
391 else:
0b2214604c74 Fixed status of changesets in preview windows
Marcin Kuzminski <marcin@python-works.com>
parents: 2796
diff changeset
392 # changeset(pull-request) status calulation based on reviewers
0b2214604c74 Fixed status of changesets in preview windows
Marcin Kuzminski <marcin@python-works.com>
parents: 2796
diff changeset
393 c.current_changeset_status = cs_model.calculate_status(
0b2214604c74 Fixed status of changesets in preview windows
Marcin Kuzminski <marcin@python-works.com>
parents: 2796
diff changeset
394 c.pull_request_reviewers,
0b2214604c74 Fixed status of changesets in preview windows
Marcin Kuzminski <marcin@python-works.com>
parents: 2796
diff changeset
395 )
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
396 c.changeset_statuses = ChangesetStatus.STATUSES
2803
0b2214604c74 Fixed status of changesets in preview windows
Marcin Kuzminski <marcin@python-works.com>
parents: 2796
diff changeset
397
3442
b3680a200f75 compare: cleanup of as_form handling
Mads Kiilerich <madski@unity3d.com>
parents: 3430
diff changeset
398 c.as_form = False
3486
2053053e0882 compare/pullrequest: introduce merge parameter
Mads Kiilerich <madski@unity3d.com>
parents: 3485
diff changeset
399 c.ancestor = None # there is one - but right here we don't know which
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
400 return render('/pullrequests/pullrequest_show.html')
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
401
2627
6bd62617b99f Opening pull request shouldn't be accessible by anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
402 @NotAnonymous()
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
403 @jsonify
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
404 def comment(self, repo_name, pull_request_id):
2608
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
405 pull_request = PullRequest.get_or_404(pull_request_id)
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
406 if pull_request.is_closed():
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
407 raise HTTPForbidden()
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
408
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
409 status = request.POST.get('changeset_status')
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
410 change_status = request.POST.get('change_changeset_status')
2796
bf3c976d02ec always post text about status changes of code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 2769
diff changeset
411 text = request.POST.get('text')
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
412 close_pr = request.POST.get('save_close')
3104
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
413
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
414 allowed_to_change_status = self._get_is_allowed_change_status(pull_request)
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
415 if status and change_status and allowed_to_change_status:
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
416 _def = (_('status change -> %s')
2796
bf3c976d02ec always post text about status changes of code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 2769
diff changeset
417 % ChangesetStatus.get_status_lbl(status))
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
418 if close_pr:
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
419 _def = _('Closing with') + ' ' + _def
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
420 text = text or _def
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
421 comm = ChangesetCommentsModel().create(
2796
bf3c976d02ec always post text about status changes of code-review
Marcin Kuzminski <marcin@python-works.com>
parents: 2769
diff changeset
422 text=text,
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
423 repo=c.rhodecode_db_repo.repo_id,
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
424 user=c.rhodecode_user.user_id,
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
425 pull_request=pull_request_id,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
426 f_path=request.POST.get('f_path'),
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
427 line_no=request.POST.get('line'),
2478
8eab81115660 white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 2444
diff changeset
428 status_change=(ChangesetStatus.get_status_lbl(status)
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
429 if status and change_status
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
430 and allowed_to_change_status else None),
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
431 closing_pr=close_pr
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
432 )
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
433
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
434 action_logger(self.rhodecode_user,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
435 'user_commented_pull_request:%s' % pull_request_id,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
436 c.rhodecode_db_repo, self.ip_addr, self.sa)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
437
3104
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
438 if allowed_to_change_status:
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
439 # get status if set !
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
440 if status and change_status:
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
441 ChangesetStatusModel().set_status(
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
442 c.rhodecode_db_repo.repo_id,
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
443 status,
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
444 c.rhodecode_user.user_id,
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
445 comm,
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
446 pull_request=pull_request_id
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
447 )
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
448
3430
bbe21df7ad48 notifications changes
Marcin Kuzminski <marcin@python-works.com>
parents: 3394
diff changeset
449 if close_pr:
3104
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
450 if status in ['rejected', 'approved']:
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
451 PullRequestModel().close_pull_request(pull_request_id)
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
452 action_logger(self.rhodecode_user,
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
453 'user_closed_pull_request:%s' % pull_request_id,
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
454 c.rhodecode_db_repo, self.ip_addr, self.sa)
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
455 else:
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
456 h.flash(_('Closing pull request on other statuses than '
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
457 'rejected or approved forbidden'),
c77d5c6358eb Implemented #670 Implementation of Roles in Pull Request
Marcin Kuzminski <marcin@python-works.com>
parents: 3103
diff changeset
458 category='warning')
2608
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
459
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
460 Session().commit()
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
461
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
462 if not request.environ.get('HTTP_X_PARTIAL_XHR'):
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
463 return redirect(h.url('pullrequest_show', repo_name=repo_name,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
464 pull_request_id=pull_request_id))
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
465
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
466 data = {
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
467 'target_id': h.safeid(h.safe_unicode(request.POST.get('f_path'))),
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
468 }
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
469 if comm:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
470 c.co = comm
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
471 data.update(comm.get_dict())
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
472 data.update({'rendered_text':
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
473 render('changeset/changeset_comment_block.html')})
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
474
2444
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
475 return data
2489
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
476
2627
6bd62617b99f Opening pull request shouldn't be accessible by anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 2614
diff changeset
477 @NotAnonymous()
2489
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
478 @jsonify
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
479 def delete_comment(self, repo_name, comment_id):
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
480 co = ChangesetComment.get(comment_id)
2608
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
481 if co.pull_request.is_closed():
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
482 #don't allow deleting comments on closed pull request
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
483 raise HTTPForbidden()
58c529332e7e Added option to close pull requests, in future that will be close & merge
Marcin Kuzminski <marcin@python-works.com>
parents: 2570
diff changeset
484
3141
a45191e7c7bb access control: fix owner checks - they were always true
Mads Kiilerich <madski@unity3d.com>
parents: 3123
diff changeset
485 owner = co.author.user_id == c.rhodecode_user.user_id
2489
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
486 if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner:
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
487 ChangesetCommentsModel().delete(comment=co)
2541
1c2ba03c42b4 Added dynamic data loading for other repo we open pull request against
Marcin Kuzminski <marcin@python-works.com>
parents: 2533
diff changeset
488 Session().commit()
2489
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
489 return True
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
490 else:
2614
3f50a5e8fc4d Added editing of pull-request reviewers.
Marcin Kuzminski <marcin@python-works.com>
parents: 2612
diff changeset
491 raise HTTPForbidden()