-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Applying 'PEP 8' style to uploadTag.py
- Loading branch information
Showing
1 changed file
with
24 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,53 @@ | ||
|
||
import sys | ||
import os | ||
import argparse | ||
import github # Importing PyGithub for GitHub API interaction | ||
|
||
import github # PyGithub | ||
|
||
# Set the argument parser | ||
parser = argparse.ArgumentParser('Release Download') | ||
# Initialize the argument parser with a description | ||
parser = argparse.ArgumentParser(description='Download a release from GitHub') | ||
|
||
# Add arguments | ||
# Add arguments for the GitHub repository, tag of the release, and file to upload | ||
parser.add_argument( | ||
"--repo", | ||
type = str, | ||
required = True, | ||
help = "Github Repo" | ||
type=str, | ||
required=True, | ||
help="GitHub repository in the format 'username/repository'" | ||
) | ||
|
||
parser.add_argument( | ||
"--tag", | ||
type = str, | ||
required = True, | ||
help = "Tag to release" | ||
type=str, | ||
required=True, | ||
help="Tag of the release to download" | ||
) | ||
|
||
parser.add_argument( | ||
"--file", | ||
type = str, | ||
required = True, | ||
help = "File to upload" | ||
type=str, | ||
required=True, | ||
help="Path to the file to upload" | ||
) | ||
|
||
# Get the arguments | ||
# Parse the arguments from the command line | ||
args = parser.parse_args() | ||
|
||
print("\nLogging into github....\n") | ||
print("\nLogging into GitHub...\n") | ||
|
||
# Retrieve GitHub token from environment variables | ||
token = os.environ.get('GH_REPO_TOKEN') | ||
|
||
# Exit if the GitHub token is not found | ||
if token is None: | ||
sys.exit("Failed to get github token from GH_REPO_TOKEN environment variable") | ||
sys.exit("Failed to get GitHub token from GH_REPO_TOKEN environment variable") | ||
|
||
# Authenticate with GitHub using the provided token | ||
gh = github.Github(token) | ||
remRepo = gh.get_repo(args.repo) | ||
|
||
# Retrieve the specified repository | ||
try: | ||
|
||
release = remRepo.get_release(args.tag) | ||
repo = gh.get_repo(args.repo) | ||
release = repo.get_release(args.tag) | ||
release.upload_asset(args.file) | ||
|
||
print(f"Successfully uploaded {args.file} to release {args.tag} in repository {args.repo}.") | ||
except Exception as e: | ||
sys.exit(f"Failed to find and upload tag {args.tag}: {e}") | ||
|
||
sys.exit(f"Failed to find the release '{args.tag}' or upload the file '{args.file}': {e}") |