-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Changelog: Add missing links #4256
Changes from 3 commits
192bea8
f7af580
bac92d5
a1428a2
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env python3 | ||
import argparse | ||
import re | ||
|
||
|
||
def add_missing_links(changelog): | ||
"""Ensure that all the changelog conforms to our common format.""" | ||
# Ensure that all launchpad issues are hyperlinks | ||
changelog = re.sub( | ||
r"(?!\[)\blp:?(?P<lpid>\d+)\b(?!\])", | ||
r"[lp:\g<lpid>](https://bugs.launchpad.net/mixxx/+bug/\g<lpid>)", | ||
changelog, | ||
) | ||
|
||
# Ensure that all GitHub PRs are hyperlinks | ||
changelog = re.sub( | ||
r"(?!\[)#\b(?P<ghid>\d+)\b(?!\])", | ||
r"[#\g<ghid>](https://github.com/mixxxdj/mixxx/pull/\g<ghid>)", | ||
changelog, | ||
) | ||
|
||
return changelog | ||
|
||
|
||
def main(argv=None): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("file", type=argparse.FileType("r+")) | ||
args = parser.parse_args(argv) | ||
|
||
# Fetch changelog and convert to RST | ||
changelog = args.file.read() | ||
fixed_changelog = add_missing_links(changelog) | ||
if changelog != fixed_changelog: | ||
args.file.seek(0) | ||
args.file.write(fixed_changelog) | ||
args.file.truncate() | ||
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. will this cause issues when the changelog is being read from stdin? We should handle this case and just print to stdout in that case. 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. Good point, I replaced 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. I guess working around a bug by just removing the feature is a solution... |
||
args.file.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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.
Why do we open the file with
r+
but then be able to write to it here? Seems like it could cause undefined behavior?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.
The python docs confuse me here...
https://docs.python.org/3/library/functions.html#open
The default mode is 'r' (open for reading text, synonym of 'rt'). Modes 'w+' and 'w+b' open and truncate the file. Modes 'r+' and 'r+b' open the file with no truncation.
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.
Clarified the situation by just opening the file separately for reading and writing.
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.
That wouldn't have been necessary, but its much clearer now anways. Thanks