Skip to content

Commit

Permalink
Create release with optional name and message when generate_release_n…
Browse files Browse the repository at this point in the history
…otes is true (#2868)

Co-authored-by: Enrico Minack <github@enrico.minack.dev>
  • Loading branch information
heitorpolidoro and EnricoMi committed Mar 21, 2024
1 parent 0784f83 commit d65fc30
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
21 changes: 12 additions & 9 deletions github/Repository.py
Expand Up @@ -1216,12 +1216,13 @@ def create_git_ref(self, ref: str, sha: str) -> GitRef:
headers, data = self._requester.requestJsonAndCheck("POST", f"{self.url}/git/refs", input=post_parameters)
return github.GitRef.GitRef(self._requester, headers, data, completed=True)

# TODO: v3: reorder arguments and add default value `NotSet` where `Opt[str]`
def create_git_tag_and_release(
self,
tag: str,
tag_message: str,
release_name: str,
release_message: str,
release_name: Opt[str],
release_message: Opt[str],
object: str,
type: str,
tagger: Opt[InputGitAuthor] = NotSet,
Expand Down Expand Up @@ -1259,8 +1260,8 @@ def create_git_tag_and_release(
def create_git_release(
self,
tag: str,
name: str,
message: str,
name: Opt[str] = NotSet,
message: Opt[str] = NotSet,
draft: bool = False,
prerelease: bool = False,
generate_release_notes: bool = False,
Expand All @@ -1278,23 +1279,25 @@ def create_git_release(
:rtype: :class:`github.GitRelease.GitRelease`
"""
assert isinstance(tag, str), tag
assert isinstance(name, str), name
assert isinstance(message, str), message
assert isinstance(generate_release_notes, bool), generate_release_notes
assert isinstance(name, str) or generate_release_notes and is_optional(name, str), name
assert isinstance(message, str) or generate_release_notes and is_optional(message, str), message
assert isinstance(draft, bool), draft
assert isinstance(prerelease, bool), prerelease
assert isinstance(generate_release_notes, bool), generate_release_notes
assert is_optional(
target_commitish,
(str, github.Branch.Branch, github.Commit.Commit, github.GitCommit.GitCommit),
), target_commitish
post_parameters = {
"tag_name": tag,
"name": name,
"body": message,
"draft": draft,
"prerelease": prerelease,
"generate_release_notes": generate_release_notes,
}
if is_defined(name):
post_parameters["name"] = name
if is_defined(message):
post_parameters["body"] = message
if isinstance(target_commitish, str):
post_parameters["target_commitish"] = target_commitish
elif isinstance(target_commitish, github.Branch.Branch):
Expand Down
@@ -0,0 +1,10 @@
https
POST
api.github.com
None
/repos/jacquev6/PyGithub/releases
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
{"prerelease": false, "generate_release_notes": true, "tag_name": "vX.Y.Z-by-PyGithub-acctest-release-notes", "draft": false}
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-release-notes","id":7636454,"tag_name":"vX.Y.Z-by-PyGithub-acctest-release-notes","target_commitish":"master","name":"vX.Y.Z: PyGithub acctest-release-notes","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-release-notes","zipball_url":"https://api.github.com/repos/jacquev6/PyGithub/zipball/vX.Y.Z-by-PyGithub-acctest-release-notes","body":"This release is created by PyGithub"}
6 changes: 6 additions & 0 deletions tests/Repository.py
Expand Up @@ -406,6 +406,12 @@ def testCreateGitRelease(self):
self.assertEqual(release.draft, False)
self.assertEqual(release.prerelease, False)

def testCreateGitReleaseGenerateReleaseNotes(self):
release = self.repo.create_git_release("vX.Y.Z-by-PyGithub-acctest-release-notes", generate_release_notes=True)
self.assertEqual(release.tag_name, "vX.Y.Z-by-PyGithub-acctest-release-notes")
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",
Expand Down

0 comments on commit d65fc30

Please sign in to comment.