~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge cleanup into first-try

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
    hooks = ProposeMergeHooks()
56
56
 
57
57
    def __init__(self, tree, source_branch, target_branch, message, reviews,
58
 
                 staging=False):
 
58
                 staging=False, approve=False):
59
59
        """Constructor.
60
60
 
61
61
        :param tree: The working tree for the source branch.
65
65
        :param reviews: A list of tuples of reviewer, review type.
66
66
        :param staging: If True, propose the merge against staging instead of
67
67
            production.
 
68
        :param approve: If True, mark the new proposal as approved immediately.
 
69
            This is useful when a project permits some things to be approved
 
70
            by the submitter (e.g. merges between release and deployment
 
71
            branches).
68
72
        """
69
73
        self.tree = tree
70
74
        if staging:
81
85
            self.target_branch = lp_api.LaunchpadBranch.from_bzr(
82
86
                self.launchpad, target_branch)
83
87
        self.commit_message = message
 
88
        # XXX: this is where bug lp:583638 could be tackled.
84
89
        if reviews == []:
85
90
            target_reviewer = self.target_branch.lp.reviewer
86
91
            if target_reviewer is None:
90
95
            self.reviews = [(self.launchpad.people[reviewer], review_type)
91
96
                            for reviewer, review_type in
92
97
                            reviews]
 
98
        self.approve = approve
93
99
 
94
100
    def get_comment(self, prerequisite_branch):
95
101
        """Determine the initial comment for the merge proposal."""
160
166
                 'prerequisite_branch': prerequisite_branch})
161
167
        return prerequisite_branch
162
168
 
 
169
    def call_webservice(self, call, *args, **kwargs):
 
170
        """Make a call to the webservice, wrapping failures.
 
171
        
 
172
        :param call: The call to make.
 
173
        :param *args: *args for the call.
 
174
        :param **kwargs: **kwargs for the call.
 
175
        :return: The result of calling call(*args, *kwargs).
 
176
        """
 
177
        try:
 
178
            return call(*args, **kwargs)
 
179
        except restful_errors.HTTPError, e:
 
180
            error_lines = []
 
181
            for line in e.content.splitlines():
 
182
                if line.startswith('Traceback (most recent call last):'):
 
183
                    break
 
184
                error_lines.append(line)
 
185
            raise Exception(''.join(error_lines))
 
186
 
163
187
    def create_proposal(self):
164
188
        """Perform the submission."""
165
189
        prerequisite_branch = self._get_prerequisite_branch()
175
199
            review_types.append(review_type)
176
200
            reviewers.append(reviewer.self_link)
177
201
        initial_comment = self.get_comment(prerequisite_branch)
178
 
        try:
179
 
            mp = self.source_branch.lp.createMergeProposal(
180
 
                target_branch=self.target_branch.lp,
181
 
                prerequisite_branch=prereq,
182
 
                initial_comment=initial_comment,
183
 
                commit_message=self.commit_message, reviewers=reviewers,
184
 
                review_types=review_types)
185
 
        except restful_errors.HTTPError, e:
186
 
            error_lines = []
187
 
            for line in e.content.splitlines():
188
 
                if line.startswith('Traceback (most recent call last):'):
189
 
                    break
190
 
                error_lines.append(line)
191
 
            raise Exception(''.join(error_lines))
192
 
        else:
193
 
            webbrowser.open(canonical_url(mp))
 
202
        mp = self.call_webservice(
 
203
            self.source_branch.lp.createMergeProposal,
 
204
            target_branch=self.target_branch.lp,
 
205
            prerequisite_branch=prereq,
 
206
            initial_comment=initial_comment,
 
207
            commit_message=self.commit_message, reviewers=reviewers,
 
208
            review_types=review_types)
 
209
        if self.approve:
 
210
            self.call_webservice(mp.setStatus, status='Approved')
 
211
        webbrowser.open(canonical_url(mp))
194
212
 
195
213
 
196
214
def modified_files(old_tree, new_tree):