/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/launchpad/lp_propose.py

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from __future__ import absolute_import
18
 
 
19
 
from bzrlib import (
 
17
from ... import (
20
18
    errors,
21
19
    hooks,
22
20
    )
23
 
from bzrlib.lazy_import import lazy_import
 
21
from ...lazy_import import lazy_import
24
22
lazy_import(globals(), """
25
23
import webbrowser
26
24
 
27
 
from bzrlib import (
 
25
from breezy import (
28
26
    msgeditor,
29
27
    )
30
 
from bzrlib.i18n import gettext
31
 
from bzrlib.plugins.launchpad import (
 
28
from breezy.i18n import gettext
 
29
from breezy.plugins.launchpad import (
32
30
    lp_api,
33
 
    lp_registration,
34
31
    )
35
32
""")
36
33
 
39
36
    """Hooks for proposing a merge on Launchpad."""
40
37
 
41
38
    def __init__(self):
42
 
        hooks.Hooks.__init__(self, "bzrlib.plugins.launchpad.lp_propose",
43
 
            "Proposer.hooks")
 
39
        hooks.Hooks.__init__(self, "breezy.plugins.launchpad.lp_propose",
 
40
                             "Proposer.hooks")
44
41
        self.add_hook('get_prerequisite',
45
 
            "Return the prerequisite branch for proposing as merge.", (2, 1))
 
42
                      "Return the prerequisite branch for proposing as merge.", (2, 1))
46
43
        self.add_hook('merge_proposal_body',
47
 
            "Return an initial body for the merge proposal message.", (2, 1))
 
44
                      "Return an initial body for the merge proposal message.", (2, 1))
48
45
 
49
46
 
50
47
class Proposer(object):
69
66
        """
70
67
        self.tree = tree
71
68
        if staging:
72
 
            lp_instance = 'staging'
 
69
            lp_base_url = lp_api.uris.STAGING_SERVICE_ROOT
73
70
        else:
74
 
            lp_instance = 'production'
75
 
        service = lp_registration.LaunchpadService(lp_instance=lp_instance)
76
 
        self.launchpad = lp_api.login(service)
 
71
            lp_base_url = lp_api.uris.LPNET_SERVICE_ROOT
 
72
        self.launchpad = lp_api.connect_launchpad(lp_base_url)
77
73
        self.source_branch = lp_api.LaunchpadBranch.from_bzr(
78
74
            self.launchpad, source_branch)
79
75
        if target_branch is None:
94
90
 
95
91
    def get_comment(self, prerequisite_branch):
96
92
        """Determine the initial comment for the merge proposal."""
 
93
        if self.commit_message is not None:
 
94
            return self.commit_message.strip().encode('utf-8')
97
95
        info = ["Source: %s\n" % self.source_branch.lp.bzr_identity]
98
96
        info.append("Target: %s\n" % self.target_branch.lp.bzr_identity)
99
97
        if prerequisite_branch is not None:
101
99
        for rdata in self.reviews:
102
100
            uniquename = "%s (%s)" % (rdata[0].display_name, rdata[0].name)
103
101
            info.append('Reviewer: %s, type "%s"\n' % (uniquename, rdata[1]))
104
 
        self.source_branch.bzr.lock_read()
105
 
        try:
106
 
            self.target_branch.bzr.lock_read()
107
 
            try:
108
 
                body = self.get_initial_body()
109
 
            finally:
110
 
                self.target_branch.bzr.unlock()
111
 
        finally:
112
 
            self.source_branch.bzr.unlock()
 
102
        with self.source_branch.bzr.lock_read(), \
 
103
                self.target_branch.bzr.lock_read():
 
104
            body = self.get_initial_body()
113
105
        initial_comment = msgeditor.edit_commit_message(''.join(info),
114
106
                                                        start_message=body)
115
107
        return initial_comment.strip().encode('utf-8')
126
118
            files = modified_files(lca_tree, source_tree)
127
119
            return list(files)
128
120
        target_loc = ('bzr+ssh://bazaar.launchpad.net/%s' %
129
 
                       self.target_branch.lp.unique_name)
 
121
                      self.target_branch.lp.unique_name)
130
122
        body = None
131
123
        for hook in self.hooks['merge_proposal_body']:
132
124
            body = hook({
140
132
    def get_source_revid(self):
141
133
        """Get the revision ID of the source branch."""
142
134
        source_branch = self.source_branch.bzr
143
 
        source_branch.lock_read()
144
 
        try:
 
135
        with source_branch.lock_read():
145
136
            return source_branch.last_revision()
146
 
        finally:
147
 
            source_branch.unlock()
148
137
 
149
138
    def check_proposal(self):
150
139
        """Check that the submission is sensible."""
151
140
        if self.source_branch.lp.self_link == self.target_branch.lp.self_link:
152
 
            raise errors.BzrCommandError(
 
141
            raise errors.CommandError(
153
142
                'Source and target branches must be different.')
154
143
        for mp in self.source_branch.lp.landing_targets:
155
144
            if mp.queue_status in ('Merged', 'Rejected'):
156
145
                continue
157
146
            if mp.target_branch.self_link == self.target_branch.lp.self_link:
158
 
                raise errors.BzrCommandError(gettext(
 
147
                raise errors.CommandError(gettext(
159
148
                    'There is already a branch merge proposal: %s') %
160
149
                    lp_api.canonical_url(mp))
161
150
 
172
161
 
173
162
    def call_webservice(self, call, *args, **kwargs):
174
163
        """Make a call to the webservice, wrapping failures.
175
 
        
 
164
 
176
165
        :param call: The call to make.
177
166
        :param *args: *args for the call.
178
167
        :param **kwargs: **kwargs for the call.
181
170
        from lazr.restfulclient import errors as restful_errors
182
171
        try:
183
172
            return call(*args, **kwargs)
184
 
        except restful_errors.HTTPError, e:
 
173
        except restful_errors.HTTPError as e:
185
174
            error_lines = []
186
175
            for line in e.content.splitlines():
187
176
                if line.startswith('Traceback (most recent call last):'):
194
183
        self.call_webservice(
195
184
            mp.createComment,
196
185
            vote=u'Approve',
197
 
            subject='', # Use the default subject.
 
186
            subject='',  # Use the default subject.
198
187
            content=u"Rubberstamp! Proposer approves of own proposal.")
199
188
        self.call_webservice(mp.setStatus, status=u'Approved', revid=revid)
200
189
 
233
222
 
234
223
def modified_files(old_tree, new_tree):
235
224
    """Return a list of paths in the new tree with modified contents."""
236
 
    for f, (op, path), c, v, p, n, (ok, k), e in new_tree.iter_changes(
237
 
        old_tree):
238
 
        if c and k == 'file':
 
225
    for change in new_tree.iter_changes(old_tree):
 
226
        if change.changed_content and change.kind[1] == 'file':
239
227
            yield str(path)