Merge lp:~jelmer/brz/existing-proposal into lp:brz/3.1

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/existing-proposal
Merge into: lp:brz/3.1
Diff against target: 71 lines (+21/-6)
2 files modified
breezy/plugins/gitlab/hoster.py (+19/-5)
breezy/propose.py (+2/-1)
To merge this branch: bzr merge lp:~jelmer/brz/existing-proposal
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+392688@code.launchpad.net

Commit message

Support providing the actual proposal to MergeProposalExists.

Description of the change

Support providing the actual proposal to MergeProposalExists.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/plugins/gitlab/hoster.py'
2--- breezy/plugins/gitlab/hoster.py 2020-10-22 17:33:25 +0000
3+++ breezy/plugins/gitlab/hoster.py 2020-10-22 22:08:26 +0000
4@@ -20,6 +20,7 @@
5
6 import json
7 import os
8+import re
9 import time
10
11 from ... import (
12@@ -125,8 +126,11 @@
13 self.project = project
14
15
16-class MergeRequestExists(Exception):
17- """Raised when a merge requests already exists."""
18+class MergeRequestConflict(Exception):
19+ """Raised when a merge requests conflicts."""
20+
21+ def __init__(self, reason):
22+ self.reason = reason
23
24
25 class ProjectCreationTimeout(errors.BzrError):
26@@ -528,7 +532,7 @@
27 if response.status == 403:
28 raise errors.PermissionDenied(response.text)
29 if response.status == 409:
30- raise MergeRequestExists()
31+ raise MergeRequestConflict(json.loads(response.data))
32 if response.status == 422:
33 data = json.loads(response.data)
34 raise GitLabUnprocessable(data['error'])
35@@ -755,8 +759,18 @@
36 kwargs['assignee_ids'].append(user['id'])
37 try:
38 merge_request = self.gl._create_mergerequest(**kwargs)
39- except MergeRequestExists:
40- raise MergeProposalExists(self.source_branch.user_url)
41+ except MergeRequestConflict as e:
42+ m = re.fullmatch(
43+ r'Another open merge request already exists for '
44+ r'this source branch: \!([0-9]+)',
45+ e.reason['message'][0])
46+ if m:
47+ merge_id = int(m.group(1))
48+ mr = self.gl._get_merge_request(
49+ target_project['path_with_namespace'], merge_id)
50+ raise MergeProposalExists(
51+ self.source_branch.user_url, GitLabMergeProposal(self.gl, mr))
52+ raise Exception('conflict: %r' % e.reason)
53 except GitLabUnprocessable as e:
54 if e.error == [
55 "Source project is not a fork of the target project"]:
56
57=== modified file 'breezy/propose.py'
58--- breezy/propose.py 2020-09-09 23:16:31 +0000
59+++ breezy/propose.py 2020-10-22 22:08:26 +0000
60@@ -39,9 +39,10 @@
61
62 _fmt = "A merge proposal already exists: %(url)s."
63
64- def __init__(self, url):
65+ def __init__(self, url, existing_proposal=None):
66 errors.BzrError.__init__(self)
67 self.url = url
68+ self.existing_proposal = existing_proposal
69
70
71 class UnsupportedHoster(errors.BzrError):

Subscribers

People subscribed via source and target branches