Skip to content

Commit a91df3a

Browse files
committed
bot: update
Signed-off-by: Akshat Kumar <akshat230405@gmail.com>
1 parent 4e38110 commit a91df3a

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

.github/scripts/check_advanced_requirement.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ if [[ "$PERMISSION" =~ ^(admin|write|triage)$ ]]; then
1212
fi
1313

1414
# 2. Get counts of completed issues
15-
# Use -f q= to handle URL encoding for labels with spaces automatically
15+
# Use -f q= for native URL encoding
1616
GFI_QUERY="repo:$REPO is:issue is:closed assignee:$ASSIGNEE -reason:\"not planned\" label:\"good first issue\""
1717
INT_QUERY="repo:$REPO is:issue is:closed assignee:$ASSIGNEE -reason:\"not planned\" label:\"intermediate\""
1818

19-
GFI_COUNT=$(gh api "search/issues" -f q="$GFI_QUERY" --jq '.total_count')
20-
INT_COUNT=$(gh api "search/issues" -f q="$INT_QUERY" --jq '.total_count')
19+
GFI_COUNT=$(gh api "search/issues" -f q="$GFI_QUERY" --jq '.total_count' || echo "0")
20+
INT_COUNT=$(gh api "search/issues" -f q="$INT_QUERY" --jq '.total_count' || echo "0")
2121

22-
# Ensure counts are numeric (default to 0)
23-
GFI_COUNT=${GFI_COUNT:-0}
24-
INT_COUNT=${INT_COUNT:-0}
22+
# Robust numeric validation
23+
if ! [[ "$GFI_COUNT" =~ ^[0-9]+$ ]]; then GFI_COUNT=0; fi
24+
if ! [[ "$INT_COUNT" =~ ^[0-9]+$ ]]; then INT_COUNT=0; fi
2525

2626
echo "Stats for @$ASSIGNEE: GFI: $GFI_COUNT, Intermediate: $INT_COUNT"
2727

@@ -35,7 +35,7 @@ else
3535
# Quote variables to prevent word-splitting
3636
gh issue edit "$ISSUE_NUMBER" --repo "$REPO" --remove-assignee "$ASSIGNEE"
3737

38-
# 4. Message
38+
# 4. Message Construction
3939
MSG="Hi @$ASSIGNEE, I cannot assign you to this issue yet.
4040
4141
**Why?**
@@ -45,9 +45,9 @@ Advanced issues involve high-risk changes to the core codebase. They require sig
4545
- Complete at least **1** 'good first issue' (You have: **$GFI_COUNT**)
4646
- Complete at least **1** 'intermediate' issue (You have: **$INT_COUNT**)
4747
48-
Please feel free to pick up an [intermediate issue](https://github.com/hiero-ledger/hiero-sdk-python/labels/intermediate) to get started! We look forward to your contributions."
48+
Please feel free to pick up an [intermediate issue](https://github.com/$REPO/labels/intermediate) to get started! We look forward to your contributions."
4949

50-
# Use the variable safely without printf format vulnerabilities
50+
# Post the comment safely without printf formatting risks
5151
gh issue comment "$ISSUE_NUMBER" --repo "$REPO" --body "$MSG"
5252

5353
exit 1

.github/workflows/bot-advanced-check.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ name: PythonBot - Advanced Requirement Check
22

33
on:
44
issues:
5-
types: [assigned]
5+
types: [assigned, labeled] # Added 'labeled' to catch label changes after assignment
66

77
# Explicitly minimal permissions
88
permissions:
99
issues: write
1010

11+
# Prevent duplicate runners/comments on the same issue
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.event.issue.number }}
14+
cancel-in-progress: true
15+
1116
jobs:
1217
check-advanced-qualification:
13-
# Most efficient: Skip the runner entirely if the issue isn't 'advanced'
18+
# Skip the runner entirely if the issue isn't 'advanced'
1419
if: contains(github.event.issue.labels.*.name, 'advanced')
1520
runs-on: ubuntu-latest
1621
steps:
@@ -22,9 +27,16 @@ jobs:
2227
- name: Verify User Qualification
2328
env:
2429
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25-
ASSIGNEE: ${{ github.event.assignee.login }}
30+
# Handle cases where triggered by assignment or by adding a label to an assigned issue
31+
ASSIGNEE: ${{ github.event.assignee.login || github.event.issue.assignee.login }}
2632
ISSUE_NUMBER: ${{ github.event.issue.number }}
2733
REPO: ${{ github.repository }}
2834
run: |
35+
# If no one is assigned, exit early
36+
if [ -z "$ASSIGNEE" ]; then
37+
echo "No assignee to check. Skipping."
38+
exit 0
39+
fi
40+
2941
chmod +x .github/scripts/check_advanced_requirement.sh
3042
./.github/scripts/check_advanced_requirement.sh

0 commit comments

Comments
 (0)