##// END OF EJS Templates
data checks
marcink -
r2444:b45e9fd7 codereview
parent child Browse files
Show More
@@ -1,99 +1,103 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':
72 log.error('Review not available for GIT REPOS')
73 raise HTTPNotFound
74
71 c.cs_ranges, discovery_data = PullRequestModel().get_compare_data(
75 c.cs_ranges, discovery_data = PullRequestModel().get_compare_data(
72 org_repo, org_ref, other_repo, other_ref
76 org_repo, org_ref, other_repo, other_ref
73 )
77 )
74
78
75 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
76 c.cs_ranges])
80 c.cs_ranges])
77 # defines that we need hidden inputs with changesets
81 # defines that we need hidden inputs with changesets
78 c.as_form = request.GET.get('as_form', False)
82 c.as_form = request.GET.get('as_form', False)
79 if request.environ.get('HTTP_X_PARTIAL_XHR'):
83 if request.environ.get('HTTP_X_PARTIAL_XHR'):
80 return render('compare/compare_cs.html')
84 return render('compare/compare_cs.html')
81
85
82 c.org_ref = org_ref[1]
86 c.org_ref = org_ref[1]
83 c.other_ref = other_ref[1]
87 c.other_ref = other_ref[1]
84 # diff needs to have swapped org with other to generate proper diff
88 # diff needs to have swapped org with other to generate proper diff
85 _diff = diffs.differ(other_repo, other_ref, org_repo, org_ref,
89 _diff = diffs.differ(other_repo, other_ref, org_repo, org_ref,
86 discovery_data)
90 discovery_data)
87 diff_processor = diffs.DiffProcessor(_diff, format='gitdiff')
91 diff_processor = diffs.DiffProcessor(_diff, format='gitdiff')
88 _parsed = diff_processor.prepare()
92 _parsed = diff_processor.prepare()
89
93
90 c.files = []
94 c.files = []
91 c.changes = {}
95 c.changes = {}
92
96
93 for f in _parsed:
97 for f in _parsed:
94 fid = h.FID('', f['filename'])
98 fid = h.FID('', f['filename'])
95 c.files.append([fid, f['operation'], f['filename'], f['stats']])
99 c.files.append([fid, f['operation'], f['filename'], f['stats']])
96 diff = diff_processor.as_html(enable_comments=False, diff_lines=[f])
100 diff = diff_processor.as_html(enable_comments=False, diff_lines=[f])
97 c.changes[fid] = [f['operation'], f['filename'], diff]
101 c.changes[fid] = [f['operation'], f['filename'], diff]
98
102
99 return render('compare/compare_diff.html')
103 return render('compare/compare_diff.html')
@@ -1,264 +1,277 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
29
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 from pylons.i18n.translation import _
32 from pylons.i18n.translation import _
33 from pylons.decorators import jsonify
33 from pylons.decorators import jsonify
34
34
35 from rhodecode.lib.base import BaseRepoController, render
35 from rhodecode.lib.base import BaseRepoController, render
36 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
36 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
37 from rhodecode.lib import helpers as h
37 from rhodecode.lib import helpers as h
38 from rhodecode.lib import diffs
38 from rhodecode.lib import diffs
39 from rhodecode.lib.utils import action_logger
39 from rhodecode.lib.utils import action_logger
40 from rhodecode.model.db import User, PullRequest, ChangesetStatus
40 from rhodecode.model.db import User, PullRequest, ChangesetStatus
41 from rhodecode.model.pull_request import PullRequestModel
41 from rhodecode.model.pull_request import PullRequestModel
42 from rhodecode.model.meta import Session
42 from rhodecode.model.meta import Session
43 from rhodecode.model.repo import RepoModel
43 from rhodecode.model.repo import RepoModel
44 from rhodecode.model.comment import ChangesetCommentsModel
44 from rhodecode.model.comment import ChangesetCommentsModel
45 from rhodecode.model.changeset_status import ChangesetStatusModel
45 from rhodecode.model.changeset_status import ChangesetStatusModel
46
46
47 log = logging.getLogger(__name__)
47 log = logging.getLogger(__name__)
48
48
49
49
50 class PullrequestsController(BaseRepoController):
50 class PullrequestsController(BaseRepoController):
51
51
52 @LoginRequired()
52 @LoginRequired()
53 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
53 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
54 'repository.admin')
54 'repository.admin')
55 def __before__(self):
55 def __before__(self):
56 super(PullrequestsController, self).__before__()
56 super(PullrequestsController, self).__before__()
57
57
58 def _get_repo_refs(self, repo):
58 def _get_repo_refs(self, repo):
59 hist_l = []
59 hist_l = []
60
60
61 branches_group = ([('branch:%s:%s' % (k, v), k) for
61 branches_group = ([('branch:%s:%s' % (k, v), k) for
62 k, v in repo.branches.iteritems()], _("Branches"))
62 k, v in repo.branches.iteritems()], _("Branches"))
63 bookmarks_group = ([('book:%s:%s' % (k, v), k) for
63 bookmarks_group = ([('book:%s:%s' % (k, v), k) for
64 k, v in repo.bookmarks.iteritems()], _("Bookmarks"))
64 k, v in repo.bookmarks.iteritems()], _("Bookmarks"))
65 tags_group = ([('tag:%s:%s' % (k, v), k) for
65 tags_group = ([('tag:%s:%s' % (k, v), k) for
66 k, v in repo.tags.iteritems()], _("Tags"))
66 k, v in repo.tags.iteritems()], _("Tags"))
67
67
68 hist_l.append(bookmarks_group)
68 hist_l.append(bookmarks_group)
69 hist_l.append(branches_group)
69 hist_l.append(branches_group)
70 hist_l.append(tags_group)
70 hist_l.append(tags_group)
71
71
72 return hist_l
72 return hist_l
73
73
74 def show_all(self, repo_name):
74 def show_all(self, repo_name):
75 c.pull_requests = PullRequestModel().get_all(repo_name)
75 c.pull_requests = PullRequestModel().get_all(repo_name)
76 c.repo_name = repo_name
76 c.repo_name = repo_name
77 return render('/pullrequests/pullrequest_show_all.html')
77 return render('/pullrequests/pullrequest_show_all.html')
78
78
79 def index(self):
79 def index(self):
80 org_repo = c.rhodecode_db_repo
80 org_repo = c.rhodecode_db_repo
81
82 if org_repo.scm_instance.alias != 'hg':
83 log.error('Review not available for GIT REPOS')
84 raise HTTPNotFound
85
81 c.org_refs = self._get_repo_refs(c.rhodecode_repo)
86 c.org_refs = self._get_repo_refs(c.rhodecode_repo)
82 c.org_repos = []
87 c.org_repos = []
83 c.other_repos = []
88 c.other_repos = []
84 c.org_repos.append((org_repo.repo_name, '%s/%s' % (
89 c.org_repos.append((org_repo.repo_name, '%s/%s' % (
85 org_repo.user.username, c.repo_name))
90 org_repo.user.username, c.repo_name))
86 )
91 )
87
92
88 c.other_refs = c.org_refs
93 c.other_refs = c.org_refs
89 c.other_repos.extend(c.org_repos)
94 c.other_repos.extend(c.org_repos)
90 c.default_pull_request = org_repo.repo_name
95 c.default_pull_request = org_repo.repo_name
91 #gather forks and add to this list
96 #gather forks and add to this list
92 for fork in org_repo.forks:
97 for fork in org_repo.forks:
93 c.other_repos.append((fork.repo_name, '%s/%s' % (
98 c.other_repos.append((fork.repo_name, '%s/%s' % (
94 fork.user.username, fork.repo_name))
99 fork.user.username, fork.repo_name))
95 )
100 )
96 #add parents of this fork also
101 #add parents of this fork also
97 if org_repo.parent:
102 if org_repo.parent:
98 c.default_pull_request = org_repo.parent.repo_name
103 c.default_pull_request = org_repo.parent.repo_name
99 c.other_repos.append((org_repo.parent.repo_name, '%s/%s' % (
104 c.other_repos.append((org_repo.parent.repo_name, '%s/%s' % (
100 org_repo.parent.user.username,
105 org_repo.parent.user.username,
101 org_repo.parent.repo_name))
106 org_repo.parent.repo_name))
102 )
107 )
103
108
104 #TODO: maybe the owner should be default ?
105 c.review_members = []
109 c.review_members = []
106 c.available_members = []
110 c.available_members = []
107 for u in User.query().filter(User.username != 'default').all():
111 for u in User.query().filter(User.username != 'default').all():
108 uname = u.username
112 uname = u.username
109 if org_repo.user == u:
113 if org_repo.user == u:
110 uname = _('%s (owner)' % u.username)
114 uname = _('%s (owner)' % u.username)
111 # auto add owner to pull-request recipients
115 # auto add owner to pull-request recipients
112 c.review_members.append([u.user_id, uname])
116 c.review_members.append([u.user_id, uname])
113 c.available_members.append([u.user_id, uname])
117 c.available_members.append([u.user_id, uname])
114 return render('/pullrequests/pullrequest.html')
118 return render('/pullrequests/pullrequest.html')
115
119
116 def create(self, repo_name):
120 def create(self, repo_name):
117 req_p = request.POST
121 req_p = request.POST
118 org_repo = req_p['org_repo']
122 org_repo = req_p['org_repo']
119 org_ref = req_p['org_ref']
123 org_ref = req_p['org_ref']
120 other_repo = req_p['other_repo']
124 other_repo = req_p['other_repo']
121 other_ref = req_p['other_ref']
125 other_ref = req_p['other_ref']
122 revisions = req_p.getall('revisions')
126 revisions = req_p.getall('revisions')
123 reviewers = req_p.getall('review_members')
127 reviewers = req_p.getall('review_members')
124 #TODO: wrap this into a FORM !!!
128 #TODO: wrap this into a FORM !!!
125
129
126 title = req_p['pullrequest_title']
130 title = req_p['pullrequest_title']
127 description = req_p['pullrequest_desc']
131 description = req_p['pullrequest_desc']
128
132
129 try:
133 try:
130 model = PullRequestModel()
134 model = PullRequestModel()
131 model.create(self.rhodecode_user.user_id, org_repo,
135 model.create(self.rhodecode_user.user_id, org_repo,
132 org_ref, other_repo, other_ref, revisions,
136 org_ref, other_repo, other_ref, revisions,
133 reviewers, title, description)
137 reviewers, title, description)
134 Session.commit()
138 Session.commit()
135 h.flash(_('Pull request send'), category='success')
139 h.flash(_('Pull request send'), category='success')
136 except Exception:
140 except Exception:
137 raise
141 raise
138 h.flash(_('Error occured during sending pull request'),
142 h.flash(_('Error occured during sending pull request'),
139 category='error')
143 category='error')
140 log.error(traceback.format_exc())
144 log.error(traceback.format_exc())
141
145
142 return redirect(url('changelog_home', repo_name=repo_name))
146 return redirect(url('changelog_home', repo_name=repo_name))
143
147
144 def _load_compare_data(self, pull_request):
148 def _load_compare_data(self, pull_request):
145 """
149 """
146 Load context data needed for generating compare diff
150 Load context data needed for generating compare diff
147
151
148 :param pull_request:
152 :param pull_request:
149 :type pull_request:
153 :type pull_request:
150 """
154 """
151
155
152 org_repo = pull_request.org_repo
156 org_repo = pull_request.org_repo
153 org_ref_type, org_ref_, org_ref = pull_request.org_ref.split(':')
157 org_ref_type, org_ref_, org_ref = pull_request.org_ref.split(':')
154 other_repo = pull_request.other_repo
158 other_repo = pull_request.other_repo
155 other_ref_type, other_ref, other_ref_ = pull_request.other_ref.split(':')
159 other_ref_type, other_ref, other_ref_ = pull_request.other_ref.split(':')
156
160
157 org_ref = (org_ref_type, org_ref)
161 org_ref = (org_ref_type, org_ref)
158 other_ref = (other_ref_type, other_ref)
162 other_ref = (other_ref_type, other_ref)
159
163
160 c.org_repo = org_repo
164 c.org_repo = org_repo
161 c.other_repo = other_repo
165 c.other_repo = other_repo
162
166
163 c.cs_ranges, discovery_data = PullRequestModel().get_compare_data(
167 c.cs_ranges, discovery_data = PullRequestModel().get_compare_data(
164 org_repo, org_ref, other_repo, other_ref
168 org_repo, org_ref, other_repo, other_ref
165 )
169 )
166
170
167 c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in
171 c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in
168 c.cs_ranges])
172 c.cs_ranges])
169 # defines that we need hidden inputs with changesets
173 # defines that we need hidden inputs with changesets
170 c.as_form = request.GET.get('as_form', False)
174 c.as_form = request.GET.get('as_form', False)
171
175
172 c.org_ref = org_ref[1]
176 c.org_ref = org_ref[1]
173 c.other_ref = other_ref[1]
177 c.other_ref = other_ref[1]
174 # diff needs to have swapped org with other to generate proper diff
178 # diff needs to have swapped org with other to generate proper diff
175 _diff = diffs.differ(other_repo, other_ref, org_repo, org_ref,
179 _diff = diffs.differ(other_repo, other_ref, org_repo, org_ref,
176 discovery_data)
180 discovery_data)
177 diff_processor = diffs.DiffProcessor(_diff, format='gitdiff')
181 diff_processor = diffs.DiffProcessor(_diff, format='gitdiff')
178 _parsed = diff_processor.prepare()
182 _parsed = diff_processor.prepare()
179
183
180 c.files = []
184 c.files = []
181 c.changes = {}
185 c.changes = {}
182
186
183 for f in _parsed:
187 for f in _parsed:
184 fid = h.FID('', f['filename'])
188 fid = h.FID('', f['filename'])
185 c.files.append([fid, f['operation'], f['filename'], f['stats']])
189 c.files.append([fid, f['operation'], f['filename'], f['stats']])
186 diff = diff_processor.as_html(enable_comments=False, diff_lines=[f])
190 diff = diff_processor.as_html(enable_comments=False, diff_lines=[f])
187 c.changes[fid] = [f['operation'], f['filename'], diff]
191 c.changes[fid] = [f['operation'], f['filename'], diff]
188
192
189 def show(self, repo_name, pull_request_id):
193 def show(self, repo_name, pull_request_id):
190 repo_model = RepoModel()
194 repo_model = RepoModel()
191 c.users_array = repo_model.get_users_js()
195 c.users_array = repo_model.get_users_js()
192 c.users_groups_array = repo_model.get_users_groups_js()
196 c.users_groups_array = repo_model.get_users_groups_js()
193 c.pull_request = PullRequest.get(pull_request_id)
197 c.pull_request = PullRequest.get(pull_request_id)
194
198
199 # valid ID
200 if not c.pull_request:
201 raise HTTPNotFound
202
203 # pull_requests repo_name we opened it against
204 # ie. other_repo must match
205 if repo_name != c.pull_request.other_repo.repo_name:
206 raise HTTPNotFound
207
195 # load compare data into template context
208 # load compare data into template context
196 self._load_compare_data(c.pull_request)
209 self._load_compare_data(c.pull_request)
197
210
198 # inline comments
211 # inline comments
199 c.inline_cnt = 0
212 c.inline_cnt = 0
200 c.inline_comments = ChangesetCommentsModel()\
213 c.inline_comments = ChangesetCommentsModel()\
201 .get_inline_comments(c.rhodecode_db_repo.repo_id,
214 .get_inline_comments(c.rhodecode_db_repo.repo_id,
202 pull_request=pull_request_id)
215 pull_request=pull_request_id)
203 # count inline comments
216 # count inline comments
204 for __, lines in c.inline_comments:
217 for __, lines in c.inline_comments:
205 for comments in lines.values():
218 for comments in lines.values():
206 c.inline_cnt += len(comments)
219 c.inline_cnt += len(comments)
207 # comments
220 # comments
208 c.comments = ChangesetCommentsModel()\
221 c.comments = ChangesetCommentsModel()\
209 .get_comments(c.rhodecode_db_repo.repo_id,
222 .get_comments(c.rhodecode_db_repo.repo_id,
210 pull_request=pull_request_id)
223 pull_request=pull_request_id)
211
224
212 # changeset(pull-request) status
225 # changeset(pull-request) status
213 c.current_changeset_status = ChangesetStatusModel()\
226 c.current_changeset_status = ChangesetStatusModel()\
214 .get_status(c.pull_request.org_repo,
227 .get_status(c.pull_request.org_repo,
215 pull_request=c.pull_request)
228 pull_request=c.pull_request)
216 c.changeset_statuses = ChangesetStatus.STATUSES
229 c.changeset_statuses = ChangesetStatus.STATUSES
217 return render('/pullrequests/pullrequest_show.html')
230 return render('/pullrequests/pullrequest_show.html')
218
231
219 @jsonify
232 @jsonify
220 def comment(self, repo_name, pull_request_id):
233 def comment(self, repo_name, pull_request_id):
221
234
222 status = request.POST.get('changeset_status')
235 status = request.POST.get('changeset_status')
223 change_status = request.POST.get('change_changeset_status')
236 change_status = request.POST.get('change_changeset_status')
224
237
225 comm = ChangesetCommentsModel().create(
238 comm = ChangesetCommentsModel().create(
226 text=request.POST.get('text'),
239 text=request.POST.get('text'),
227 repo_id=c.rhodecode_db_repo.repo_id,
240 repo_id=c.rhodecode_db_repo.repo_id,
228 user_id=c.rhodecode_user.user_id,
241 user_id=c.rhodecode_user.user_id,
229 pull_request=pull_request_id,
242 pull_request=pull_request_id,
230 f_path=request.POST.get('f_path'),
243 f_path=request.POST.get('f_path'),
231 line_no=request.POST.get('line'),
244 line_no=request.POST.get('line'),
232 status_change=(ChangesetStatus.get_status_lbl(status)
245 status_change=(ChangesetStatus.get_status_lbl(status)
233 if status and change_status else None)
246 if status and change_status else None)
234 )
247 )
235
248
236 # get status if set !
249 # get status if set !
237 if status and change_status:
250 if status and change_status:
238 ChangesetStatusModel().set_status(
251 ChangesetStatusModel().set_status(
239 c.rhodecode_db_repo.repo_id,
252 c.rhodecode_db_repo.repo_id,
240 status,
253 status,
241 c.rhodecode_user.user_id,
254 c.rhodecode_user.user_id,
242 comm,
255 comm,
243 pull_request=pull_request_id
256 pull_request=pull_request_id
244 )
257 )
245 action_logger(self.rhodecode_user,
258 action_logger(self.rhodecode_user,
246 'user_commented_pull_request:%s' % pull_request_id,
259 'user_commented_pull_request:%s' % pull_request_id,
247 c.rhodecode_db_repo, self.ip_addr, self.sa)
260 c.rhodecode_db_repo, self.ip_addr, self.sa)
248
261
249 Session.commit()
262 Session.commit()
250
263
251 if not request.environ.get('HTTP_X_PARTIAL_XHR'):
264 if not request.environ.get('HTTP_X_PARTIAL_XHR'):
252 return redirect(h.url('pullrequest_show', repo_name=repo_name,
265 return redirect(h.url('pullrequest_show', repo_name=repo_name,
253 pull_request_id=pull_request_id))
266 pull_request_id=pull_request_id))
254
267
255 data = {
268 data = {
256 'target_id': h.safeid(h.safe_unicode(request.POST.get('f_path'))),
269 'target_id': h.safeid(h.safe_unicode(request.POST.get('f_path'))),
257 }
270 }
258 if comm:
271 if comm:
259 c.co = comm
272 c.co = comm
260 data.update(comm.get_dict())
273 data.update(comm.get_dict())
261 data.update({'rendered_text':
274 data.update({'rendered_text':
262 render('changeset/changeset_comment_block.html')})
275 render('changeset/changeset_comment_block.html')})
263
276
264 return data No newline at end of file
277 return data
General Comments 0
You need to be logged in to leave comments. Login now