~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

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
 
17
19
from bzrlib import (
18
20
    errors,
19
21
    hooks,
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,
49
52
    hooks = ProposeMergeHooks()
50
53
 
51
54
    def __init__(self, tree, source_branch, target_branch, message, reviews,
52
 
                 staging=False, approve=False):
 
55
                 staging=False, approve=False, fixes=None):
53
56
        """Constructor.
54
57
 
55
58
        :param tree: The working tree for the source branch.
87
90
                            for reviewer, review_type in
88
91
                            reviews]
89
92
        self.approve = approve
 
93
        self.fixes = fixes
90
94
 
91
95
    def get_comment(self, prerequisite_branch):
92
96
        """Determine the initial comment for the merge proposal."""
 
97
        if self.commit_message is not None:
 
98
            return self.commit_message.strip().encode('utf-8')
93
99
        info = ["Source: %s\n" % self.source_branch.lp.bzr_identity]
94
100
        info.append("Target: %s\n" % self.target_branch.lp.bzr_identity)
95
101
        if prerequisite_branch is not None:
133
139
            })
134
140
        return body
135
141
 
 
142
    def get_source_revid(self):
 
143
        """Get the revision ID of the source branch."""
 
144
        source_branch = self.source_branch.bzr
 
145
        source_branch.lock_read()
 
146
        try:
 
147
            return source_branch.last_revision()
 
148
        finally:
 
149
            source_branch.unlock()
 
150
 
136
151
    def check_proposal(self):
137
152
        """Check that the submission is sensible."""
138
153
        if self.source_branch.lp.self_link == self.target_branch.lp.self_link:
142
157
            if mp.queue_status in ('Merged', 'Rejected'):
143
158
                continue
144
159
            if mp.target_branch.self_link == self.target_branch.lp.self_link:
145
 
                raise errors.BzrCommandError(
146
 
                    'There is already a branch merge proposal: %s' %
 
160
                raise errors.BzrCommandError(gettext(
 
161
                    'There is already a branch merge proposal: %s') %
147
162
                    lp_api.canonical_url(mp))
148
163
 
149
164
    def _get_prerequisite_branch(self):
176
191
                error_lines.append(line)
177
192
            raise Exception(''.join(error_lines))
178
193
 
 
194
    def approve_proposal(self, mp):
 
195
        revid = self.get_source_revid()
 
196
        self.call_webservice(
 
197
            mp.createComment,
 
198
            vote=u'Approve',
 
199
            subject='', # Use the default subject.
 
200
            content=u"Rubberstamp! Proposer approves of own proposal.")
 
201
        self.call_webservice(mp.setStatus, status=u'Approved', revid=revid)
 
202
 
179
203
    def create_proposal(self):
180
204
        """Perform the submission."""
181
205
        prerequisite_branch = self._get_prerequisite_branch()
199
223
            commit_message=self.commit_message, reviewers=reviewers,
200
224
            review_types=review_types)
201
225
        if self.approve:
202
 
            self.call_webservice(mp.setStatus, status='Approved')
 
226
            self.approve_proposal(mp)
 
227
        if self.fixes:
 
228
            if self.fixes.startswith('lp:'):
 
229
                self.fixes = self.fixes[3:]
 
230
            self.call_webservice(
 
231
                self.source_branch.lp.linkBug,
 
232
                bug=self.launchpad.bugs[int(self.fixes)])
203
233
        webbrowser.open(lp_api.canonical_url(mp))
204
234
 
205
235