~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

(vila) Revise legal option names to be less drastic. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2010 Canonical Ltd
 
1
# Copyright (C) 2010, 2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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
 
17
19
from bzrlib import (
18
20
    errors,
19
21
    hooks,
24
26
 
25
27
from bzrlib import (
26
28
    msgeditor,
27
 
)
 
29
    )
 
30
from bzrlib.i18n import gettext
28
31
from bzrlib.plugins.launchpad import (
29
32
    lp_api,
30
33
    lp_registration,
31
 
)
 
34
    )
32
35
""")
33
36
 
34
37
 
36
39
    """Hooks for proposing a merge on Launchpad."""
37
40
 
38
41
    def __init__(self):
39
 
        hooks.Hooks.__init__(self)
40
 
        self.create_hook(
41
 
            hooks.HookPoint(
42
 
                'get_prerequisite',
43
 
                "Return the prerequisite branch for proposing as merge.",
44
 
                (2, 1), None),
45
 
        )
46
 
        self.create_hook(
47
 
            hooks.HookPoint(
48
 
                'merge_proposal_body',
49
 
                "Return an initial body for the merge proposal message.",
50
 
                (2, 1), None),
51
 
        )
 
42
        hooks.Hooks.__init__(self, "bzrlib.plugins.launchpad.lp_propose",
 
43
            "Proposer.hooks")
 
44
        self.add_hook('get_prerequisite',
 
45
            "Return the prerequisite branch for proposing as merge.", (2, 1))
 
46
        self.add_hook('merge_proposal_body',
 
47
            "Return an initial body for the merge proposal message.", (2, 1))
52
48
 
53
49
 
54
50
class Proposer(object):
56
52
    hooks = ProposeMergeHooks()
57
53
 
58
54
    def __init__(self, tree, source_branch, target_branch, message, reviews,
59
 
                 staging=False, approve=False):
 
55
                 staging=False, approve=False, fixes=None):
60
56
        """Constructor.
61
57
 
62
58
        :param tree: The working tree for the source branch.
94
90
                            for reviewer, review_type in
95
91
                            reviews]
96
92
        self.approve = approve
 
93
        self.fixes = fixes
97
94
 
98
95
    def get_comment(self, prerequisite_branch):
99
96
        """Determine the initial comment for the merge proposal."""
140
137
            })
141
138
        return body
142
139
 
 
140
    def get_source_revid(self):
 
141
        """Get the revision ID of the source branch."""
 
142
        source_branch = self.source_branch.bzr
 
143
        source_branch.lock_read()
 
144
        try:
 
145
            return source_branch.last_revision()
 
146
        finally:
 
147
            source_branch.unlock()
 
148
 
143
149
    def check_proposal(self):
144
150
        """Check that the submission is sensible."""
145
151
        if self.source_branch.lp.self_link == self.target_branch.lp.self_link:
149
155
            if mp.queue_status in ('Merged', 'Rejected'):
150
156
                continue
151
157
            if mp.target_branch.self_link == self.target_branch.lp.self_link:
152
 
                raise errors.BzrCommandError(
153
 
                    'There is already a branch merge proposal: %s' %
 
158
                raise errors.BzrCommandError(gettext(
 
159
                    'There is already a branch merge proposal: %s') %
154
160
                    lp_api.canonical_url(mp))
155
161
 
156
162
    def _get_prerequisite_branch(self):
183
189
                error_lines.append(line)
184
190
            raise Exception(''.join(error_lines))
185
191
 
 
192
    def approve_proposal(self, mp):
 
193
        revid = self.get_source_revid()
 
194
        self.call_webservice(
 
195
            mp.createComment,
 
196
            vote=u'Approve',
 
197
            subject='', # Use the default subject.
 
198
            content=u"Rubberstamp! Proposer approves of own proposal.")
 
199
        self.call_webservice(mp.setStatus, status=u'Approved', revid=revid)
 
200
 
186
201
    def create_proposal(self):
187
202
        """Perform the submission."""
188
203
        prerequisite_branch = self._get_prerequisite_branch()
206
221
            commit_message=self.commit_message, reviewers=reviewers,
207
222
            review_types=review_types)
208
223
        if self.approve:
209
 
            self.call_webservice(mp.setStatus, status='Approved')
 
224
            self.approve_proposal(mp)
 
225
        if self.fixes:
 
226
            if self.fixes.startswith('lp:'):
 
227
                self.fixes = self.fixes[3:]
 
228
            self.call_webservice(
 
229
                self.source_branch.lp.linkBug,
 
230
                bug=self.launchpad.bugs[int(self.fixes)])
210
231
        webbrowser.open(lp_api.canonical_url(mp))
211
232
 
212
233