~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin
  • Date: 2010-05-20 18:23:17 UTC
  • mto: This revision was merged to the branch mainline in revision 5244.
  • Revision ID: gzlist@googlemail.com-20100520182317-10t33p32m8qcq0m3
Point launchpad links in comments at production server rather than edge

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, approve=False):
 
58
                 staging=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).
72
68
        """
73
69
        self.tree = tree
74
70
        if staging:
75
71
            lp_instance = 'staging'
76
72
        else:
77
 
            lp_instance = 'edge'
 
73
            lp_instance = 'production'
78
74
        service = lp_registration.LaunchpadService(lp_instance=lp_instance)
79
75
        self.launchpad = lp_api.login(service)
80
76
        self.source_branch = lp_api.LaunchpadBranch.from_bzr(
85
81
            self.target_branch = lp_api.LaunchpadBranch.from_bzr(
86
82
                self.launchpad, target_branch)
87
83
        self.commit_message = message
88
 
        # XXX: this is where bug lp:583638 could be tackled.
89
84
        if reviews == []:
90
85
            target_reviewer = self.target_branch.lp.reviewer
91
86
            if target_reviewer is None:
95
90
            self.reviews = [(self.launchpad.people[reviewer], review_type)
96
91
                            for reviewer, review_type in
97
92
                            reviews]
98
 
        self.approve = approve
99
93
 
100
94
    def get_comment(self, prerequisite_branch):
101
95
        """Determine the initial comment for the merge proposal."""
166
160
                 'prerequisite_branch': prerequisite_branch})
167
161
        return prerequisite_branch
168
162
 
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
 
 
187
163
    def create_proposal(self):
188
164
        """Perform the submission."""
189
165
        prerequisite_branch = self._get_prerequisite_branch()
199
175
            review_types.append(review_type)
200
176
            reviewers.append(reviewer.self_link)
201
177
        initial_comment = self.get_comment(prerequisite_branch)
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))
 
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))
212
194
 
213
195
 
214
196
def modified_files(old_tree, new_tree):