##// END OF EJS Templates
Fixed origin repo in pull-request view
marcink -
r2487:995d938c beta
parent child Browse files
Show More
@@ -1,103 +1,104 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.controllers.compare
3 rhodecode.controllers.compare
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5
6 compare controller for pylons showoing differences between two
6 compare controller for pylons showoing differences between two
7 repos, branches, bookmarks or tips
7 repos, branches, bookmarks or tips
8
8
9 :created_on: May 6, 2012
9 :created_on: May 6, 2012
10 :author: marcink
10 :author: marcink
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
12 :license: GPLv3, see COPYING for more details.
12 :license: GPLv3, see COPYING for more details.
13 """
13 """
14 # This program is free software: you can redistribute it and/or modify
14 # This program is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation, either version 3 of the License, or
16 # the Free Software Foundation, either version 3 of the License, or
17 # (at your option) any later version.
17 # (at your option) any later version.
18 #
18 #
19 # This program is distributed in the hope that it will be useful,
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
22 # GNU General Public License for more details.
23 #
23 #
24 # You should have received a copy of the GNU General Public License
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 import logging
26 import logging
27 import traceback
27 import traceback
28
28
29 from webob.exc import HTTPNotFound
29 from webob.exc import HTTPNotFound
30 from pylons import request, response, session, tmpl_context as c, url
30 from pylons import request, response, session, tmpl_context as c, url
31 from pylons.controllers.util import abort, redirect
31 from pylons.controllers.util import abort, redirect
32
32
33 from rhodecode.lib import helpers as h
33 from rhodecode.lib import helpers as h
34 from rhodecode.lib.base import BaseRepoController, render
34 from rhodecode.lib.base import BaseRepoController, render
35 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
35 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
36 from rhodecode.lib import diffs
36 from rhodecode.lib import diffs
37
37
38 from rhodecode.model.db import Repository
38 from rhodecode.model.db import Repository
39 from rhodecode.model.pull_request import PullRequestModel
39 from rhodecode.model.pull_request import PullRequestModel
40
40
41 log = logging.getLogger(__name__)
41 log = logging.getLogger(__name__)
42
42
43
43
44 class CompareController(BaseRepoController):
44 class CompareController(BaseRepoController):
45
45
46 @LoginRequired()
46 @LoginRequired()
47 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
47 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
48 'repository.admin')
48 'repository.admin')
49 def __before__(self):
49 def __before__(self):
50 super(CompareController, self).__before__()
50 super(CompareController, self).__before__()
51
51
52 def index(self, org_ref_type, org_ref, other_ref_type, other_ref):
52 def index(self, org_ref_type, org_ref, other_ref_type, other_ref):
53
53
54 org_repo = c.rhodecode_db_repo.repo_name
54 org_repo = c.rhodecode_db_repo.repo_name
55 org_ref = (org_ref_type, org_ref)
55 org_ref = (org_ref_type, org_ref)
56 other_ref = (other_ref_type, other_ref)
56 other_ref = (other_ref_type, other_ref)
57 other_repo = request.GET.get('repo', org_repo)
57 other_repo = request.GET.get('repo', org_repo)
58
58
59 c.swap_url = h.url('compare_url', repo_name=other_repo,
59 c.swap_url = h.url('compare_url', repo_name=other_repo,
60 org_ref_type=other_ref[0], org_ref=other_ref[1],
60 org_ref_type=other_ref[0], org_ref=other_ref[1],
61 other_ref_type=org_ref[0], other_ref=org_ref[1],
61 other_ref_type=org_ref[0], other_ref=org_ref[1],
62 repo=org_repo)
62 repo=org_repo)
63
63
64 c.org_repo = org_repo = Repository.get_by_repo_name(org_repo)
64 c.org_repo = org_repo = Repository.get_by_repo_name(org_repo)
65 c.other_repo = other_repo = Repository.get_by_repo_name(other_repo)
65 c.other_repo = other_repo = Repository.get_by_repo_name(other_repo)
66
66
67 if c.org_repo is None or c.other_repo is None:
67 if c.org_repo is None or c.other_repo is None:
68 log.error('Could not found repo %s or %s' % (org_repo, other_repo))
68 log.error('Could not found repo %s or %s' % (org_repo, other_repo))
69 raise HTTPNotFound
69 raise HTTPNotFound
70
70
71 if c.org_repo.scm_instance.alias != 'hg':
71 if c.org_repo.scm_instance.alias != 'hg':
72 log.error('Review not available for GIT REPOS')
72 log.error('Review not available for GIT REPOS')
73 raise HTTPNotFound
73 raise HTTPNotFound
74
74
75 c.cs_ranges, discovery_data = PullRequestModel().get_compare_data(
75 c.cs_ranges, discovery_data = PullRequestModel().get_compare_data(
76 org_repo, org_ref, other_repo, other_ref
76 org_repo, org_ref, other_repo, other_ref
77 )
77 )
78
78
79 c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in
79 c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in
80 c.cs_ranges])
80 c.cs_ranges])
81 c.target_repo = c.repo_name
81 # defines that we need hidden inputs with changesets
82 # defines that we need hidden inputs with changesets
82 c.as_form = request.GET.get('as_form', False)
83 c.as_form = request.GET.get('as_form', False)
83 if request.environ.get('HTTP_X_PARTIAL_XHR'):
84 if request.environ.get('HTTP_X_PARTIAL_XHR'):
84 return render('compare/compare_cs.html')
85 return render('compare/compare_cs.html')
85
86
86 c.org_ref = org_ref[1]
87 c.org_ref = org_ref[1]
87 c.other_ref = other_ref[1]
88 c.other_ref = other_ref[1]
88 # diff needs to have swapped org with other to generate proper diff
89 # diff needs to have swapped org with other to generate proper diff
89 _diff = diffs.differ(other_repo, other_ref, org_repo, org_ref,
90 _diff = diffs.differ(other_repo, other_ref, org_repo, org_ref,
90 discovery_data)
91 discovery_data)
91 diff_processor = diffs.DiffProcessor(_diff, format='gitdiff')
92 diff_processor = diffs.DiffProcessor(_diff, format='gitdiff')
92 _parsed = diff_processor.prepare()
93 _parsed = diff_processor.prepare()
93
94
94 c.files = []
95 c.files = []
95 c.changes = {}
96 c.changes = {}
96
97
97 for f in _parsed:
98 for f in _parsed:
98 fid = h.FID('', f['filename'])
99 fid = h.FID('', f['filename'])
99 c.files.append([fid, f['operation'], f['filename'], f['stats']])
100 c.files.append([fid, f['operation'], f['filename'], f['stats']])
100 diff = diff_processor.as_html(enable_comments=False, diff_lines=[f])
101 diff = diff_processor.as_html(enable_comments=False, diff_lines=[f])
101 c.changes[fid] = [f['operation'], f['filename'], diff]
102 c.changes[fid] = [f['operation'], f['filename'], diff]
102
103
103 return render('compare/compare_diff.html')
104 return render('compare/compare_diff.html')
@@ -1,297 +1,297 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.controllers.pullrequests
3 rhodecode.controllers.pullrequests
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5
6 pull requests controller for rhodecode for initializing pull requests
6 pull requests controller for rhodecode for initializing pull requests
7
7
8 :created_on: May 7, 2012
8 :created_on: May 7, 2012
9 :author: marcink
9 :author: marcink
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
11 :license: GPLv3, see COPYING for more details.
12 """
12 """
13 # This program is free software: you can redistribute it and/or modify
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
16 # (at your option) any later version.
17 #
17 #
18 # This program is distributed in the hope that it will be useful,
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
21 # GNU General Public License for more details.
22 #
22 #
23 # You should have received a copy of the GNU General Public License
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 import logging
25 import logging
26 import traceback
26 import traceback
27
27
28 from webob.exc import HTTPNotFound
28 from webob.exc import HTTPNotFound
29 from collections import defaultdict
29 from collections import defaultdict
30 from itertools import groupby
30 from itertools import groupby
31
31
32 from pylons import request, response, session, tmpl_context as c, url
32 from pylons import request, response, session, tmpl_context as c, url
33 from pylons.controllers.util import abort, redirect
33 from pylons.controllers.util import abort, redirect
34 from pylons.i18n.translation import _
34 from pylons.i18n.translation import _
35 from pylons.decorators import jsonify
35 from pylons.decorators import jsonify
36
36
37 from rhodecode.lib.base import BaseRepoController, render
37 from rhodecode.lib.base import BaseRepoController, render
38 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
38 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
39 from rhodecode.lib import helpers as h
39 from rhodecode.lib import helpers as h
40 from rhodecode.lib import diffs
40 from rhodecode.lib import diffs
41 from rhodecode.lib.utils import action_logger
41 from rhodecode.lib.utils import action_logger
42 from rhodecode.model.db import User, PullRequest, ChangesetStatus
42 from rhodecode.model.db import User, PullRequest, ChangesetStatus
43 from rhodecode.model.pull_request import PullRequestModel
43 from rhodecode.model.pull_request import PullRequestModel
44 from rhodecode.model.meta import Session
44 from rhodecode.model.meta import Session
45 from rhodecode.model.repo import RepoModel
45 from rhodecode.model.repo import RepoModel
46 from rhodecode.model.comment import ChangesetCommentsModel
46 from rhodecode.model.comment import ChangesetCommentsModel
47 from rhodecode.model.changeset_status import ChangesetStatusModel
47 from rhodecode.model.changeset_status import ChangesetStatusModel
48
48
49 log = logging.getLogger(__name__)
49 log = logging.getLogger(__name__)
50
50
51
51
52 class PullrequestsController(BaseRepoController):
52 class PullrequestsController(BaseRepoController):
53
53
54 @LoginRequired()
54 @LoginRequired()
55 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
55 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
56 'repository.admin')
56 'repository.admin')
57 def __before__(self):
57 def __before__(self):
58 super(PullrequestsController, self).__before__()
58 super(PullrequestsController, self).__before__()
59
59
60 def _get_repo_refs(self, repo):
60 def _get_repo_refs(self, repo):
61 hist_l = []
61 hist_l = []
62
62
63 branches_group = ([('branch:%s:%s' % (k, v), k) for
63 branches_group = ([('branch:%s:%s' % (k, v), k) for
64 k, v in repo.branches.iteritems()], _("Branches"))
64 k, v in repo.branches.iteritems()], _("Branches"))
65 bookmarks_group = ([('book:%s:%s' % (k, v), k) for
65 bookmarks_group = ([('book:%s:%s' % (k, v), k) for
66 k, v in repo.bookmarks.iteritems()], _("Bookmarks"))
66 k, v in repo.bookmarks.iteritems()], _("Bookmarks"))
67 tags_group = ([('tag:%s:%s' % (k, v), k) for
67 tags_group = ([('tag:%s:%s' % (k, v), k) for
68 k, v in repo.tags.iteritems()], _("Tags"))
68 k, v in repo.tags.iteritems()], _("Tags"))
69
69
70 hist_l.append(bookmarks_group)
70 hist_l.append(bookmarks_group)
71 hist_l.append(branches_group)
71 hist_l.append(branches_group)
72 hist_l.append(tags_group)
72 hist_l.append(tags_group)
73
73
74 return hist_l
74 return hist_l
75
75
76 def show_all(self, repo_name):
76 def show_all(self, repo_name):
77 c.pull_requests = PullRequestModel().get_all(repo_name)
77 c.pull_requests = PullRequestModel().get_all(repo_name)
78 c.repo_name = repo_name
78 c.repo_name = repo_name
79 return render('/pullrequests/pullrequest_show_all.html')
79 return render('/pullrequests/pullrequest_show_all.html')
80
80
81 def index(self):
81 def index(self):
82 org_repo = c.rhodecode_db_repo
82 org_repo = c.rhodecode_db_repo
83
83
84 if org_repo.scm_instance.alias != 'hg':
84 if org_repo.scm_instance.alias != 'hg':
85 log.error('Review not available for GIT REPOS')
85 log.error('Review not available for GIT REPOS')
86 raise HTTPNotFound
86 raise HTTPNotFound
87
87
88 c.org_refs = self._get_repo_refs(c.rhodecode_repo)
88 c.org_refs = self._get_repo_refs(c.rhodecode_repo)
89 c.org_repos = []
89 c.org_repos = []
90 c.other_repos = []
90 c.other_repos = []
91 c.org_repos.append((org_repo.repo_name, '%s/%s' % (
91 c.org_repos.append((org_repo.repo_name, '%s/%s' % (
92 org_repo.user.username, c.repo_name))
92 org_repo.user.username, c.repo_name))
93 )
93 )
94
94
95 c.other_refs = c.org_refs
95 c.other_refs = c.org_refs
96 c.other_repos.extend(c.org_repos)
96 c.other_repos.extend(c.org_repos)
97 c.default_pull_request = org_repo.repo_name
97 c.default_pull_request = org_repo.repo_name
98 #gather forks and add to this list
98 #gather forks and add to this list
99 for fork in org_repo.forks:
99 for fork in org_repo.forks:
100 c.other_repos.append((fork.repo_name, '%s/%s' % (
100 c.other_repos.append((fork.repo_name, '%s/%s' % (
101 fork.user.username, fork.repo_name))
101 fork.user.username, fork.repo_name))
102 )
102 )
103 #add parents of this fork also
103 #add parents of this fork also
104 if org_repo.parent:
104 if org_repo.parent:
105 c.default_pull_request = org_repo.parent.repo_name
105 c.default_pull_request = org_repo.parent.repo_name
106 c.other_repos.append((org_repo.parent.repo_name, '%s/%s' % (
106 c.other_repos.append((org_repo.parent.repo_name, '%s/%s' % (
107 org_repo.parent.user.username,
107 org_repo.parent.user.username,
108 org_repo.parent.repo_name))
108 org_repo.parent.repo_name))
109 )
109 )
110
110
111 c.review_members = []
111 c.review_members = []
112 c.available_members = []
112 c.available_members = []
113 for u in User.query().filter(User.username != 'default').all():
113 for u in User.query().filter(User.username != 'default').all():
114 uname = u.username
114 uname = u.username
115 if org_repo.user == u:
115 if org_repo.user == u:
116 uname = _('%s (owner)' % u.username)
116 uname = _('%s (owner)' % u.username)
117 # auto add owner to pull-request recipients
117 # auto add owner to pull-request recipients
118 c.review_members.append([u.user_id, uname])
118 c.review_members.append([u.user_id, uname])
119 c.available_members.append([u.user_id, uname])
119 c.available_members.append([u.user_id, uname])
120 return render('/pullrequests/pullrequest.html')
120 return render('/pullrequests/pullrequest.html')
121
121
122 def create(self, repo_name):
122 def create(self, repo_name):
123 req_p = request.POST
123 req_p = request.POST
124 org_repo = req_p['org_repo']
124 org_repo = req_p['org_repo']
125 org_ref = req_p['org_ref']
125 org_ref = req_p['org_ref']
126 other_repo = req_p['other_repo']
126 other_repo = req_p['other_repo']
127 other_ref = req_p['other_ref']
127 other_ref = req_p['other_ref']
128 revisions = req_p.getall('revisions')
128 revisions = req_p.getall('revisions')
129 reviewers = req_p.getall('review_members')
129 reviewers = req_p.getall('review_members')
130 #TODO: wrap this into a FORM !!!
130 #TODO: wrap this into a FORM !!!
131
131
132 title = req_p['pullrequest_title']
132 title = req_p['pullrequest_title']
133 description = req_p['pullrequest_desc']
133 description = req_p['pullrequest_desc']
134
134
135 try:
135 try:
136 model = PullRequestModel()
136 model = PullRequestModel()
137 model.create(self.rhodecode_user.user_id, org_repo,
137 model.create(self.rhodecode_user.user_id, org_repo,
138 org_ref, other_repo, other_ref, revisions,
138 org_ref, other_repo, other_ref, revisions,
139 reviewers, title, description)
139 reviewers, title, description)
140 Session.commit()
140 Session.commit()
141 h.flash(_('Pull request send'), category='success')
141 h.flash(_('Pull request send'), category='success')
142 except Exception:
142 except Exception:
143 raise
143 raise
144 h.flash(_('Error occured during sending pull request'),
144 h.flash(_('Error occured during sending pull request'),
145 category='error')
145 category='error')
146 log.error(traceback.format_exc())
146 log.error(traceback.format_exc())
147
147
148 return redirect(url('changelog_home', repo_name=repo_name))
148 return redirect(url('changelog_home', repo_name=repo_name))
149
149
150 def _load_compare_data(self, pull_request):
150 def _load_compare_data(self, pull_request):
151 """
151 """
152 Load context data needed for generating compare diff
152 Load context data needed for generating compare diff
153
153
154 :param pull_request:
154 :param pull_request:
155 :type pull_request:
155 :type pull_request:
156 """
156 """
157
157
158 org_repo = pull_request.org_repo
158 org_repo = pull_request.org_repo
159 org_ref_type, org_ref_, org_ref = pull_request.org_ref.split(':')
159 org_ref_type, org_ref_, org_ref = pull_request.org_ref.split(':')
160 other_repo = pull_request.other_repo
160 other_repo = pull_request.other_repo
161 other_ref_type, other_ref, other_ref_ = pull_request.other_ref.split(':')
161 other_ref_type, other_ref, other_ref_ = pull_request.other_ref.split(':')
162
162
163 org_ref = (org_ref_type, org_ref)
163 org_ref = (org_ref_type, org_ref)
164 other_ref = (other_ref_type, other_ref)
164 other_ref = (other_ref_type, other_ref)
165
165
166 c.org_repo = org_repo
166 c.org_repo = org_repo
167 c.other_repo = other_repo
167 c.other_repo = other_repo
168
168
169 c.cs_ranges, discovery_data = PullRequestModel().get_compare_data(
169 c.cs_ranges, discovery_data = PullRequestModel().get_compare_data(
170 org_repo, org_ref, other_repo, other_ref
170 org_repo, org_ref, other_repo, other_ref
171 )
171 )
172
172
173 c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in
173 c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in
174 c.cs_ranges])
174 c.cs_ranges])
175 # defines that we need hidden inputs with changesets
175 # defines that we need hidden inputs with changesets
176 c.as_form = request.GET.get('as_form', False)
176 c.as_form = request.GET.get('as_form', False)
177
177
178 c.org_ref = org_ref[1]
178 c.org_ref = org_ref[1]
179 c.other_ref = other_ref[1]
179 c.other_ref = other_ref[1]
180 # diff needs to have swapped org with other to generate proper diff
180 # diff needs to have swapped org with other to generate proper diff
181 _diff = diffs.differ(other_repo, other_ref, org_repo, org_ref,
181 _diff = diffs.differ(other_repo, other_ref, org_repo, org_ref,
182 discovery_data)
182 discovery_data)
183 diff_processor = diffs.DiffProcessor(_diff, format='gitdiff')
183 diff_processor = diffs.DiffProcessor(_diff, format='gitdiff')
184 _parsed = diff_processor.prepare()
184 _parsed = diff_processor.prepare()
185
185
186 c.files = []
186 c.files = []
187 c.changes = {}
187 c.changes = {}
188
188
189 for f in _parsed:
189 for f in _parsed:
190 fid = h.FID('', f['filename'])
190 fid = h.FID('', f['filename'])
191 c.files.append([fid, f['operation'], f['filename'], f['stats']])
191 c.files.append([fid, f['operation'], f['filename'], f['stats']])
192 diff = diff_processor.as_html(enable_comments=False, diff_lines=[f])
192 diff = diff_processor.as_html(enable_comments=False, diff_lines=[f])
193 c.changes[fid] = [f['operation'], f['filename'], diff]
193 c.changes[fid] = [f['operation'], f['filename'], diff]
194
194
195 def show(self, repo_name, pull_request_id):
195 def show(self, repo_name, pull_request_id):
196 repo_model = RepoModel()
196 repo_model = RepoModel()
197 c.users_array = repo_model.get_users_js()
197 c.users_array = repo_model.get_users_js()
198 c.users_groups_array = repo_model.get_users_groups_js()
198 c.users_groups_array = repo_model.get_users_groups_js()
199 c.pull_request = PullRequest.get(pull_request_id)
199 c.pull_request = PullRequest.get(pull_request_id)
200
200
201 # valid ID
201 # valid ID
202 if not c.pull_request:
202 if not c.pull_request:
203 raise HTTPNotFound
203 raise HTTPNotFound
204 cc_model = ChangesetCommentsModel()
204 cc_model = ChangesetCommentsModel()
205 cs_model = ChangesetStatusModel()
205 cs_model = ChangesetStatusModel()
206 _cs_statuses = cs_model.get_statuses(c.pull_request.org_repo,
206 _cs_statuses = cs_model.get_statuses(c.pull_request.org_repo,
207 pull_request=c.pull_request,
207 pull_request=c.pull_request,
208 with_revisions=True)
208 with_revisions=True)
209
209
210 cs_statuses = defaultdict(list)
210 cs_statuses = defaultdict(list)
211 for st in _cs_statuses:
211 for st in _cs_statuses:
212 cs_statuses[st.author.username] += [st]
212 cs_statuses[st.author.username] += [st]
213
213
214 c.pull_request_reviewers = []
214 c.pull_request_reviewers = []
215 for o in c.pull_request.reviewers:
215 for o in c.pull_request.reviewers:
216 st = cs_statuses.get(o.user.username, None)
216 st = cs_statuses.get(o.user.username, None)
217 if st:
217 if st:
218 sorter = lambda k: k.version
218 sorter = lambda k: k.version
219 st = [(x, list(y)[0])
219 st = [(x, list(y)[0])
220 for x, y in (groupby(sorted(st, key=sorter), sorter))]
220 for x, y in (groupby(sorted(st, key=sorter), sorter))]
221 c.pull_request_reviewers.append([o.user, st])
221 c.pull_request_reviewers.append([o.user, st])
222
222
223 # pull_requests repo_name we opened it against
223 # pull_requests repo_name we opened it against
224 # ie. other_repo must match
224 # ie. other_repo must match
225 if repo_name != c.pull_request.other_repo.repo_name:
225 if repo_name != c.pull_request.other_repo.repo_name:
226 raise HTTPNotFound
226 raise HTTPNotFound
227
227
228 # load compare data into template context
228 # load compare data into template context
229 self._load_compare_data(c.pull_request)
229 self._load_compare_data(c.pull_request)
230
230
231 # inline comments
231 # inline comments
232 c.inline_cnt = 0
232 c.inline_cnt = 0
233 c.inline_comments = cc_model.get_inline_comments(
233 c.inline_comments = cc_model.get_inline_comments(
234 c.rhodecode_db_repo.repo_id,
234 c.rhodecode_db_repo.repo_id,
235 pull_request=pull_request_id)
235 pull_request=pull_request_id)
236 # count inline comments
236 # count inline comments
237 for __, lines in c.inline_comments:
237 for __, lines in c.inline_comments:
238 for comments in lines.values():
238 for comments in lines.values():
239 c.inline_cnt += len(comments)
239 c.inline_cnt += len(comments)
240 # comments
240 # comments
241 c.comments = cc_model.get_comments(c.rhodecode_db_repo.repo_id,
241 c.comments = cc_model.get_comments(c.rhodecode_db_repo.repo_id,
242 pull_request=pull_request_id)
242 pull_request=pull_request_id)
243
243
244 # changeset(pull-request) status
244 # changeset(pull-request) status
245 c.current_changeset_status = cs_model.calculate_status(
245 c.current_changeset_status = cs_model.calculate_status(
246 c.pull_request_reviewers
246 c.pull_request_reviewers
247 )
247 )
248 c.changeset_statuses = ChangesetStatus.STATUSES
248 c.changeset_statuses = ChangesetStatus.STATUSES
249
249 c.target_repo = c.pull_request.org_repo.repo_name
250 return render('/pullrequests/pullrequest_show.html')
250 return render('/pullrequests/pullrequest_show.html')
251
251
252 @jsonify
252 @jsonify
253 def comment(self, repo_name, pull_request_id):
253 def comment(self, repo_name, pull_request_id):
254
254
255 status = request.POST.get('changeset_status')
255 status = request.POST.get('changeset_status')
256 change_status = request.POST.get('change_changeset_status')
256 change_status = request.POST.get('change_changeset_status')
257
257
258 comm = ChangesetCommentsModel().create(
258 comm = ChangesetCommentsModel().create(
259 text=request.POST.get('text'),
259 text=request.POST.get('text'),
260 repo_id=c.rhodecode_db_repo.repo_id,
260 repo_id=c.rhodecode_db_repo.repo_id,
261 user_id=c.rhodecode_user.user_id,
261 user_id=c.rhodecode_user.user_id,
262 pull_request=pull_request_id,
262 pull_request=pull_request_id,
263 f_path=request.POST.get('f_path'),
263 f_path=request.POST.get('f_path'),
264 line_no=request.POST.get('line'),
264 line_no=request.POST.get('line'),
265 status_change=(ChangesetStatus.get_status_lbl(status)
265 status_change=(ChangesetStatus.get_status_lbl(status)
266 if status and change_status else None)
266 if status and change_status else None)
267 )
267 )
268
268
269 # get status if set !
269 # get status if set !
270 if status and change_status:
270 if status and change_status:
271 ChangesetStatusModel().set_status(
271 ChangesetStatusModel().set_status(
272 c.rhodecode_db_repo.repo_id,
272 c.rhodecode_db_repo.repo_id,
273 status,
273 status,
274 c.rhodecode_user.user_id,
274 c.rhodecode_user.user_id,
275 comm,
275 comm,
276 pull_request=pull_request_id
276 pull_request=pull_request_id
277 )
277 )
278 action_logger(self.rhodecode_user,
278 action_logger(self.rhodecode_user,
279 'user_commented_pull_request:%s' % pull_request_id,
279 'user_commented_pull_request:%s' % pull_request_id,
280 c.rhodecode_db_repo, self.ip_addr, self.sa)
280 c.rhodecode_db_repo, self.ip_addr, self.sa)
281
281
282 Session.commit()
282 Session.commit()
283
283
284 if not request.environ.get('HTTP_X_PARTIAL_XHR'):
284 if not request.environ.get('HTTP_X_PARTIAL_XHR'):
285 return redirect(h.url('pullrequest_show', repo_name=repo_name,
285 return redirect(h.url('pullrequest_show', repo_name=repo_name,
286 pull_request_id=pull_request_id))
286 pull_request_id=pull_request_id))
287
287
288 data = {
288 data = {
289 'target_id': h.safeid(h.safe_unicode(request.POST.get('f_path'))),
289 'target_id': h.safeid(h.safe_unicode(request.POST.get('f_path'))),
290 }
290 }
291 if comm:
291 if comm:
292 c.co = comm
292 c.co = comm
293 data.update(comm.get_dict())
293 data.update(comm.get_dict())
294 data.update({'rendered_text':
294 data.update({'rendered_text':
295 render('changeset/changeset_comment_block.html')})
295 render('changeset/changeset_comment_block.html')})
296
296
297 return data
297 return data
@@ -1,27 +1,27 b''
1 ## Changesets table !
1 ## Changesets table !
2 <div class="container">
2 <div class="container">
3 <table class="compare_view_commits noborder">
3 <table class="compare_view_commits noborder">
4 %if not c.cs_ranges:
4 %if not c.cs_ranges:
5 <tr><td>${_('No changesets')}</td></tr>
5 <tr><td>${_('No changesets')}</td></tr>
6 %else:
6 %else:
7 %for cnt, cs in enumerate(c.cs_ranges):
7 %for cnt, cs in enumerate(c.cs_ranges):
8 <tr>
8 <tr>
9 <td><div class="gravatar"><img alt="gravatar" src="${h.gravatar_url(h.email(cs.author),14)}"/></div></td>
9 <td><div class="gravatar"><img alt="gravatar" src="${h.gravatar_url(h.email(cs.author),14)}"/></div></td>
10 <td>
10 <td>
11 %if cs.raw_id in c.statuses:
11 %if cs.raw_id in c.statuses:
12 <div title="${c.statuses[cs.raw_id][1]}" class="changeset-status-ico"><img src="${h.url('/images/icons/flag_status_%s.png' % c.statuses[cs.raw_id][0])}" /></div>
12 <div title="${c.statuses[cs.raw_id][1]}" class="changeset-status-ico"><img src="${h.url('/images/icons/flag_status_%s.png' % c.statuses[cs.raw_id][0])}" /></div>
13 %endif
13 %endif
14 </td>
14 </td>
15 <td>${h.link_to('r%s:%s' % (cs.revision,h.short_id(cs.raw_id)),h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id))}
15 <td>${h.link_to('r%s:%s' % (cs.revision,h.short_id(cs.raw_id)),h.url('changeset_home',repo_name=c.target_repo,revision=cs.raw_id))}
16 %if c.as_form:
16 %if c.as_form:
17 ${h.hidden('revisions',cs.raw_id)}
17 ${h.hidden('revisions',cs.raw_id)}
18 %endif
18 %endif
19 </td>
19 </td>
20 <td><div class="author">${h.person(cs.author)}</div></td>
20 <td><div class="author">${h.person(cs.author)}</div></td>
21 <td><span class="tooltip" title="${h.age(cs.date)}">${cs.date}</span></td>
21 <td><span class="tooltip" title="${h.age(cs.date)}">${cs.date}</span></td>
22 <td><div class="message">${h.urlify_commit(h.wrap_paragraphs(cs.message),c.repo_name)}</div></td>
22 <td><div class="message">${h.urlify_commit(h.wrap_paragraphs(cs.message),c.repo_name)}</div></td>
23 </tr>
23 </tr>
24 %endfor
24 %endfor
25 %endif
25 %endif
26 </table>
26 </table>
27 </div>
27 </div>
General Comments 0
You need to be logged in to leave comments. Login now