Skip to content

Commit db04ee4

Browse files
authored
feat: add assignment guard for advanced issues (#1142) (#1209)
Signed-off-by: Akshat Kumar <[email protected]> Signed-off-by: Akshat8510 <[email protected]>
1 parent 3fa6ef8 commit db04ee4

File tree

3 files changed

+132
-1
lines changed

3 files changed

+132
-1
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# 1. Define Helper Functions First
5+
log() {
6+
echo "[advanced-check] $1"
7+
}
8+
9+
# 2. Validate required environment variables
10+
if [[ -z "${REPO:-}" ]] || [[ -z "${ISSUE_NUMBER:-}" ]] || [[ -z "${GH_TOKEN:-}" ]]; then
11+
log "ERROR: Required environment variables (REPO, ISSUE_NUMBER, GH_TOKEN) must be set"
12+
exit 1
13+
fi
14+
15+
# 3. Function to check a single user
16+
check_user() {
17+
local user=$1
18+
log "Checking qualification for @$user..."
19+
20+
# Permission exemption
21+
PERM_JSON=$(gh api "repos/$REPO/collaborators/$user/permission" 2>/dev/null || echo '{"permission":"none"}')
22+
PERMISSION=$(echo "$PERM_JSON" | jq -r '.permission // "none"')
23+
24+
if [[ "$PERMISSION" =~ ^(admin|write|triage)$ ]]; then
25+
log "User @$user is core member ($PERMISSION). Qualification check skipped."
26+
return 0
27+
fi
28+
29+
# 2. Get counts
30+
# Using exact repository label names ("Good First Issue" and "intermediate")
31+
GFI_QUERY="repo:$REPO is:issue is:closed assignee:$user -reason:\"not planned\" label:\"Good First Issue\""
32+
INT_QUERY="repo:$REPO is:issue is:closed assignee:$user -reason:\"not planned\" label:\"intermediate\""
33+
34+
GFI_COUNT=$(gh api "search/issues" -f q="$GFI_QUERY" --jq '.total_count' || echo "0")
35+
INT_COUNT=$(gh api "search/issues" -f q="$INT_QUERY" --jq '.total_count' || echo "0")
36+
37+
# Numeric validation
38+
if ! [[ "$GFI_COUNT" =~ ^[0-9]+$ ]]; then GFI_COUNT=0; fi
39+
if ! [[ "$INT_COUNT" =~ ^[0-9]+$ ]]; then INT_COUNT=0; fi
40+
41+
# Validation Logic
42+
if (( GFI_COUNT >= 1 )) && (( INT_COUNT >= 1 )); then
43+
log "User @$user qualified."
44+
return 0
45+
else
46+
log "User @$user failed. Unassigning..."
47+
48+
# Tailor the suggestion based on what is missing
49+
# Links and names now match exact repository labels
50+
if (( GFI_COUNT == 0 )); then
51+
SUGGESTION="[Good First Issue](https://github.com/$REPO/labels/Good%20First%20Issue)"
52+
else
53+
SUGGESTION="[intermediate issue](https://github.com/$REPO/labels/intermediate)"
54+
fi
55+
56+
# Post the message FIRST, then unassign.
57+
MSG="Hi @$user, I cannot assign you to this issue yet.
58+
59+
**Why?**
60+
Advanced issues involve high-risk changes to the core codebase. They require significant testing and can impact automation and CI behavior.
61+
62+
**Requirement:**
63+
- Complete at least **1** 'Good First Issue' (You have: **$GFI_COUNT**)
64+
- Complete at least **1** 'intermediate' issue (You have: **$INT_COUNT**)
65+
66+
Please check out our **$SUGGESTION** tasks to build your experience first!"
67+
68+
gh issue comment "$ISSUE_NUMBER" --repo "$REPO" --body "$MSG"
69+
gh issue edit "$ISSUE_NUMBER" --repo "$REPO" --remove-assignee "$user"
70+
fi
71+
}
72+
73+
# --- Main Logic ---
74+
75+
if [[ -n "${TRIGGER_ASSIGNEE:-}" ]]; then
76+
check_user "$TRIGGER_ASSIGNEE"
77+
else
78+
log "Checking all current assignees..."
79+
80+
# Fetch assignees into a variable first.
81+
ASSIGNEE_LIST=$(gh issue view "$ISSUE_NUMBER" --repo "$REPO" --json assignees --jq '.assignees[].login')
82+
83+
if [[ -z "$ASSIGNEE_LIST" ]]; then
84+
log "No assignees found to check."
85+
else
86+
# Use a here-string (<<<) to iterate over the variable safely.
87+
while read -r user; do
88+
if [[ -n "$user" ]]; then
89+
check_user "$user"
90+
fi
91+
done <<< "$ASSIGNEE_LIST"
92+
fi
93+
fi
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: PythonBot - Advanced Requirement Check
2+
3+
on:
4+
issues:
5+
types: [assigned, labeled]
6+
7+
permissions:
8+
issues: write
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.event.issue.number }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
check-advanced-qualification:
16+
# Run only for issues labeled 'advanced', triggered by assignment or by adding
17+
# the label to an issue that already has assignees
18+
if: >
19+
contains(github.event.issue.labels.*.name, 'advanced') &&
20+
(github.event.action == 'assigned' || (github.event.action == 'labeled' && github.event.issue.assignees[0] != null))
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout scripts
24+
# Pinned to v6.0.1 (8e8c483db84b4bee98b60c0593521ed34d9990e8)
25+
# Followed guide: https://github.com/actions/checkout/releases
26+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
27+
with:
28+
sparse-checkout: .github/scripts
29+
30+
- name: Verify User Qualification
31+
env:
32+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
TRIGGER_ASSIGNEE: ${{ github.event.assignee.login || '' }}
34+
ISSUE_NUMBER: ${{ github.event.issue.number }}
35+
REPO: ${{ github.repository }}
36+
run: |
37+
chmod +x .github/scripts/check_advanced_requirement.sh
38+
./.github/scripts/check_advanced_requirement.sh

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
77
## [Unreleased]
88

99
### Added
10-
10+
- Automated assignment guard for `advanced` issues; requires completion of at least one `good first issue` and one `intermediate` issue before assignment (exempts maintainers, committers, and triage members). (#1142)
1111
- Added Hbar object support for TransferTransaction HBAR transfers:
1212
- Methods now accept `Union[int, Hbar]` for amount parameters with immediate normalization to tinybars
1313
- Includes comprehensive unit tests covering various Hbar units (HBAR, MICROBAR, NANOBAR, TINYBAR) and accumulation behavior with mixed `int` and `Hbar` inputs

0 commit comments

Comments
 (0)