-
-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep more of GitHub release notes body #327
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,11 @@ def verify_build(is_test: str) -> None: | |
|
||
|
||
def generate_github_release_notes_body(token: str, version: str) -> str: | ||
"""Generate and grab release notes URL from Github.""" | ||
"""Generate and grab release notes URL from Github. | ||
|
||
Delete their first paragraph, because we track its contents in a tighter | ||
form in CHANGELOG.md. See `get_changelog_release_notes`. | ||
""" | ||
response = requests.post( | ||
"https://api.github.com/repos/john-kurkowski/tldextract/releases/generate-notes", | ||
headers={ | ||
|
@@ -100,24 +104,13 @@ def generate_github_release_notes_body(token: str, version: str) -> str: | |
file=sys.stderr, | ||
) | ||
return "" | ||
return str(response.json()["body"]) | ||
|
||
|
||
def get_release_notes_url(body: str) -> str: | ||
"""Parse the release notes content to get the changelog URL.""" | ||
url_pattern = re.compile(r"\*\*Full Changelog\*\*: (.*)$") | ||
match = url_pattern.search(body) | ||
if match: | ||
return match.group(1) | ||
else: | ||
print( | ||
"WARNING: Failed to parse release notes URL from GitHub response.", | ||
file=sys.stderr, | ||
) | ||
return "" | ||
body = str(response.json()["body"]) | ||
paragraphs = body.split("\n\n") | ||
return "\n\n".join(paragraphs[1:]) | ||
|
||
|
||
def get_changelog_release_notes(release_notes_url: str, version: str) -> str: | ||
def get_changelog_release_notes(version: str) -> str: | ||
"""Get the changelog release notes. | ||
|
||
Uses a regex starting on a heading beginning with the version number | ||
|
@@ -131,25 +124,15 @@ def get_changelog_release_notes(release_notes_url: str, version: str) -> str: | |
if match: | ||
return str(match.group(1)).strip() | ||
else: | ||
print( | ||
f"WARNING: Failed to parse changelog release notes. Manually copy this version's notes from the CHANGELOG.md file to {release_notes_url}.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haven't tripped on this error handler yet, but I think the URL in it was wrong. It's a compare link like 5.1.1...5.1.2, not a create-release link. I moved this error print to after we have the release link. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, good point. I think I garbled this warning when I added the |
||
file=sys.stderr, | ||
) | ||
return "" | ||
|
||
|
||
def create_release_notes_body(token: str, version: str) -> str: | ||
"""Compile the release notes.""" | ||
github_release_body = generate_github_release_notes_body(token, version) | ||
release_notes_url = get_release_notes_url(github_release_body) | ||
changelog_notes = get_changelog_release_notes(release_notes_url, version) | ||
full_release_notes = f"{changelog_notes}\n\n**Full Changelog**: {release_notes_url}" | ||
return full_release_notes | ||
|
||
|
||
def create_github_release_draft(token: str, version: str) -> None: | ||
"""Create a release on GitHub.""" | ||
release_body = create_release_notes_body(token, version) | ||
github_release_body = generate_github_release_notes_body(token, version) | ||
changelog_notes = get_changelog_release_notes(version) | ||
release_body = f"{changelog_notes}\n\n{github_release_body}" | ||
|
||
response = requests.post( | ||
"https://api.github.com/repos/john-kurkowski/tldextract/releases", | ||
headers={ | ||
|
@@ -174,8 +157,15 @@ def create_github_release_draft(token: str, version: str) -> None: | |
file=sys.stderr, | ||
) | ||
return | ||
|
||
print(f'Release created successfully: {response.json()["html_url"]}') | ||
|
||
if not changelog_notes: | ||
print( | ||
"WARNING: Failed to parse changelog release notes. Manually copy this version's notes from the CHANGELOG.md file to the above URL.", | ||
file=sys.stderr, | ||
) | ||
|
||
|
||
def upload_build_to_pypi(is_test: str) -> None: | ||
"""Upload the build to PyPI.""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So concise and it got rid of the REGEX-- love it. Still a little brittle if this format changes, but I think this is a great improvement.