##// END OF EJS Templates
added more validations when opening pull request...
marcink -
r2711:1de45f58 beta
parent child Browse files
Show More
@@ -24,6 +24,7 b''
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 import formencode
27
28
28 from webob.exc import HTTPNotFound, HTTPForbidden
29 from webob.exc import HTTPNotFound, HTTPForbidden
29 from collections import defaultdict
30 from collections import defaultdict
@@ -48,6 +49,7 b' from rhodecode.model.meta import Session'
48 from rhodecode.model.repo import RepoModel
49 from rhodecode.model.repo import RepoModel
49 from rhodecode.model.comment import ChangesetCommentsModel
50 from rhodecode.model.comment import ChangesetCommentsModel
50 from rhodecode.model.changeset_status import ChangesetStatusModel
51 from rhodecode.model.changeset_status import ChangesetStatusModel
52 from rhodecode.model.forms import PullRequestForm
51
53
52 log = logging.getLogger(__name__)
54 log = logging.getLogger(__name__)
53
55
@@ -138,18 +140,31 b' class PullrequestsController(BaseRepoCon'
138
140
139 @NotAnonymous()
141 @NotAnonymous()
140 def create(self, repo_name):
142 def create(self, repo_name):
141 req_p = request.POST
143
142 org_repo = req_p['org_repo']
144 try:
143 org_ref = req_p['org_ref']
145 _form = PullRequestForm()().to_python(request.POST)
144 other_repo = req_p['other_repo']
146 except formencode.Invalid, errors:
145 other_ref = req_p['other_ref']
147 log.error(traceback.format_exc())
146 revisions = req_p.getall('revisions')
148 if errors.error_dict.get('revisions'):
147 reviewers = req_p.getall('review_members')
149 msg = _('Cannot open a pull request with '
150 'empty list of changesets')
151 elif errors.error_dict.get('pullrequest_title'):
152 msg = _('Pull request requires a title with min. 3 chars')
153 else:
154 msg = _('error during creation of pull request')
148
155
149 #TODO: wrap this into a FORM !!!
156 h.flash(msg, 'error')
157 return redirect(url('pullrequest_home', repo_name=repo_name))
150
158
151 title = req_p['pullrequest_title']
159 org_repo = _form['org_repo']
152 description = req_p['pullrequest_desc']
160 org_ref = _form['org_ref']
161 other_repo = _form['other_repo']
162 other_ref = _form['other_ref']
163 revisions = _form['revisions']
164 reviewers = _form['review_members']
165
166 title = _form['pullrequest_title']
167 description = _form['pullrequest_desc']
153
168
154 try:
169 try:
155 pull_request = PullRequestModel().create(
170 pull_request = PullRequestModel().create(
@@ -163,7 +178,7 b' class PullrequestsController(BaseRepoCon'
163 h.flash(_('Error occurred during sending pull request'),
178 h.flash(_('Error occurred during sending pull request'),
164 category='error')
179 category='error')
165 log.error(traceback.format_exc())
180 log.error(traceback.format_exc())
166 return redirect(url('changelog_home', repo_name=org_repo,))
181 return redirect(url('pullrequest_home', repo_name=repo_name))
167
182
168 return redirect(url('pullrequest_show', repo_name=other_repo,
183 return redirect(url('pullrequest_show', repo_name=other_repo,
169 pull_request_id=pull_request.pull_request_id))
184 pull_request_id=pull_request.pull_request_id))
@@ -190,12 +205,19 b' class PullrequestsController(BaseRepoCon'
190 """
205 """
191
206
192 org_repo = pull_request.org_repo
207 org_repo = pull_request.org_repo
193 org_ref_type, org_ref_, org_ref = pull_request.org_ref.split(':')
208 (org_ref_type,
209 org_ref_name,
210 org_ref_rev) = pull_request.org_ref.split(':')
211
194 other_repo = pull_request.other_repo
212 other_repo = pull_request.other_repo
195 other_ref_type, other_ref, other_ref_ = pull_request.other_ref.split(':')
213 (other_ref_type,
214 other_ref_name,
215 other_ref_rev) = pull_request.other_ref.split(':')
196
216
197 org_ref = (org_ref_type, org_ref)
217 # dispite opening revisions for bookmarks/branches/tags, we always
198 other_ref = (other_ref_type, other_ref)
218 # convert this to rev to prevent changes after book or branch change
219 org_ref = ('rev', org_ref_rev)
220 other_ref = ('rev', other_ref_rev)
199
221
200 c.org_repo = org_repo
222 c.org_repo = org_repo
201 c.other_repo = other_repo
223 c.other_repo = other_repo
@@ -321,3 +321,22 b' def UserExtraEmailForm():'
321 email = All(v.UniqSystemEmail(), v.Email)
321 email = All(v.UniqSystemEmail(), v.Email)
322
322
323 return _UserExtraEmailForm
323 return _UserExtraEmailForm
324
325
326 def PullRequestForm():
327 class _PullRequestForm(formencode.Schema):
328 allow_extra_fields = True
329 filter_extra_fields = True
330
331 user = v.UnicodeString(strip=True, required=True)
332 org_repo = v.UnicodeString(strip=True, required=True)
333 org_ref = v.UnicodeString(strip=True, required=True)
334 other_repo = v.UnicodeString(strip=True, required=True)
335 other_ref = v.UnicodeString(strip=True, required=True)
336 revisions = v.Set(required=True)
337 review_members = v.Set(required=True)
338
339 pullrequest_title = v.UnicodeString(strip=True, required=True, min=3)
340 pullrequest_desc = v.UnicodeString(strip=True, required=False)
341
342 return _PullRequestForm No newline at end of file
@@ -9,9 +9,8 b' from pylons.i18n.translation import _'
9 from webhelpers.pylonslib.secure_form import authentication_token
9 from webhelpers.pylonslib.secure_form import authentication_token
10
10
11 from formencode.validators import (
11 from formencode.validators import (
12 UnicodeString, OneOf, Int, Number, Regex, Email, Bool, StringBoolean, Set
12 UnicodeString, OneOf, Int, Number, Regex, Email, Bool, StringBoolean, Set,
13 )
13 )
14
15 from rhodecode.lib.utils import repo_name_slug
14 from rhodecode.lib.utils import repo_name_slug
16 from rhodecode.model.db import RepoGroup, Repository, UsersGroup, User
15 from rhodecode.model.db import RepoGroup, Repository, UsersGroup, User
17 from rhodecode.lib.exceptions import LdapImportError
16 from rhodecode.lib.exceptions import LdapImportError
General Comments 0
You need to be logged in to leave comments. Login now