Skip to content
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

Add flag to get the latest release from a specified major version #12

Merged
merged 4 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions get-reposense.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,32 @@ def parse_args():
group.add_argument('-r', '--release', action='store_true', help='Get RepoSense.jar from the latest release (Stable)')
group.add_argument('-m', '--master', action='store_true', help='Get RepoSense.jar from the latest master (Beta)')
group.add_argument('-t', '--tag', help='Get RepoSense.jar of a specific release version tag')
group.add_argument('-l', '--latest', help='Get RepoSense.jar of the latest release of a specific version tag')
group.add_argument('-c', '--commit', help='Get RepoSense.jar of a specific commit')

parser.add_argument('-o', '--overwrite', action='store_true', help='Overwrite RepoSense.jar file, if exists. Default: false')

return parser.parse_args()

def handle_latest_tag(tag):
page = 1
while True:
response = requests.get(f'https://api.github.com/repos/reposense/RepoSense/releases?per_page=100&page={page}')
if response.status_code in [403, 500]:
print('GitHub API has exceed the rate limit.')
exit(1)
releases = response.json()
if not releases:
print('Error, the provided tag does not exist!')
exit(1)
for i in releases:
release_tag = i['tag_name']
if release_tag[:len(tag)] == tag and \
not (release_tag[len(tag):len(tag)+1].isdigit() and tag[-1].isdigit()):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: some tags look like v1.9rc which could match with v1.9 depending on the order of releases but are not technically official releases - in general, release versions could include non-numeric characters.

Maybe we can split by . and compare each section (or something else that makes sense)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the review, I've updated it accordingly

handle_specific_release(release_tag)
exit()
page += 1

def handle_specific_commit(commit):
get_reposense_jar('https://api.github.com/repos/reposense/RepoSense/commits/' + commit, commit=commit)

Expand Down Expand Up @@ -92,6 +112,10 @@ def download_file(url):
if args.tag:
handle_specific_release(args.tag)
exit()

if args.latest:
handle_latest_tag(args.latest)
exit()

if args.commit:
handle_specific_commit(args.commit)
Expand Down
1 change: 1 addition & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### ./get-reposense.py --release # Gets the latest release (Stable)
### ./get-reposense.py --master # Gets the latest master (Beta)
### ./get-reposense.py --tag v1.6.1 # Gets a specific version
### ./get-reposense.py --latest v1.6 # Gets the latest version of a specific tag
### ./get-reposense.py --commit abc123 # Gets a specific commit
### ./get-reposense.py --release --overwrite # Overwrite RepoSense.jar, if exists, with the latest release

Expand Down