Skip to content

Commit 0b0237f

Browse files
committed
Merge branch 'pr970-signed' of https://github.com/cheese-cakee/hiero-sdk-python into pr970-signed
2 parents b1d4de2 + 191a676 commit 0b0237f

File tree

4 files changed

+146
-5
lines changed

4 files changed

+146
-5
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: 2 additions & 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
@@ -111,6 +111,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
111111

112112
### Fixed
113113

114+
- Fixed the README account balance example to use correct SDK APIs and provide a runnable testnet setup. (#1250)
114115
- Fix token association verification in `token_airdrop_transaction.py` to correctly check if tokens are associated by using `token_id in token_balances` instead of incorrectly displaying zero balances which was misleading (#[815])
115116
- Fixed inactivity bot workflow not checking out repository before running (#964)
116117
- Fixed the topic_message_query integarion test

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ A Python SDK for interacting with the Hedera Hashgraph platform.
1414
```bash
1515
pip install --upgrade pip
1616
pip install hiero-sdk-python
17+
pip install python-dotenv
1718
```
1819

1920
### Environment Configuration
@@ -30,14 +31,22 @@ A sample file is provided: [.env.example](.env.example)
3031
### Basic Usage
3132

3233
```python
33-
from hiero_sdk_python import Client, AccountBalanceQuery
34+
import os
35+
from dotenv import load_dotenv
36+
from hiero_sdk_python import Network, Client, CryptoGetAccountBalanceQuery, AccountId, PrivateKey
3437

3538
# Connect to testnet
36-
client = Client.for_testnet()
37-
client.set_operator(account_id, private_key)
39+
load_dotenv()
40+
network = Network("testnet")
41+
client = Client(network)
42+
43+
operator_id = AccountId.from_string(os.getenv("OPERATOR_ID",""))
44+
operator_key = PrivateKey.from_string(os.getenv("OPERATOR_KEY",""))
45+
46+
client.set_operator(operator_id, operator_key)
3847

3948
# Query account balance
40-
balance = AccountBalanceQuery(account_id=account_id).execute(client)
49+
balance = CryptoGetAccountBalanceQuery(account_id=operator_id).execute(client)
4150
print(f"Balance: {balance.hbars} HBAR")
4251
```
4352

0 commit comments

Comments
 (0)