Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test labelling enforcement #5

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
Experiment with preventing issue closure
  • Loading branch information
jhiemstrawisc committed Nov 27, 2024
commit 7275c6f58bf688796c77c13be936d79474a6867a
34 changes: 33 additions & 1 deletion .github/workflows/enforce-labelling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
# one limitation here is that there's no trigger to re-run any time we "connect" or "disconnect" an issue
types: [opened, edited, labeled, unlabeled, synchronize]
issues:
types: [opened, edited, labeled, unlabeled]
types: [opened, edited, labeled, unlabeled, closed]

jobs:
validate-pr:
Expand All @@ -32,6 +32,7 @@ jobs:
TIMELINE_JSON=$(curl -s "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/issues/$PR_NUMBER/timeline")

# Count the number of times the timeline sees a "connected" event and subract the number of "disconnected" events
# We might also consider using the "cross-referenced" event in the future if actual connecting/disconnecting is too heavy-handed
LINKED_ISSUES=$(echo "$TIMELINE_JSON" | jq '
reduce .[] as $event (
0;
Expand All @@ -57,6 +58,7 @@ jobs:

validate-issue:
runs-on: ubuntu-latest
if: github.event.action == 'closed'
steps:
- name: Check out the repository
uses: actions/checkout@v2
Expand All @@ -69,3 +71,33 @@ jobs:
echo "No labels found on the issue."
exit 1
fi

- name: Validate issue is linked to a PR
id: check_linked_prs
run: |
ISSUE_NUMBER=$(jq -r '.issue.number' $GITHUB_EVENT_PATH)
REPO_OWNER=$(jq -r '.repository.owner.login' $GITHUB_EVENT_PATH)
REPO_NAME=$(jq -r '.repository.name' $GITHUB_EVENT_PATH)
TIMELINE_JSON=$(curl -s "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/issues/$ISSUE_NUMBER/timeline")

LINKED_PRS=$(echo "$TIMELINE_JSON" | jq '
reduce .[] as $event (
0;
if $event.event == "connected" then
. + 1
elif $event.event == "disconnected" then
. - 1
else
.
end
)')

if [ "$LINKED_PRS" -eq "0" ]; then
echo "❌ No linked pull requests found in the issue."
exit 1
elif [ "$LINKED_PRS" -lt "0" ]; then
echo "Error: More disconnected events than connected events. This shouldn't be possible and likely indicates a big ol' 🪲"
exit 1
else
echo "Linked PRs found: $LINKED_PRS"
fi
Loading