Changeset - e68c0cd1647d
[Not reviewed]
default
0 1 0
Mads Kiilerich - 6 years ago 2020-02-04 03:07:44
mads@kiilerich.com
Grafted from: d0f213273ba4
pull-request: refactor iteration version bump

Avoid relying on exceptions thrown when re.match fails ... and thus please
pytype and make the code better.
1 file changed with 5 insertions and 5 deletions:
0 comments (0 inline, 0 general)
kallithea/model/pull_request.py
Show inline comments
 
@@ -353,29 +353,29 @@ class CreatePullRequestIterationAction(o
 
                infos.append(_("Ancestor didn't change - diff since previous iteration:"))
 
                infos.append(h.canonical_url('compare_url',
 
                                 repo_name=org_repo.repo_name, # other_repo is always same as repo_name
 
                                 org_ref_type='rev', org_ref_name=h.short_id(org_rev), # use old org_rev as base
 
                                 other_ref_type='rev', other_ref_name=h.short_id(new_org_rev),
 
                                 )) # note: linear diff, merge or not doesn't matter
 
            else:
 
                infos.append(_('This iteration is based on another %s revision and there is no simple diff.') % other_ref_name)
 
        else:
 
            infos.append(_('No changes found on %s %s since previous iteration.') % (org_ref_type, org_ref_name))
 
            # TODO: fail?
 

	
 
        try:
 
            title, old_v = re.match(r'(.*)\(v(\d+)\)\s*$', title).groups()
 
            v = int(old_v) + 1
 
        except (AttributeError, ValueError):
 
            v = 2
 
        v = 2
 
        m = re.match(r'(.*)\(v(\d+)\)\s*$', title)
 
        if m is not None:
 
            title = m.group(1)
 
            v = int(m.group(2)) + 1
 
        self.create_action.title = '%s (v%s)' % (title.strip(), v)
 

	
 
        # using a mail-like separator, insert new iteration info in description with latest first
 
        descriptions = description.replace('\r\n', '\n').split('\n-- \n', 1)
 
        description = descriptions[0].strip() + '\n\n-- \n' + '\n'.join(infos)
 
        if len(descriptions) > 1:
 
            description += '\n\n' + descriptions[1].strip()
 
        self.create_action.description = description
 

	
 
        if not CreatePullRequestIterationAction.is_user_authorized(self.old_pull_request):
 
            raise CreatePullRequestAction.Unauthorized(_('You are not authorized to create the pull request'))
 

	
0 comments (0 inline, 0 general)