mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +00:00
Added target_commitish option to Repository.create_git_release() (#625)
* Added is_draft and is_prerelease property to GitRelease * Added target_commitish option to Repository.create_git_release() * Added test for Repository.create_git_release() * Renamed attr of GitRelease: is_draft, is_prerelease -> draft, prerelease
This commit is contained in:
committed by
Wan Liuyang
parent
654b06f6ba
commit
0f0a7d4e68
@@ -68,6 +68,22 @@ class GitRelease(github.GithubObject.CompletableGithubObject):
|
||||
self._completeIfNotSet(self._tag_name)
|
||||
return self._tag_name.value
|
||||
|
||||
@property
|
||||
def draft(self):
|
||||
"""
|
||||
:type: bool
|
||||
"""
|
||||
self._completeIfNotSet(self._draft)
|
||||
return self._draft.value
|
||||
|
||||
@property
|
||||
def prerelease(self):
|
||||
"""
|
||||
:type: bool
|
||||
"""
|
||||
self._completeIfNotSet(self._prerelease)
|
||||
return self._prerelease.value
|
||||
|
||||
@property
|
||||
def author(self):
|
||||
"""
|
||||
@@ -175,6 +191,8 @@ class GitRelease(github.GithubObject.CompletableGithubObject):
|
||||
self._body = github.GithubObject.NotSet
|
||||
self._title = github.GithubObject.NotSet
|
||||
self._tag_name = github.GithubObject.NotSet
|
||||
self._draft = github.GithubObject.NotSet
|
||||
self._prerelease = github.GithubObject.NotSet
|
||||
self._author = github.GithubObject.NotSet
|
||||
self._url = github.GithubObject.NotSet
|
||||
self._upload_url = github.GithubObject.NotSet
|
||||
@@ -191,6 +209,10 @@ class GitRelease(github.GithubObject.CompletableGithubObject):
|
||||
self._title = self._makeStringAttribute(attributes["name"])
|
||||
if "tag_name" in attributes:
|
||||
self._tag_name = self._makeStringAttribute(attributes["tag_name"])
|
||||
if "draft" in attributes:
|
||||
self._draft = self._makeBoolAttribute(attributes["draft"])
|
||||
if "prerelease" in attributes:
|
||||
self._prerelease = self._makeBoolAttribute(attributes["prerelease"])
|
||||
if "author" in attributes:
|
||||
self._author = self._makeClassAttribute(github.GitAuthor.GitAuthor, attributes["author"])
|
||||
if "url" in attributes:
|
||||
|
||||
@@ -787,12 +787,13 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
self.create_git_tag(tag, tag_message, object, type, tagger)
|
||||
return self.create_git_release(tag, release_name, release_message, draft, prerelease)
|
||||
|
||||
def create_git_release(self, tag, name, message, draft=False, prerelease=False):
|
||||
def create_git_release(self, tag, name, message, draft=False, prerelease=False, target_commitish=github.GithubObject.NotSet):
|
||||
assert isinstance(tag, (str, unicode)), tag
|
||||
assert isinstance(name, (str, unicode)), name
|
||||
assert isinstance(message, (str, unicode)), message
|
||||
assert isinstance(draft, bool), draft
|
||||
assert isinstance(prerelease, bool), prerelease
|
||||
assert target_commitish is github.GithubObject.NotSet or isinstance(target_commitish, (str, unicode, github.Branch.Branch, github.Commit.Commit, github.GitCommit.GitCommit)), target_commitish
|
||||
post_parameters = {
|
||||
"tag_name": tag,
|
||||
"name": name,
|
||||
@@ -800,6 +801,12 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
"draft": draft,
|
||||
"prerelease": prerelease,
|
||||
}
|
||||
if isinstance(target_commitish, (str, unicode)):
|
||||
post_parameters["target_commitish"] = target_commitish
|
||||
elif isinstance(target_commitish, github.Branch.Branch):
|
||||
post_parameters["target_commitish"] = target_commitish.name
|
||||
elif isinstance(target_commitish, (github.Commit.Commit, github.GitCommit.GitCommit)):
|
||||
post_parameters["target_commitish"] = target_commitish.sha
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"POST",
|
||||
self.url + "/releases",
|
||||
|
||||
@@ -56,6 +56,8 @@ class Release(Framework.TestCase):
|
||||
self.assertEqual(self.release.upload_url, "https://uploads.github.com/repos/edhollandAL/PyGithub/releases/1210814/assets{?name}")
|
||||
self.assertEqual(self.release.body, "Body")
|
||||
self.assertEqual(self.release.title, "Test")
|
||||
self.assertEqual(self.release.draft, False)
|
||||
self.assertEqual(self.release.prerelease, False)
|
||||
self.assertEqual(self.release.url, "https://api.github.com/repos/edhollandAL/PyGithub/releases/1210814")
|
||||
self.assertEqual(self.release.author._rawData['login'], "edhollandAL")
|
||||
self.assertEqual(self.release.html_url, "https://github.com/edhollandAL/PyGithub/releases/tag/v1.25.2")
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
https
|
||||
POST
|
||||
api.github.com
|
||||
None
|
||||
/repos/jacquev6/PyGithub/releases
|
||||
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
|
||||
{"body": "This release is created by PyGithub", "prerelease": false, "tag_name": "vX.Y.Z-by-PyGithub-acctest", "draft": false, "name": "vX.Y.Z: PyGithub acctest"}
|
||||
201
|
||||
[('content-length', '1656'), ('x-runtime-rack', '0.601694'), ('vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding'), ('x-xss-protection', '1; mode=block'), ('x-content-type-options', 'nosniff'), ('etag', '"64c4aea05900ae1072ee705caf9b529c"'), ('location', 'https://api.github.com/repos/jacquev6/PyGithub/releases/7636454'), ('cache-control', 'private, max-age=60, s-maxage=60'), ('status', '201 Created'), ('x-ratelimit-remaining', '4951'), ('x-github-media-type', 'github.v3; format=json'), ('access-control-expose-headers', 'ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval'), ('x-github-request-id', '92E2:1D39A:50FE29C:5DF3D65:59AE9019'), ('date', 'Tue, 05 Sep 2017 11:52:58 GMT'), ('access-control-allow-origin', '*'), ('content-security-policy', "default-src 'none'"), ('strict-transport-security', 'max-age=31536000; includeSubdomains; preload'), ('server', 'GitHub.com'), ('x-ratelimit-limit', '5000'), ('x-frame-options', 'deny'), ('content-type', 'application/json; charset=utf-8'), ('x-ratelimit-reset', '1504614271')]
|
||||
{"url":"https://api.github.com/repos/jacquev6/PyGithub/releases/7636454","assets_url":"https://api.github.com/repos/jacquev6/PyGithub/releases/7636454/assets","upload_url":"https://uploads.github.com/repos/jacquev6/PyGithub/releases/7636454/assets{?name,label}","html_url":"https://github.com/jacquev6/PyGithub/releases/tag/vX.Y.Z-by-PyGithub-acctest","id":7636454,"tag_name":"vX.Y.Z-by-PyGithub-acctest","target_commitish":"master","name":"vX.Y.Z: PyGithub acctest","draft":false,"author":{"login":"jacquev6","id":3760893,"avatar_url":"https://avatars2.githubusercontent.com/u/3760893?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"prerelease":false,"created_at":"2016-10-29T02:39:27Z","published_at":"2017-09-05T11:52:58Z","assets":[],"tarball_url":"https://api.github.com/repos/jacquev6/PyGithub/tarball/vX.Y.Z-by-PyGithub-acctest","zipball_url":"https://api.github.com/repos/jacquev6/PyGithub/zipball/vX.Y.Z-by-PyGithub-acctest","body":"This release is created by PyGithub"}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -290,6 +290,35 @@ class Repository(Framework.TestCase):
|
||||
commit = self.repo.create_git_commit("Commit created by PyGithub", tree, [], github.InputGitAuthor("John Doe", "j.doe@vincent-jacques.net", "2008-07-09T16:13:30+12:00"), github.InputGitAuthor("John Doe", "j.doe@vincent-jacques.net", "2008-07-09T16:13:30+12:00"))
|
||||
self.assertEqual(commit.sha, "526946197ae9da59c6507cacd13ad6f1cfb686ea")
|
||||
|
||||
def testCreateGitRelease(self):
|
||||
release = self.repo.create_git_release(
|
||||
"vX.Y.Z-by-PyGithub-acctest",
|
||||
"vX.Y.Z: PyGithub acctest",
|
||||
"This release is created by PyGithub",
|
||||
)
|
||||
self.assertEqual(release.tag_name, "vX.Y.Z-by-PyGithub-acctest")
|
||||
self.assertEqual(release.title, "vX.Y.Z: PyGithub acctest")
|
||||
self.assertEqual(release.body, "This release is created by PyGithub")
|
||||
self.assertEqual(release.draft, False)
|
||||
self.assertEqual(release.prerelease, False)
|
||||
|
||||
def testCreateGitReleaseWithAllArguments(self):
|
||||
release = self.repo.create_git_release(
|
||||
"vX.Y.Z-by-PyGithub-acctest2",
|
||||
"vX.Y.Z: PyGithub acctest2",
|
||||
"This release is also created by PyGithub",
|
||||
False,
|
||||
True,
|
||||
"da9a285fd8b782461e56cba39ae8d2fa41ca7cdc",
|
||||
)
|
||||
self.assertEqual(release.tag_name, "vX.Y.Z-by-PyGithub-acctest2")
|
||||
self.assertEqual(release.title, "vX.Y.Z: PyGithub acctest2")
|
||||
self.assertEqual(release.body, "This release is also created by PyGithub")
|
||||
self.assertEqual(release.draft, False)
|
||||
self.assertEqual(release.prerelease, True)
|
||||
tag = [tag for tag in self.repo.get_tags() if tag.name == "vX.Y.Z-by-PyGithub-acctest2"].pop()
|
||||
self.assertEqual(tag.commit.sha, "da9a285fd8b782461e56cba39ae8d2fa41ca7cdc")
|
||||
|
||||
def testCreateGitTag(self):
|
||||
tag = self.repo.create_git_tag("TaggedByPyGithub", "Tag created by PyGithub", "0b820628236ab8bab3890860fc414fa757ca15f4", "commit")
|
||||
self.assertEqual(tag.sha, "5ba561eaa2b7ca9015662510157b15d8f3b0232a")
|
||||
|
||||
Reference in New Issue
Block a user