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