Skip to content

Commit

Permalink
Further fix to check_newsfragments script
Browse files Browse the repository at this point in the history
- Improve logging of newsfragment (display the `git log` command that
  will be executed).
- Prefix `base` argument with `origin/`.
- Use repeat on base argument to prevent iterating over each char of the
  string.
- Allow closed issue/PR.
- Fetch `base_ref` before executing the script.

Co-authored-by: Marcos Medrano <[email protected]>
  • Loading branch information
FirelightFlagboy and mmmarcos committed Nov 16, 2023
1 parent dd114cd commit 664acb6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 15 additions & 13 deletions .github/scripts/check_newsfragments.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS

# cspell:words oneline

"""
PRs must contain a newsfragment that reference an opened issue
"""

import argparse
import json
from concurrent.futures import ThreadPoolExecutor
from itertools import repeat
from pathlib import Path
from subprocess import run
from typing import Optional
Expand All @@ -18,11 +21,13 @@

def check_newsfragment(fragment: Path, base: str) -> Optional[bool]:
fragment_name = fragment.name

# If file never existed in `base`, consider as a new newsfragment
# Cannot just git diff against `base` branch here given newsfragments
# removed in master will be considered as new items in our branch
# --exit-code makes the command exit with 0 if there are changes
cmd_args = ["git", "log", base, "--exit-code", "--", str(fragment)]
cmd_args = ["git", "log", base, "--exit-code", "--oneline", "--", str(fragment)]
print(f"[{fragment_name}] Checking news fragment on base {base} with `{' '.join(cmd_args)}`")
ret = run(cmd_args, capture_output=True)

if ret.returncode == 0:
Expand All @@ -48,21 +53,14 @@ def check_newsfragment(fragment: Path, base: str) -> Optional[bool]:
response = urlopen(req)
except HTTPError as exc:
print(
f"[{fragment_name}] fragment ID doesn't correspond to an issue ! (On <{url}> HTTP error {exc.code} {exc.reason})"
f"[{fragment_name}] fragment ID doesn't correspond to an issue! (On <{url}> HTTP error {exc.code} {exc.reason})"
)
return False
else:
# Sanity check: try to deserialize the response.
data = json.loads(response.read())
print(f"[{fragment_name}] issue#{id} => {data}")
if "pull_request" in data:
print(
f"[{fragment_name}] fragment ID correspond to a pull request instead of an issue !"
)
else:
if data["state"] == "open":
return True
else:
print(f"[{fragment_name}] fragment ID correspond to a closed issue !")
return False
return True
else:
return None

Expand All @@ -78,7 +76,11 @@ def check_newsfragment(fragment: Path, base: str) -> Optional[bool]:
ret = list(
filter(
lambda value: value is not None,
pool.map(check_newsfragment, Path("newsfragments").glob("*.rst"), args.base),
pool.map(
check_newsfragment,
Path("newsfragments").glob("*.rst"),
repeat("origin/" + args.base),
),
)
)

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ jobs:
&& steps.newsfragment-have-changed.outputs.newsfragments == 'true'
run: |
whereis git
git fetch origin master
git fetch origin ${{ github.base_ref }}
python .github/scripts/check_newsfragments.py --base=${{ github.base_ref }}
timeout-minutes: 5

Expand Down

0 comments on commit 664acb6

Please sign in to comment.