Skip to content

Commit c8d0ea6

Browse files
Merge pull request #350 from tillahoffmann/requirements-error
Improve error message for missing requirements (cf. #319).
2 parents 1fe10bd + 1f88d34 commit c8d0ea6

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

get_requirements.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ def __main__() -> None:
2323
elif (path := pathlib.Path(".github-token")).is_file():
2424
token = path.read_text().strip()
2525
else:
26-
token = input("we need a GitHub access token to fetch the requirements; please visit "
26+
token = input("We need a GitHub access token to fetch the requirements. Please visit "
2727
"https://github.com/settings/tokens/new, create a token with `public_repo` "
2828
"scope, and paste it here: ").strip()
29-
cache = input("do you want to cache the token in a `.github-token` file [Ny]? ")
29+
cache = input("Do you want to cache the token in a `.github-token` file [Ny]? ")
3030
if cache.lower().startswith("y"):
3131
path.write_text(token)
3232

@@ -38,13 +38,13 @@ def __main__() -> None:
3838
if args.run: # Run id was specified.
3939
run = args.run
4040
elif args.pr: # PR was specified, let's get the most recent run id.
41-
print(f"fetching most recent commit for PR #{args.pr}")
41+
print(f"Fetching most recent commit for PR #{args.pr}.")
4242
response = requests.get(f"{base_url}/pulls/{args.pr}", headers=headers)
4343
response.raise_for_status()
4444
response = response.json()
4545
head_sha = response["head"]["sha"]
4646
else: # Nothing was specified, let's get the most recent run id on the main branch.
47-
print(f"fetching most recent commit for branch `{args.branch}`")
47+
print(f"Fetching most recent commit for branch `{args.branch}`.")
4848
response = requests.get(f"{base_url}/branches/{args.branch}", headers=headers)
4949
response.raise_for_status()
5050
response = response.json()
@@ -61,8 +61,12 @@ def __main__() -> None:
6161
# Get the requirements run.
6262
runs = [run for run in response["workflow_runs"] if
6363
run["path"].endswith("requirements.yml")]
64+
if not runs:
65+
raise RuntimeError("Could not find a workflow. Has the GitHub Action run completed? If you"
66+
"are a first-time contributor, a contributor has to approve your changes"
67+
"before Actions can run.")
6468
if len(runs) != 1:
65-
raise RuntimeError(f"could not identify unique workflow run: {runs}")
69+
raise RuntimeError(f"Could not identify unique workflow run: {runs}")
6670
run = runs[0]["id"]
6771

6872
# Get all the artifacts.
@@ -72,13 +76,13 @@ def __main__() -> None:
7276
response.raise_for_status()
7377
response = response.json()
7478
artifacts = response["artifacts"]
75-
print(f"discovered {len(artifacts)} artifacts")
79+
print(f"Discovered {len(artifacts)} artifacts.")
7680

7781
# Get the content for each artifact and save it.
7882
for artifact in artifacts:
7983
name: str = artifact["name"]
8084
name = name.removeprefix("requirements-")
81-
print(f"fetching artifact {name} ...")
85+
print(f"Fetching artifact {name} ...")
8286
response = requests.get(artifact["archive_download_url"], headers=headers)
8387
response.raise_for_status()
8488
with zipfile.ZipFile(io.BytesIO(response.content)) as zip, \
@@ -87,7 +91,7 @@ def __main__() -> None:
8791
shutil.move(pathlib.Path(tempdir) / "requirements.txt",
8892
pathlib.Path("requirements") / name)
8993

90-
print("done")
94+
print("Done.")
9195

9296

9397
if __name__ == "__main__":

0 commit comments

Comments
 (0)