Skip to content

Commit 59960fc

Browse files
committed
Fix-up the ability to create a branch
1 parent 5e144a1 commit 59960fc

5 files changed

Lines changed: 56 additions & 37 deletions

File tree

github3/repos/repo.py

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -516,20 +516,21 @@ def create_blob(self, content, encoding):
516516
return sha
517517

518518
@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.
519+
def create_branch_ref(self, name, sha=None):
520+
"""Create a branch git reference.
522521
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.
522+
This is a shortcut for calling
523+
:meth:`github3.repos.repo.Repository.create_ref`.
527524
528-
:returns: bool -- True if successful, False otherwise
525+
:param str branch:
526+
(required), the branch to create
527+
:param str sha:
528+
the commit to base the branch from
529+
:returns:
530+
a reference object representing the branch
531+
:rtype:
532+
:class:`~github3.git.Reference`
529533
"""
530-
if sha is None:
531-
sha = self.commit("HEAD").sha
532-
533534
ref = "refs/heads/%s" % name
534535
return self.create_ref(ref, sha)
535536

@@ -931,9 +932,8 @@ def create_ref(self, ref, sha):
931932
:rtype:
932933
:class:`~github3.git.Reference`
933934
"""
934-
if isinstance(sha, Commit):
935-
sha = sha.sha
936-
935+
sha = getattr(sha, 'sha', sha)
936+
937937
json = None
938938
if ref and ref.startswith('refs') and ref.count('/') >= 2 and sha:
939939
data = {'ref': ref, 'sha': sha}
@@ -1095,17 +1095,6 @@ def delete(self):
10951095
"""
10961096
return self._boolean(self._delete(self._api), 204, 404)
10971097

1098-
@requires_auth
1099-
def delete_branch(self, name):
1100-
"""Delete a branch. Returns False if branch doesn't exist
1101-
or not authorized.
1102-
1103-
:param str branch: (required), the branch to delete.
1104-
1105-
:returns: bool -- True if successful, False otherwise
1106-
"""
1107-
return self.delete_ref("heads/%s" % name)
1108-
11091098
@requires_auth
11101099
def delete_key(self, key_id):
11111100
"""Delete the key with the specified id from your deploy keys list.
@@ -1120,18 +1109,6 @@ def delete_key(self, key_id):
11201109
url = self._build_url('keys', str(key_id), base_url=self._api)
11211110
return self._boolean(self._delete(url), 204, 404)
11221111

1123-
@requires_auth
1124-
def delete_ref(self, ref):
1125-
"""Delete a reference. Returns False if ref doesn't exist
1126-
or not authorized for the action.
1127-
1128-
:param str ref: (required), the reference to delete.
1129-
1130-
:returns: bool -- True if successful, False otherwise
1131-
"""
1132-
url = self._build_url('git/refs', ref, base_url=self._api)
1133-
return self._boolean(self._delete(url), 204, 404)
1134-
11351112
@requires_auth
11361113
def delete_subscription(self):
11371114
"""Delete the user's subscription to this repository.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions": [{"request": {"body": {"encoding": "utf-8", "string": ""}, "headers": {"User-Agent": "github3.py/1.1.0", "Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json", "Connection": "keep-alive", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Authorization": "token <AUTH_TOKEN>"}, "method": "GET", "uri": "https://api.github.com/repos/github3py/fork_this"}, "response": {"body": {"encoding": "utf-8", "base64_string": "H4sIAAAAAAAAA+1YwXKrOBD8lRTXdQJ24vcSqrbe7hfsJae9uGSQjTaAWEnY5VD59+2RhAHX2nHkay4uLNRNazQjzUwXiTxKl8/zHy/PT7OoZhWP0mgj1dvKFEJHs2jTluXKj2+FKdr1Y3OIxzPkvuYqSruolFtRA36cBjjRz38+L+bLH7OI7ZhhatWqErMKYxqdxrEb1MmDg7Waq0zWhtfmIZNV3MYe/mv3+xMIt8qzEHOEgRO2RngihwabjseCClOVJwrcazt/PHMjy1LugT8VfPETMI2HkfHss6i3IRSAdbE0BYfFsIwPWrzQ5otyLKTDwrRZiZxINPZA8fxrkjwIgmi3P7pY8UZatnatMyUaI2T9RWkTKKik2rJavLMAKkDJWUnUF0VYCKB8B4/7ItZhurhRYseyA5lD8YyLHawbwnc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mbxSnm2SKGXcevjtZQ5Pvu5PVNykv9/y+O1nTPityoEkbDFF+fSer5mZPDejhsBrXJH708eM/+otgF7sWAAA=", "string": ""}, "headers": {"Server": "GitHub.com", "Date": "Thu, 19 Apr 2018 02:13:43 GMT", "Content-Type": "application/json; charset=utf-8", "Transfer-Encoding": "chunked", "Status": "200 OK", "X-RateLimit-Limit": "5000", "X-RateLimit-Remaining": "4999", "X-RateLimit-Reset": "1524107623", "Cache-Control": "private, max-age=60, s-maxage=60", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "ETag": "W/\"7b15b5de54a51238e3c76ef6da8dbc99\"", "Last-Modified": "Sat, 16 Dec 2017 00:02:09 GMT", "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user", "X-Accepted-OAuth-Scopes": "repo", "X-GitHub-Media-Type": "github.v3; param=full; format=json", "Access-Control-Expose-Headers": "ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "Access-Control-Allow-Origin": "*", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "X-Frame-Options": "deny", "X-Content-Type-Options": "nosniff", "X-XSS-Protection": "1; mode=block", "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-Runtime-rack": "0.065351", "Content-Encoding": "gzip", "X-GitHub-Request-Id": "B968:08B2:F33499:223E70C:5AD7FB57"}, "status": {"code": 200, "message": "OK"}, "url": "https://api.github.com/repos/github3py/fork_this"}, "recorded_at": "2018-04-19T02:13:43"}, {"request": {"body": {"encoding": "utf-8", "string": ""}, "headers": {"User-Agent": "github3.py/1.1.0", "Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json", "Connection": "keep-alive", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Authorization": "token <AUTH_TOKEN>"}, "method": "GET", "uri": "https://api.github.com/repos/github3py/fork_this/commits/master"}, "response": {"body": {"encoding": "utf-8", "base64_string": "H4sIAAAAAAAAA61Xy67bNhD9FUHb2FdvyTZwEQdt0HaRLvrYNA6MEUXaRCVSICkbruF/z1Dy6zrNvZYcLwxK4jkzHM4hZ/auXoM7c9M4ZWQSp2E4DdMJBDGLk8CPJ36Kw2iaFDQhBcmJO3KJrCpu3NnehcaspbIjARVFlt9AOH8aqEtqpHB+kqoATSRiaAW8xAkrBYyBIbKsuFjJzXxlPzwhJU4qwFiS0A+ycRCOg/Qv35/54czP/nEPJ7uGXhv8hZtfm/zKgJCK1uVuvuJm3eT3EVdUa1hZ05+oWlFH0O04VyDI2uHCSKcCba2OXKMoztofQ5YR8MNJ7gPJplHM/GnGUhKSMIl9n/gQZizKk8xPEdgou/i1MbWeeR7U/Onin4cOS+11L6J65zGp/l2aNW/fedam9u62hXF6wFi3tdrrmQ1UmCWRjcCk8EfuhirOOAHDpbDR6p5p4c4YlJqOXEVB209uIzRfCfwycu0ATKMwvqIpy5Fbw66UgCD7eBi+rAFLWpuqXL6M4tV2/d9GdUYGhE3f2Lk7Nfouy7MA3CeNsb7ItpQrbjcCo1/BhqtGhzFO4Bj2MPYnEe4mbMCAunWzfamjYxo3mioihUF+qziv8Tr0+82zpUPRdySW131LDpZMezcevb4lN5OZLEu5RZZbr1/q7ltDKL0jEp3sxnhKDWRB5N6TZk0xeLikgw0E16a/Uy1qj4eBNkteWB6NwVe06O3YEYdubQV6tG+PnpawyTVRvLaS7e/gCzSySbUCwf9rD4D+bIi2Sdqeir1X2KIQTTc213vDO9jeqxXfANnZ0ChKKN9gsAdS3uCR0exqe9f8jUlhQ88NXUKB1+HxfLy96U4a3dJ8zDCvEWN1FEwnaRzH2VCFnvAPaPTKo9f1eTWxlzZPuOG6vGF4RJNnqof0eGb5cVq8UF6reIgOz0x9NXgG9tffGfpjtHflyQvd3qW7GlR7Rc4+n2q8JIgTMk0nYRGnRRbEJAqA+nnCchr5gBdkNIVpShOkH1h2nS7yHpZeF9sr9cndNg6jUwBoFhQQY/0fh9PMJ6kfRVmQBBl2CGHIchYGkDAS2L7gwQD0sDQ4AHfbOHxpb1mbC3vXSANYv4d41BYFb281PH+xX6HY5xyf8NRmvKTXuROQnMUZzbI4zbIIIgijLM+LKLVNw7Qg2B1QmOQMQ2ehxxbqj48ffv708alqi2L0oEFKt5IFltRtofx9F7BDWoNYWR/Q1byUeb8i1iLuLmG9az8VbPuZQsAwS8cq842b/fsd1Ql/cf+9ouy5R79TY/e6xi2Zz51xMIqdd/ZvPl8I59y34fj59MPxQow/OK1L3Ei1c7CjNFSbdj5eSI5kC7FYOL9L23iWXFAHjENFgR8cmxgL8e4N/IWdU+0AQitsZDtup+tkMSsOXw5fAV7LsNXuDwAA", "string": ""}, "headers": {"Server": "GitHub.com", "Date": "Thu, 19 Apr 2018 02:13:43 GMT", "Content-Type": "application/json; charset=utf-8", "Transfer-Encoding": "chunked", "Status": "200 OK", "X-RateLimit-Limit": "5000", "X-RateLimit-Remaining": "4998", "X-RateLimit-Reset": "1524107623", "Cache-Control": "private, max-age=60, s-maxage=60", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "ETag": "W/\"534b504070349481fa289a9af535efe2\"", "Last-Modified": "Sat, 16 Dec 2017 00:02:07 GMT", "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user", "X-Accepted-OAuth-Scopes": "", "X-GitHub-Media-Type": "github.v3; param=full; format=json", "Access-Control-Expose-Headers": "ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "Access-Control-Allow-Origin": "*", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "X-Frame-Options": "deny", "X-Content-Type-Options": "nosniff", "X-XSS-Protection": "1; mode=block", "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-Runtime-rack": "0.126927", "Content-Encoding": "gzip", "X-GitHub-Request-Id": "B968:08B2:F3349D:223E71A:5AD7FB57"}, "status": {"code": 200, "message": "OK"}, "url": "https://api.github.com/repos/github3py/fork_this/commits/master"}, "recorded_at": "2018-04-19T02:13:43"}, {"request": {"body": {"encoding": "utf-8", "string": "{\"ref\": \"refs/heads/test-branch-646fc8\", \"sha\": \"646fc846229268a14f4510480614f395de5cdcbc\"}"}, "headers": {"User-Agent": "github3.py/1.1.0", "Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json", "Connection": "keep-alive", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Content-Length": "91", "Authorization": "token <AUTH_TOKEN>"}, "method": "POST", "uri": "https://api.github.com/repos/github3py/fork_this/git/refs"}, "response": {"body": {"encoding": "utf-8", "string": "{\"ref\":\"refs/heads/test-branch-646fc8\",\"url\":\"https://api.github.com/repos/github3py/fork_this/git/refs/heads/test-branch-646fc8\",\"object\":{\"sha\":\"646fc846229268a14f4510480614f395de5cdcbc\",\"type\":\"commit\",\"url\":\"https://api.github.com/repos/github3py/fork_this/git/commits/646fc846229268a14f4510480614f395de5cdcbc\"}}"}, "headers": {"Server": "GitHub.com", "Date": "Thu, 19 Apr 2018 02:13:44 GMT", "Content-Type": "application/json; charset=utf-8", "Content-Length": "316", "Status": "201 Created", "X-RateLimit-Limit": "5000", "X-RateLimit-Remaining": "4997", "X-RateLimit-Reset": "1524107623", "Cache-Control": "private, max-age=60, s-maxage=60", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "ETag": "\"301d94615097c4e6e30948f53e32dbfa\"", "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user", "X-Accepted-OAuth-Scopes": "repo", "Location": "https://api.github.com/repos/github3py/fork_this/git/refs/heads/test-branch-646fc8", "X-GitHub-Media-Type": "github.v3; param=full; format=json", "Access-Control-Expose-Headers": "ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "Access-Control-Allow-Origin": "*", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "X-Frame-Options": "deny", "X-Content-Type-Options": "nosniff", "X-XSS-Protection": "1; mode=block", "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-Runtime-rack": "0.593588", "X-GitHub-Request-Id": "B968:08B2:F334AC:223E744:5AD7FB57"}, "status": {"code": 201, "message": "Created"}, "url": "https://api.github.com/repos/github3py/fork_this/git/refs"}, "recorded_at": "2018-04-19T02:13:44"}, {"request": {"body": {"encoding": "utf-8", "string": ""}, "headers": {"User-Agent": "github3.py/1.1.0", "Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json", "Connection": "keep-alive", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Content-Length": "0", "Authorization": "token <AUTH_TOKEN>"}, "method": "DELETE", "uri": "https://api.github.com/repos/github3py/fork_this/git/refs/heads/test-branch-646fc8"}, "response": {"body": {"encoding": null, "string": ""}, "headers": {"Server": "GitHub.com", "Date": "Thu, 19 Apr 2018 02:13:44 GMT", "Content-Type": "application/octet-stream", "Status": "204 No Content", "X-RateLimit-Limit": "5000", "X-RateLimit-Remaining": "4996", "X-RateLimit-Reset": "1524107623", "X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user", "X-Accepted-OAuth-Scopes": "repo", "X-GitHub-Media-Type": "github.v3; param=full; format=json", "Access-Control-Expose-Headers": "ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "Access-Control-Allow-Origin": "*", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "X-Frame-Options": "deny", "X-Content-Type-Options": "nosniff", "X-XSS-Protection": "1; mode=block", "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", "X-Runtime-rack": "0.574721", "X-GitHub-Request-Id": "B968:08B2:F334DC:223E7AB:5AD7FB58"}, "status": {"code": 204, "message": "No Content"}, "url": "https://api.github.com/repos/github3py/fork_this/git/refs/heads/test-branch-646fc8"}, "recorded_at": "2018-04-19T02:13:44"}], "recorded_with": "betamax/0.8.0"}

0 commit comments

Comments
 (0)