Skip to content

Commit ece8844

Browse files
authored
feat: Add automated assignment limit bot (#960)
Signed-off-by: Adityarya11 <arya050411@gmail.com> Signed-off-by: notsogod <149138960+Adityarya11@users.noreply.github.com>
1 parent 6140d2a commit ece8844

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
if [ -z "$ASSIGNEE" ] || [ -z "$ISSUE_NUMBER" ] || [ -z "$REPO" ]; then
4+
echo "Error: Missing required environment variables (ASSIGNEE, ISSUE_NUMBER, REPO)."
5+
exit 1
6+
fi
7+
8+
echo "Checking assignment rules for user $ASSIGNEE on issue #$ISSUE_NUMBER"
9+
10+
PERM_JSON=$(gh api repos/$REPO/collaborators/$ASSIGNEE/permission)
11+
PERMISSION=$(echo "$PERM_JSON" | jq -r '.permission')
12+
13+
echo "User permission level: $PERMISSION"
14+
15+
if [[ "$PERMISSION" == "admin" ]] || [[ "$PERMISSION" == "write" ]]; then
16+
echo "User is a maintainer or committer. Limit does not apply."
17+
exit 0
18+
fi
19+
20+
ASSIGNMENTS_JSON=$(gh issue list --repo $REPO --assignee "$ASSIGNEE" --state open --json number)
21+
COUNT=$(echo "$ASSIGNMENTS_JSON" | jq '. | length')
22+
23+
echo "Current open assignments count: $COUNT"
24+
25+
if (( COUNT > 2 )); then
26+
echo "Limit exceeded (Max 2 allowed). Revoking assignment."
27+
28+
gh issue edit $ISSUE_NUMBER --repo $REPO --remove-assignee "$ASSIGNEE"
29+
30+
MSG="Hi @$ASSIGNEE, this is the Assignment Bot."
31+
MSG="$MSG\n\nAssigning you to this issue would exceed the limit of 2 open assignments."
32+
MSG="$MSG\n\nPlease resolve and merge your existing assigned issues before requesting new ones."
33+
34+
gh issue comment $ISSUE_NUMBER --repo $REPO --body "$(printf "$MSG")"
35+
36+
exit 1
37+
else
38+
echo "Assignment valid. User has $COUNT assignments."
39+
fi
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: PythonBot - Assignment Limit
2+
3+
on:
4+
issues:
5+
types: [assigned]
6+
7+
permissions:
8+
issues: write
9+
10+
jobs:
11+
check-assignment-limit:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Harden the runner
15+
uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2
16+
with:
17+
egress-policy: audit
18+
19+
- name: Checkout repository
20+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
21+
22+
- name: Check Assignment Count
23+
env:
24+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
ASSIGNEE: ${{ github.event.assignee.login }}
26+
ISSUE_NUMBER: ${{ github.event.issue.number }}
27+
REPO: ${{ github.repository }}
28+
run: |
29+
# Make script executable (just in case permissions were lost during checkout)
30+
chmod +x .github/scripts/check_assignment_limit.sh
31+
32+
# Run the script
33+
./.github/scripts/check_assignment_limit.sh

CHANGELOG.md

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

99
### Added
10+
11+
- Added `.github/workflows/bot-assignment-check.yml` to limit non-maintainers to 2 concurrent issue assignments.
1012
- Add examples/tokens/token_create_transaction_pause_key.py example demonstrating token pause/unpause behavior and pause key usage (#833)
1113
- Added `docs/sdk_developers/training/transaction_lifecycle.md` to explain the typical lifecycle of executing a transaction using the Hedera Python SDK.
1214
- Add inactivity bot workflow to unassign stale issue assignees (#952)
1315
### Changed
14-
-
1516

1617
### Fixed
18+
1719
-
1820

1921
### Breaking Change
22+
2023
-
2124

2225
## [0.1.10] - 2025-12-03
2326

2427
### Added
28+
2529
- Added docs/sdk_developers/training/workflow: a training for developers to learn the workflow to contribute to the python SDK.
2630
- Added Improved NFT allowance deletion flow with receipt-based status checks and strict `SPENDER_DOES_NOT_HAVE_ALLOWANCE` verification.
2731
- Add `max_automatic_token_associations`, `staked_account_id`, `staked_node_id` and `decline_staking_reward` fields to `AccountUpdateTransaction` (#801)
@@ -41,7 +45,6 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
4145
- feat: Add string representation method for `CustomFractionalFee` class and update `custom_fractional_fee.py` example.
4246
- Moved query examples to their respective domain folders to improve structure matching.
4347

44-
4548
### Fixed
4649

4750
- fixed workflow: changelog check with improved sensitivity to deletions, additions, new releases

0 commit comments

Comments
 (0)