Skip to content

Commit 8d95829

Browse files
committed
feat: add PR inactivity reminder bot for stale pull requests
Signed-off-by: MonaaEid <monaa_eid@hotmail.com>
1 parent ece8844 commit 8d95829

23 files changed

+1227
-198
lines changed
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
name: Good First Issue Template
2+
description: Create a Good First Issue for new contributors
3+
title: "[Good First Issue]: "
4+
labels: ["Good First Issue"]
5+
assignees: []
6+
body:
7+
- type: textarea
8+
id: intro
9+
attributes:
10+
label: 🆕🐥 First Timers Only
11+
description: Who is this issue for?
12+
value: |
13+
This issue is reserved for people who have never contributed or have made minimal contributions to [Hiero Python SDK](https://hiero.org).
14+
We know that creating a pull request (PR) is a major barrier for new contributors.
15+
The goal of this issue and all other issues in [**find a good first issue**](https://github.com/issues?q=is%3Aopen+is%3Aissue+org%3Ahiero-ledger+archived%3Afalse+label%3A%22good+first+issue%22+) is to help you make your first contribution to the Hiero Python SDK.
16+
validations:
17+
required: false
18+
19+
- type: textarea
20+
id: issue
21+
attributes:
22+
label: 👾 Description of the issue
23+
description: |
24+
DESCRIBE THE ISSUE IN A WAY THAT IS UNDERSTANDABLE TO NEW CONTRIBUTORS.
25+
YOU MUST NOT ASSUME THAT SUCH CONTRIBUTORS HAVE ANY KNOWLEDGE ABOUT THE CODEBASE OR HIERO.
26+
IT IS HELPFUL TO ADD LINKS TO THE RELEVANT DOCUMENTATION AND/OR CODE SECTIONS.
27+
BELOW IS AN EXAMPLE.
28+
value: |
29+
Edit here. Example provided below.
30+
31+
validations:
32+
required: true
33+
34+
- type: markdown
35+
attributes:
36+
value: |
37+
<!-- Example for problem (hidden in submission) -->
38+
## 👾 Description of the issue - Example
39+
40+
The example for Token Associate Transaction located at examples/tokens/token_associate_transaction.py can be improved. It correctly illustrates how to associate a token, however, it does so all from one function main()
41+
42+
As everything is grouped together in main(), it is difficult for a user to understand all the individual steps required to associate a token.
43+
44+
For example:
45+
```python
46+
47+
def run_demo():
48+
"""Monolithic token association demo."""
49+
print(f"🚀 Connecting to Hedera {network_name} network!")
50+
client = Client(Network(network_name))
51+
operator_id = AccountId.from_string(os.getenv("OPERATOR_ID", ""))
52+
operator_key = PrivateKey.from_string(os.getenv("OPERATOR_KEY", ""))
53+
client.set_operator(operator_id, operator_key)
54+
print(f"✅ Client ready (operator {operator_id})")
55+
56+
test_key = PrivateKey.generate_ed25519()
57+
receipt = (
58+
AccountCreateTransaction()
59+
.set_key(test_key.public_key())
60+
.set_initial_balance(Hbar(1))
61+
.set_account_memo("Test account for token association demo")
62+
.freeze_with(client)
63+
.sign(operator_key)
64+
.execute(client)
65+
)
66+
if receipt.status != ResponseCode.SUCCESS:
67+
raise Exception(receipt.status)
68+
account_id = receipt.account_id
69+
print(f"✅ Created test account {account_id}")
70+
71+
# Create tokens
72+
tokens = []
73+
for i in range(3):
74+
try:
75+
receipt = (
76+
TokenCreateTransaction()
77+
.set_token_name(f"DemoToken{i}")
78+
.set_token_symbol(f"DTK{i}")
79+
.set_decimals(2)
80+
.set_initial_supply(100_000)
81+
.set_treasury_account_id(operator_id)
82+
.freeze_with(client)
83+
.sign(operator_key)
84+
.execute(client)
85+
)
86+
if receipt.status != ResponseCode.SUCCESS:
87+
raise Exception(receipt.status)
88+
token_id = receipt.token_id
89+
tokens.append(token_id)
90+
print(f"✅ Created token {token_id}")
91+
except Exception as e:
92+
print(f"❌ Token creation failed: {e}")
93+
sys.exit(1)
94+
95+
# Associate first token
96+
try:
97+
TokenAssociateTransaction().set_account_id(account_id).add_token_id(tokens[0]).freeze_with(client).sign(test_key).execute(client)
98+
print(f"✅ Token {tokens[0]} associated with account {account_id}")
99+
except Exception as e:
100+
print(f"❌ Token association failed: {e}")
101+
sys.exit(1)
102+
```
103+
104+
- type: textarea
105+
id: solution
106+
attributes:
107+
label: 💡 Proposed Solution
108+
description: |
109+
AT THIS SECTION YOU NEED TO DESCRIBE THE STEPS NEEDED TO SOLVE THE ISSUE.
110+
PLEASE BREAK DOWN THE STEPS AS MUCH AS POSSIBLE AND MAKE SURE THAT THEY
111+
ARE EASY TO FOLLOW. IF POSSIBLE, ADD LINKS TO THE RELEVANT
112+
DOCUMENTATION AND/OR CODE SECTIONS.
113+
value: |
114+
Edit here. Example provided below.
115+
116+
validations:
117+
required: true
118+
119+
- type: markdown
120+
attributes:
121+
value: |
122+
<!-- Example for the solution (hidden in submission) -->
123+
## 💡 Solution - Example
124+
125+
For the TokenAssociateTransaction example, the solution is to split the monolithic main() function for illustrating TokenAssociateTransaction into separate smaller functions which are called from main().
126+
Such as:
127+
- Setting up the client
128+
- Creating an account
129+
- Creating a token
130+
- Associating the account to the token
131+
132+
- type: textarea
133+
id: implementation
134+
attributes:
135+
label: 👩‍💻 Implementation Steps
136+
description: |
137+
AT THIS SECTION YOU NEED TO DESCRIBE THE TECHNICAL STEPS NEEDED TO SOLVE THE ISSUE.
138+
PLEASE BREAK DOWN THE STEPS AS MUCH AS POSSIBLE AND MAKE SURE THAT THEY ARE EASY TO FOLLOW.
139+
IF POSSIBLE, ADD LINKS TO THE RELEVANT DOCUMENTATION AND/OR CODE.
140+
value: |
141+
Edit here. Example provided below.
142+
143+
validations:
144+
required: true
145+
146+
- type: markdown
147+
attributes:
148+
value: |
149+
<!-- Example implementation (hidden in submission) -->
150+
### 👩‍💻 Implementation - Example
151+
152+
To break down the monolithic main function, you need to:
153+
- [ ] Extract the Key Steps (set up a client, create a test account, create a token, associate the token)
154+
- [ ] Copy and paste the functionality for each key step into its own function
155+
- [ ] Pass to each function the variables you need to run it
156+
- [ ] Call each function in main()
157+
- [ ] Ensure you return the values you'll need to pass on to the next step in main
158+
- [ ] Ensure the example still runs and has the same output!
159+
160+
For example:
161+
```python
162+
163+
def setup_client():
164+
"""Initialize and set up the client with operator account."""
165+
166+
def create_test_account(client, operator_key):
167+
"""Create a new test account for demonstration."""
168+
169+
def create_fungible_token(client, operator_id, operator_key):
170+
"""Create a fungible token for association with test account."""
171+
172+
def associate_token_with_account(client, token_id, account_id, account_key):
173+
"""Associate the token with the test account."""
174+
175+
def main():
176+
client, operator_id, operator_key = setup_client()
177+
account_id, account_private_key = create_test_account(client, operator_key)
178+
token_id = create_fungible_token(client, operator_id, operator_key)
179+
associate_token_with_account(client, token_id, account_id, account_private_key)
180+
```
181+
182+
- type: textarea
183+
id: contribution_steps
184+
attributes:
185+
label: 📋 Step-by-Step Contribution Guide
186+
description: Provide a contribution workflow suitable for new contributors
187+
value: |
188+
If you have never contributed to an open source project at GitHub, the following step-by-step guide will introduce you to the workflow.
189+
190+
- [ ] **Claim this issue:** Comment below that you are interested in working on the issue. Without assignment, your pull requests might be closed and the issue given to another developer.
191+
- [ ] **Wait for assignment:** A community member with the given rights will add you as an assignee of the issue
192+
- [ ] **Fork, Branch and Work on the issue:** Create a copy of the repository, create a branch for the issue and solve the problem. For instructions, please read our [Contributing guide](https://github.com/hiero-ledger/hiero-sdk-python/blob/main/CONTRIBUTING.md) file. Further help can be found at [Set-up Training](https://github.com/hiero-ledger/hiero-sdk-python/tree/main/docs/sdk_developers/training/setup) and [Workflow Training](https://github.com/hiero-ledger/hiero-sdk-python/tree/main/docs/sdk_developers/training/workflow).
193+
- [ ] **DCO and GPG key sign each commit :** each commit must be -s and -S signed. An explanation on how to do this is at [Signing Guide](https://github.com/hiero-ledger/hiero-sdk-python/blob/main/docs/sdk_developers/signing.md)
194+
- [ ] **Add a Changelog Entry :** your pull request will require a changelog. Read [Changelog Entry Guide](https://github.com/hiero-ledger/hiero-sdk-python/blob/main/docs/sdk_developers/changelog_entry.md) to learn how.
195+
- [ ] **Push and Create a Pull Request :** Once your issue is resolved, and your commits are signed, and you have a changelog entry, push your changes and create a pull request. Detailed instructions can be found at [Submit PR Training](https://github.com/hiero-ledger/hiero-sdk-python/blob/main/docs/sdk_developers/training/workflow/11_submit_pull_request.md), part of [Workflow Training](https://github.com/hiero-ledger/hiero-sdk-python/tree/main/docs/sdk_developers/training/workflow).
196+
- [ ] **You did it 🎉:** A maintainer or committer will review your pull request and provide feedback. If approved, we will merge the fix in the main branch. Thanks for being part of the Hiero community as an open-source contributor ❤️
197+
198+
***IMPORTANT*** Your pull request CANNOT BE MERGED until you add a changelog entry AND sign your commits each with `git commit -S -s -m "chore: your commit message"` with a GPG key setup.
199+
validations:
200+
required: true
201+
202+
- type: textarea
203+
id: information
204+
attributes:
205+
label: 🤔 Additional Information
206+
description: Provide any extra resources or context for contributors to solve this good first issue
207+
value: |
208+
For more help, we have extensive documentation attributes:
209+
- [SDK Developer Docs](https://github.com/hiero-ledger/hiero-sdk-python/tree/main/docs/sdk_developers)
210+
- [SDK Developer Training](https://github.com/hiero-ledger/hiero-sdk-python/tree/main/docs/sdk_developers/training)
211+
212+
Additionally, we invite you to join our community on our [Discord](https://github.com/hiero-ledger/hiero-sdk-python/blob/main/docs/discord.md) server.
213+
214+
We also invite you to attend each Wednesday, 2pm UTC our [Python SDK Office Hour and Community Calls](https://zoom-lfx.platform.linuxfoundation.org/meetings/hiero?view=week). The Python SDK Office hour is for hands-on-help and the Community Call for general community discussion.
215+
216+
You can also ask for help in a comment below!

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
blank_issues_enabled: true
2+
3+
# Only show specific issue templates
4+
# issue_templates:
5+
# - name: Good First Issue
6+
# filename: 01-good_first_issue.yml
7+
8+
# Test contact links
9+
contact_links:
10+
- name: Hiero Discord
11+
url: https://github.com/hiero-ledger/hiero-sdk-python/blob/main/docs/discord.md
12+
about: Please ask and answer questions here.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// A script to remind PR authors of inactivity by posting a comment.
2+
3+
// DRY_RUN env var: any case-insensitive 'true' value will enable dry-run
4+
const dryRun = (process.env.DRY_RUN || 'false').toString().toLowerCase() === 'true';
5+
6+
// Helper to get the last commit date of a PR
7+
async function getLastCommitDate(github, pr, owner, repo) {
8+
const headRepoOwner = pr.head.repo?.owner?.login || owner;
9+
const headRepoName = pr.head.repo?.name || repo;
10+
try {
11+
const commitRes = await github.rest.repos.getCommit({
12+
owner: headRepoOwner,
13+
repo: headRepoName,
14+
ref: pr.head.sha,
15+
});
16+
const commit = commitRes.data?.commit ?? null;
17+
return new Date(commit?.author?.date || commit?.committer?.date || pr.created_at);
18+
} catch (getCommitErr) {
19+
console.log(`Failed to fetch head commit ${pr.head.sha} for PR #${pr.number}:`, getCommitErr.message || getCommitErr);
20+
return null; // Signal fallback needed
21+
}
22+
}
23+
24+
25+
// Look for an existing bot comment using our unique marker.
26+
async function hasExistingBotComment(github, pr, owner, repo, marker) {
27+
try {
28+
const comments = await github.paginate(github.rest.issues.listComments, {
29+
owner,
30+
repo,
31+
issue_number: pr.number,
32+
per_page: 100,
33+
});
34+
return comments.find(c => c.body && c.body.includes(marker)) || false;
35+
} catch (err) {
36+
console.log(`Failed to list comments for PR #${pr.number}:`, err.message || err);
37+
return null; // Prevent duplicate comment if we cannot check
38+
}
39+
}
40+
41+
// Helper to post an inactivity comment
42+
async function postInactivityComment(github, pr, owner, repo, marker, inactivityThresholdDays, discordLink, office_hours_calendar) {
43+
const comment = `${marker}
44+
Hi @${pr.user.login},\n\nThis pull request has had no commit activity for ${inactivityThresholdDays} days. Are you still working on the issue? please push a commit to keep the PR active or it will be closed due to inactivity.
45+
Reach out on discord or join our office hours if you need assistance.\n\n- ${discordLink}\n- ${office_hours_calendar} \n\nFrom the Python SDK Team`;
46+
if (dryRun) {
47+
console.log(`DRY-RUN: Would comment on PR #${pr.number} (${pr.html_url}) with body:\n---\n${comment}\n---`);
48+
return true;
49+
}
50+
51+
try {
52+
await github.rest.issues.createComment({
53+
owner,
54+
repo,
55+
issue_number: pr.number,
56+
body: comment,
57+
});
58+
console.log(`Commented on PR #${pr.number} (${pr.html_url})`);
59+
return true;
60+
} catch (commentErr) {
61+
console.log(`Failed to comment on PR #${pr.number}:`, commentErr);
62+
return false;
63+
}
64+
}
65+
66+
// Main module function
67+
module.exports = async ({github, context}) => {
68+
const inactivityThresholdDays = 10; // days of inactivity before commenting
69+
const cutoff = new Date(Date.now() - inactivityThresholdDays * 24 * 60 * 60 * 1000);
70+
const owner = context.repo.owner;
71+
const repo = context.repo.repo;
72+
const discordLink = `[Discord](https://github.com/hiero-ledger/hiero-sdk-python/blob/main/docs/discord.md)`;
73+
const office_hours_calendar =`[Office Hours](https://zoom-lfx.platform.linuxfoundation.org/meetings/hiero?view=week)`;
74+
// Unique marker so we can find the bot's own comment later.
75+
const marker = '<!-- pr-inactivity-bot-marker -->';
76+
77+
if (dryRun) {
78+
console.log('Running in DRY-RUN mode: no comments will be posted.');
79+
}
80+
81+
let commentedCount = 0;
82+
let skippedCount = 0;
83+
84+
const prs = await github.paginate(github.rest.pulls.list, {
85+
owner,
86+
repo,
87+
state: 'open',
88+
per_page: 100,
89+
});
90+
91+
for (const pr of prs) {
92+
// 1. Check inactivity
93+
const lastCommitDate = await getLastCommitDate(github, pr, owner, repo);
94+
if (lastCommitDate > cutoff) {
95+
skippedCount++;
96+
console.log(`PR #${pr.number} has recent commit on ${lastCommitDate.toISOString()} - skipping`);
97+
continue;
98+
}
99+
100+
// 2. Check for existing comment
101+
const existingBotComment = await hasExistingBotComment(github, pr, owner, repo, marker);
102+
if (existingBotComment) {
103+
skippedCount++;
104+
const idInfo = existingBotComment && existingBotComment.id ? existingBotComment.id : '(unknown)';
105+
console.log(`PR #${pr.number} already has an inactivity comment (id: ${idInfo}) - skipping`);
106+
continue;
107+
}
108+
109+
// 3. Post inactivity comment
110+
const commented = await postInactivityComment(github, pr, owner, repo, marker, inactivityThresholdDays, discordLink, office_hours_calendar);
111+
if (commented) commentedCount++;
112+
}
113+
114+
console.log("=== Summary ===");
115+
console.log(`PRs commented: ${commentedCount}`);
116+
console.log(`PRs skipped (existing comment present): ${skippedCount}`);
117+
};

.github/workflows/bot-inactivity-unassign-phase1.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: bot-inactivity-unassign-phase1
22

33
on:
44
schedule:
5-
- cron: "0 10 * * *"
5+
- cron: "0 12 * * *"
66
workflow_dispatch:
77

88
permissions:
@@ -15,6 +15,8 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
1820
- name: Harden the runner
1921
uses: step-security/harden-runner@df199fb7be9f65074067a9eb93f12bb4c5547cf2
2022
with:

0 commit comments

Comments
 (0)