Skip to content

Commit 567a54e

Browse files
megawacsigmavirus24
authored andcommitted
Support for creating and deleting branches
1 parent 76f5b76 commit 567a54e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

github3/repos/repo.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,26 @@ def create_blob(self, content, encoding):
515515
sha = json.get('sha')
516516
return sha
517517

518+
@requires_auth
519+
def create_branch(self, name, sha=None):
520+
"""Create a branch. Returns False if branch doesn't exist
521+
or not authorized.
522+
523+
:param str branch: (required), the branch to create.
524+
:param str|commit sha: (optional), the commit to base
525+
the branch from, otherwise the HEAD commit on
526+
master will be fetched from the API.
527+
528+
:returns: bool -- True if successful, False otherwise
529+
"""
530+
if isinstance(sha, Commit):
531+
sha = sha.sha
532+
elif not isinstance(sha, basestring):
533+
sha = self.commit("HEAD").sha
534+
535+
ref = "refs/heads/%s" % name
536+
return self.create_ref(ref, sha)
537+
518538
@requires_auth
519539
def create_comment(self, body, sha, path=None, position=None, line=1):
520540
"""Create a comment on a commit.
@@ -1074,6 +1094,18 @@ def delete(self):
10741094
"""
10751095
return self._boolean(self._delete(self._api), 204, 404)
10761096

1097+
@requires_auth
1098+
def delete_branch(self, name):
1099+
"""Delete a branch. Returns False if branch doesn't exist
1100+
or not authorized.
1101+
1102+
:param str branch: (required), the branch to delete.
1103+
1104+
:returns: bool -- True if successful, False otherwise
1105+
"""
1106+
url = self._build_url('git/refs/heads', name, base_url=self._api)
1107+
return self._boolean(self._delete(url), 204, 404)
1108+
10771109
@requires_auth
10781110
def delete_key(self, key_id):
10791111
"""Delete the key with the specified id from your deploy keys list.

0 commit comments

Comments
 (0)