/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to github.py

  • Committer: Jelmer Vernooij
  • Date: 2018-10-14 19:02:14 UTC
  • mto: (0.431.45 trunk)
  • mto: This revision was merged to the branch mainline in revision 7233.
  • Revision ID: jelmer@jelmer.uk-20181014190214-w3zjgxn2p49dgn60
Some python 3 compatibility.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
from ...config import AuthenticationConfig, GlobalStack
39
39
from ...git.urls import git_url_to_bzr_url
40
40
from ...i18n import gettext
 
41
from ...sixish import PY3
41
42
from ...trace import note
42
43
from ...lazy_import import lazy_import
43
44
lazy_import(globals(), """
81
82
    return owner, repo_name, branch.name
82
83
 
83
84
 
 
85
def github_url_to_bzr_url(url, branch_name):
 
86
    if not PY3:
 
87
        branch_name = branch_name.encode('utf-8')
 
88
    return urlutils.join_segment_parameters(
 
89
            git_url_to_bzr_url(url), {"branch": branch_name})
 
90
 
 
91
 
84
92
class GitHub(Hoster):
85
93
 
86
94
    supports_merge_proposal_labels = True
117
125
        remote_dir = controldir.ControlDir.open(git_url_to_bzr_url(remote_repo.ssh_url))
118
126
        push_result = remote_dir.push_branch(local_branch, revision_id=revision_id,
119
127
            overwrite=overwrite, name=name)
120
 
        return push_result.target_branch, urlutils.join_segment_parameters(
121
 
                remote_repo.html_url, {"branch": name.encode('utf-8')})
 
128
        return push_result.target_branch, github_url_to_bzr_url(
 
129
                remote_repo.html_url, name)
122
130
 
123
131
    def get_push_url(self, branch):
124
132
        owner, project, branch_name = parse_github_url(branch)
125
133
        repo = self.gh.get_repo('%s/%s' % (owner, project))
126
 
        return urlutils.join_segment_parameters(
127
 
            git_url_to_bzr_url(repo.ssh_url), {"branch": branch_name.encode('utf-8')})
 
134
        return github_url_to_bzr_url(repo.ssh_url, branch_name)
128
135
 
129
136
    def get_derived_branch(self, base_branch, name, project=None, owner=None):
130
137
        import github
136
143
            project = base_repo.name
137
144
        try:
138
145
            remote_repo = self.gh.get_repo('%s/%s' % (owner, project))
139
 
            full_url = urlutils.join_segment_parameters(
140
 
                git_url_to_bzr_url(remote_repo.ssh_url), {"branch": name.encode('utf-8')})
 
146
            full_url = github_url_to_bzr_url(remote_repo.ssh_url, name)
141
147
            return _mod_branch.Branch.open(full_url)
142
148
        except github.UnknownObjectException:
143
149
            raise errors.NotBranchError('https://github.com/%s/%s' % (owner, project))