##// END OF EJS Templates
Added dynamic data loading for other repo we open pull request against...
marcink -
r2541:1c2ba03c beta
parent child Browse files
Show More
@@ -377,8 +377,8 b' class ChangesetController(BaseRepoContro'
377 377
378 378 comm = ChangesetCommentsModel().create(
379 379 text=request.POST.get('text'),
380 repo_id=c.rhodecode_db_repo.repo_id,
381 user_id=c.rhodecode_user.user_id,
380 repo=c.rhodecode_db_repo.repo_id,
381 user=c.rhodecode_user.user_id,
382 382 revision=revision,
383 383 f_path=request.POST.get('f_path'),
384 384 line_no=request.POST.get('line'),
@@ -34,6 +34,7 b' from pylons.controllers.util import abor'
34 34 from pylons.i18n.translation import _
35 35 from pylons.decorators import jsonify
36 36
37 from rhodecode.lib.compat import json
37 38 from rhodecode.lib.base import BaseRepoController, render
38 39 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
39 40 from rhodecode.lib import helpers as h
@@ -86,6 +87,8 b' class PullrequestsController(BaseRepoCon'
86 87 log.error('Review not available for GIT REPOS')
87 88 raise HTTPNotFound
88 89
90 other_repos_info = {}
91
89 92 c.org_refs = self._get_repo_refs(c.rhodecode_repo)
90 93 c.org_repos = []
91 94 c.other_repos = []
@@ -95,12 +98,23 b' class PullrequestsController(BaseRepoCon'
95 98
96 99 c.other_refs = c.org_refs
97 100 c.other_repos.extend(c.org_repos)
101
102 #add orginal repo
103 other_repos_info[org_repo.repo_name] = {
104 'gravatar': h.gravatar_url(org_repo.user.email, 24),
105 'description': org_repo.description
106 }
107
98 108 c.default_pull_request = org_repo.repo_name
99 109 #gather forks and add to this list
100 110 for fork in org_repo.forks:
101 111 c.other_repos.append((fork.repo_name, '%s/%s' % (
102 112 fork.user.username, fork.repo_name))
103 113 )
114 other_repos_info[fork.repo_name] = {
115 'gravatar': h.gravatar_url(fork.user.email, 24),
116 'description': fork.description
117 }
104 118 #add parents of this fork also
105 119 if org_repo.parent:
106 120 c.default_pull_request = org_repo.parent.repo_name
@@ -108,7 +122,12 b' class PullrequestsController(BaseRepoCon'
108 122 org_repo.parent.user.username,
109 123 org_repo.parent.repo_name))
110 124 )
125 other_repos_info[org_repo.parent.repo_name] = {
126 'gravatar': h.gravatar_url(org_repo.parent.user.email, 24),
127 'description': org_repo.parent.description
128 }
111 129
130 c.other_repos_info = json.dumps(other_repos_info)
112 131 c.review_members = []
113 132 c.available_members = []
114 133 for u in User.query().filter(User.username != 'default').all():
@@ -134,17 +153,18 b' class PullrequestsController(BaseRepoCon'
134 153 description = req_p['pullrequest_desc']
135 154
136 155 try:
137 model = PullRequestModel()
138 pull_request = model.create(self.rhodecode_user.user_id, org_repo,
139 org_ref, other_repo, other_ref, revisions,
140 reviewers, title, description)
141 Session.commit()
156 pull_request = PullRequestModel().create(
157 self.rhodecode_user.user_id, org_repo, org_ref, other_repo,
158 other_ref, revisions, reviewers, title, description
159 )
160 Session().commit()
142 161 h.flash(_('Successfully opened new pull request'),
143 162 category='success')
144 163 except Exception:
145 164 h.flash(_('Error occurred during sending pull request'),
146 165 category='error')
147 166 log.error(traceback.format_exc())
167 return redirect(url('changelog_home', repo_name=org_repo,))
148 168
149 169 return redirect(url('pullrequest_show', repo_name=other_repo,
150 170 pull_request_id=pull_request.pull_request_id))
@@ -257,8 +277,8 b' class PullrequestsController(BaseRepoCon'
257 277
258 278 comm = ChangesetCommentsModel().create(
259 279 text=request.POST.get('text'),
260 repo_id=c.rhodecode_db_repo.repo_id,
261 user_id=c.rhodecode_user.user_id,
280 repo=c.rhodecode_db_repo.repo_id,
281 user=c.rhodecode_user.user_id,
262 282 pull_request=pull_request_id,
263 283 f_path=request.POST.get('f_path'),
264 284 line_no=request.POST.get('line'),
@@ -279,7 +299,7 b' class PullrequestsController(BaseRepoCon'
279 299 'user_commented_pull_request:%s' % pull_request_id,
280 300 c.rhodecode_db_repo, self.ip_addr, self.sa)
281 301
282 Session.commit()
302 Session().commit()
283 303
284 304 if not request.environ.get('HTTP_X_PARTIAL_XHR'):
285 305 return redirect(h.url('pullrequest_show', repo_name=repo_name,
@@ -302,7 +322,7 b' class PullrequestsController(BaseRepoCon'
302 322 owner = lambda: co.author.user_id == c.rhodecode_user.user_id
303 323 if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner:
304 324 ChangesetCommentsModel().delete(comment=co)
305 Session.commit()
325 Session().commit()
306 326 return True
307 327 else:
308 328 raise HTTPForbidden() No newline at end of file
@@ -57,7 +57,7 b' class ChangesetCommentsModel(BaseModel):'
57 57 user_objects.append(user_obj)
58 58 return user_objects
59 59
60 def create(self, text, repo_id, user_id, revision=None, pull_request=None,
60 def create(self, text, repo, user, revision=None, pull_request=None,
61 61 f_path=None, line_no=None, status_change=None):
62 62 """
63 63 Creates new comment for changeset or pull request.
@@ -65,8 +65,8 b' class ChangesetCommentsModel(BaseModel):'
65 65 status change of changeset or changesets associated with pull request
66 66
67 67 :param text:
68 :param repo_id:
69 :param user_id:
68 :param repo:
69 :param user:
70 70 :param revision:
71 71 :param pull_request:
72 72 :param f_path:
@@ -76,10 +76,11 b' class ChangesetCommentsModel(BaseModel):'
76 76 if not text:
77 77 return
78 78
79 repo = Repository.get(repo_id)
79 repo = self._get_repo(repo)
80 user = self._get_user(user)
80 81 comment = ChangesetComment()
81 82 comment.repo = repo
82 comment.user_id = user_id
83 comment.author = user
83 84 comment.text = text
84 85 comment.f_path = f_path
85 86 comment.line_no = line_no
@@ -92,7 +93,7 b' class ChangesetCommentsModel(BaseModel):'
92 93 elif pull_request:
93 94 pull_request = self.__get_pull_request(pull_request)
94 95 comment.pull_request = pull_request
95 desc = ''
96 desc = pull_request.pull_request_id
96 97 else:
97 98 raise Exception('Please specify revision or pull_request_id')
98 99
@@ -108,8 +109,8 b' class ChangesetCommentsModel(BaseModel):'
108 109 if line_no:
109 110 line = _('on line %s') % line_no
110 111 subj = safe_unicode(
111 h.link_to('Re commit: %(commit_desc)s %(line)s' % \
112 {'commit_desc': desc, 'line': line},
112 h.link_to('Re commit: %(desc)s %(line)s' % \
113 {'desc': desc, 'line': line},
113 114 h.url('changeset_home', repo_name=repo.repo_name,
114 115 revision=revision,
115 116 anchor='comment-%s' % comment.comment_id,
@@ -124,8 +125,18 b' class ChangesetCommentsModel(BaseModel):'
124 125 recipients += [User.get_by_email(author_email)]
125 126 #pull request
126 127 elif pull_request:
127 #TODO: make this something usefull
128 subj = 'commented on pull request something...'
128 subj = safe_unicode(
129 h.link_to('Re pull request: %(desc)s %(line)s' % \
130 {'desc': desc, 'line': line},
131 h.url('pullrequest_show',
132 repo_name=pull_request.other_repo.repo_name,
133 pull_request_id=pull_request.pull_request_id,
134 anchor='comment-%s' % comment.comment_id,
135 qualified=True,
136 )
137 )
138 )
139
129 140 notification_type = Notification.TYPE_PULL_REQUEST_COMMENT
130 141 # get the current participants of this pull request
131 142 recipients = ChangesetComment.get_users(pull_request_id=
@@ -135,7 +146,7 b' class ChangesetCommentsModel(BaseModel):'
135 146
136 147 # create notification objects, and emails
137 148 NotificationModel().create(
138 created_by=user_id, subject=subj, body=body,
149 created_by=user, subject=subj, body=body,
139 150 recipients=recipients, type_=notification_type,
140 151 email_kwargs={'status_change': status_change}
141 152 )
@@ -145,7 +156,7 b' class ChangesetCommentsModel(BaseModel):'
145 156 if mention_recipients:
146 157 subj = _('[Mention]') + ' ' + subj
147 158 NotificationModel().create(
148 created_by=user_id, subject=subj, body=body,
159 created_by=user, subject=subj, body=body,
149 160 recipients=mention_recipients,
150 161 type_=notification_type,
151 162 email_kwargs={'status_change': status_change}
@@ -29,11 +29,15 b' from pylons.i18n.translation import _'
29 29
30 30 from rhodecode.lib import helpers as h
31 31 from rhodecode.model import BaseModel
32 from rhodecode.model.db import PullRequest, PullRequestReviewers, Notification
32 from rhodecode.model.db import PullRequest, PullRequestReviewers, Notification,\
33 ChangesetStatus
33 34 from rhodecode.model.notification import NotificationModel
34 35 from rhodecode.lib.utils2 import safe_unicode
35 36
36 37 from rhodecode.lib.vcs.utils.hgcompat import discovery
38 from rhodecode.model.changeset_status import ChangesetStatusModel
39 from rhodecode.model.comment import ChangesetCommentsModel
40 from rhodecode.model.meta import Session
37 41
38 42 log = logging.getLogger(__name__)
39 43
@@ -48,19 +52,22 b' class PullRequestModel(BaseModel):'
48 52
49 53 def create(self, created_by, org_repo, org_ref, other_repo,
50 54 other_ref, revisions, reviewers, title, description=None):
55
51 56 created_by_user = self._get_user(created_by)
57 org_repo = self._get_repo(org_repo)
58 other_repo = self._get_repo(other_repo)
52 59
53 60 new = PullRequest()
54 new.org_repo = self._get_repo(org_repo)
61 new.org_repo = org_repo
55 62 new.org_ref = org_ref
56 new.other_repo = self._get_repo(other_repo)
63 new.other_repo = other_repo
57 64 new.other_ref = other_ref
58 65 new.revisions = revisions
59 66 new.title = title
60 67 new.description = description
61 68 new.author = created_by_user
62 69 self.sa.add(new)
63
70 Session().flush()
64 71 #members
65 72 for member in reviewers:
66 73 _usr = self._get_user(member)
@@ -82,7 +89,7 b' class PullRequestModel(BaseModel):'
82 89 )
83 90 )
84 91 body = description
85 notif.create(created_by=created_by, subject=subject, body=body,
92 notif.create(created_by=created_by_user, subject=subject, body=body,
86 93 recipients=reviewers,
87 94 type_=Notification.TYPE_PULL_REQUEST,)
88 95
@@ -50,12 +50,12 b''
50 50 <div style="float:left">
51 51 <div class="fork_user">
52 52 <div class="gravatar">
53 <img alt="gravatar" src="${h.gravatar_url(c.rhodecode_db_repo.user.email,24)}"/>
53 <img id="other_repo_gravatar" alt="gravatar" src=""/>
54 54 </div>
55 55 <span style="font-size: 20px">
56 56 ${h.select('other_repo',c.default_pull_request ,c.other_repos,class_='refs')}:${h.select('other_ref','',c.other_refs,class_='refs')}
57 57 </span>
58 <div style="padding:5px 3px 3px 42px;">${c.rhodecode_db_repo.description}</div>
58 <div id="other_repo_desc" style="padding:5px 3px 3px 42px;"></div>
59 59 </div>
60 60 <div style="clear:both;padding-top: 10px"></div>
61 61 </div>
@@ -142,7 +142,7 b''
142 142
143 143 <script type="text/javascript">
144 144 MultiSelectWidget('review_members','available_members','pull_request_form');
145
145 var other_repos_info = ${c.other_repos_info|n};
146 146 var loadPreview = function(){
147 147 YUD.setStyle(YUD.get('pull_request_overview_url').parentElement,'display','none');
148 148 var url = "${h.url('compare_url',
@@ -176,8 +176,12 b''
176 176 }
177 177
178 178 ypjax(url,'pull_request_overview', function(data){
179 var sel_box = YUQ('#pull_request_form #other_repo')[0];
180 var repo_name = sel_box.options[sel_box.selectedIndex].value;
179 181 YUD.get('pull_request_overview_url').href = url;
180 182 YUD.setStyle(YUD.get('pull_request_overview_url').parentElement,'display','');
183 YUD.get('other_repo_gravatar').src = other_repos_info[repo_name]['gravatar'];
184 YUD.get('other_repo_desc').innerHTML = other_repos_info[repo_name]['description'];
181 185 })
182 186 }
183 187 YUE.on('refresh','click',function(e){
General Comments 0
You need to be logged in to leave comments. Login now