TobKed commented on a change in pull request #12150:
URL: https://github.com/apache/beam/pull/12150#discussion_r457933802



##########
File path: release/src/main/scripts/download_github_actions_artifacts.py
##########
@@ -51,26 +55,56 @@ def parse_arguments():
 
   args = parser.parse_args()
 
-  global GITHUB_TOKEN, USER_GITHUB_ID, REPO_URL, RELEASE_BRANCH, 
RELEASE_COMMIT, ARTIFACTS_DIR
-  GITHUB_TOKEN = args.github_token
-  USER_GITHUB_ID = args.github_user
-  REPO_URL = args.repo_url
-  RELEASE_BRANCH = args.release_branch
-  RELEASE_COMMIT = args.release_commit
-  ARTIFACTS_DIR = args.artifacts_dir
+  github_token = ask_for_github_token()
+  print("You passed following arguments:")
+  pprint.pprint({**vars(args), **{"github_token": github_token}})
+  if not get_yes_or_no_answer("Do you want to continue?"):
+    print("You said NO. Quitting ...")
+    sys.exit(1)
+
+  user_github_id = args.github_user
+  repo_url = args.repo_url
+  release_branch = args.release_branch
+  release_commit = args.release_commit
+  artifacts_dir = args.artifacts_dir
+
+  return github_token, user_github_id, repo_url, release_branch, 
release_commit, artifacts_dir
+
 
+def ask_for_github_token():
+  """Ask for github token and print basic information about it"""
+  url = 
"https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token";
+  message = (
+      f"You need to have a github access token with public_repo scope. "
+      f"More info about creating access tokens can be found here {url}")
+  print(message)
+  github_token = input("Enter github token: ")
+  if not github_token:
+    return ask_for_github_token()
+  return github_token
 
-def request_url(url, return_json=True, *args, **kwargs):
+
+def request_url(url, github_token, return_json=True, *args, **kwargs):
   """Helper function form making requests authorized by GitHub token"""
-  r = requests.get(url, *args, auth=("token", GITHUB_TOKEN), **kwargs)
+  r = requests.get(url, *args, auth=("token", github_token), **kwargs)
   if return_json:
     r.raise_for_status()
     return r.json()
   return r
 
 
+def safe_get(data, key, url=None):
+  """Gets data by the key with informative Exception in case of non existent 
key."""

Review comment:
       I like your suggestion. Thank you. I will apply it.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to