Skip to content

Commit

Permalink
Add flag to get the latest release from a specified major version (#12)
Browse files Browse the repository at this point in the history
The `--tag` flag fetches the exact specified RepoSense version, but provides no way to fetch the latest release of a specified major version.

Let's introduce the  `--latest` or `-l` flag to get the latest release from a specified major version.
  • Loading branch information
jedkohjk authored Aug 1, 2024
1 parent 75d21e3 commit 8018580
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
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
major = tag.strip('. ').split('.')
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.strip('. ').split('.')[:len(major)] == major:
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

0 comments on commit 8018580

Please sign in to comment.