~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-11-08 13:45:51 UTC
  • mfrom: (5532.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20101108134551-sxvk77ehmegkrwmm
(vila) Fix news entry

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
 
 
18
import urlparse
 
19
import webbrowser
 
20
 
17
21
from bzrlib import (
18
22
    errors,
19
23
    hooks,
20
 
    )
21
 
from bzrlib.lazy_import import lazy_import
22
 
lazy_import(globals(), """
23
 
import webbrowser
24
 
 
25
 
from bzrlib import (
26
24
    msgeditor,
27
25
)
28
26
from bzrlib.plugins.launchpad import (
29
27
    lp_api,
30
28
    lp_registration,
31
29
)
32
 
""")
 
30
 
 
31
from lazr.restfulclient import errors as restful_errors
33
32
 
34
33
 
35
34
class ProposeMergeHooks(hooks.Hooks):
75
74
        if staging:
76
75
            lp_instance = 'staging'
77
76
        else:
78
 
            lp_instance = 'production'
 
77
            lp_instance = 'edge'
79
78
        service = lp_registration.LaunchpadService(lp_instance=lp_instance)
80
79
        self.launchpad = lp_api.login(service)
81
80
        self.source_branch = lp_api.LaunchpadBranch.from_bzr(
82
81
            self.launchpad, source_branch)
83
82
        if target_branch is None:
84
 
            self.target_branch = self.source_branch.get_target()
 
83
            self.target_branch = self.source_branch.get_dev_focus()
85
84
        else:
86
85
            self.target_branch = lp_api.LaunchpadBranch.from_bzr(
87
86
                self.launchpad, target_branch)
88
87
        self.commit_message = message
89
88
        # XXX: this is where bug lp:583638 could be tackled.
90
89
        if reviews == []:
91
 
            self.reviews = []
 
90
            target_reviewer = self.target_branch.lp.reviewer
 
91
            if target_reviewer is None:
 
92
                raise errors.BzrCommandError('No reviewer specified')
 
93
            self.reviews = [(target_reviewer, '')]
92
94
        else:
93
95
            self.reviews = [(self.launchpad.people[reviewer], review_type)
94
96
                            for reviewer, review_type in
151
153
            if mp.target_branch.self_link == self.target_branch.lp.self_link:
152
154
                raise errors.BzrCommandError(
153
155
                    'There is already a branch merge proposal: %s' %
154
 
                    lp_api.canonical_url(mp))
 
156
                    canonical_url(mp))
155
157
 
156
158
    def _get_prerequisite_branch(self):
157
159
        hooks = self.hooks['get_prerequisite']
172
174
        :param **kwargs: **kwargs for the call.
173
175
        :return: The result of calling call(*args, *kwargs).
174
176
        """
175
 
        from lazr.restfulclient import errors as restful_errors
176
177
        try:
177
178
            return call(*args, **kwargs)
178
179
        except restful_errors.HTTPError, e:
207
208
            review_types=review_types)
208
209
        if self.approve:
209
210
            self.call_webservice(mp.setStatus, status='Approved')
210
 
        webbrowser.open(lp_api.canonical_url(mp))
 
211
        webbrowser.open(canonical_url(mp))
211
212
 
212
213
 
213
214
def modified_files(old_tree, new_tree):
216
217
        old_tree):
217
218
        if c and k == 'file':
218
219
            yield str(path)
 
220
 
 
221
 
 
222
def canonical_url(object):
 
223
    """Return the canonical URL for a branch."""
 
224
    scheme, netloc, path, params, query, fragment = urlparse.urlparse(
 
225
        str(object.self_link))
 
226
    path = '/'.join(path.split('/')[2:])
 
227
    netloc = netloc.replace('api.', 'code.')
 
228
    return urlparse.urlunparse((scheme, netloc, path, params, query,
 
229
                                fragment))