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