Skip to content

Commit 7064723

Browse files
fix(post_issue_on_zulip.py): filter out draft PRs (#49)
The draft data is not included in the issues object, so we need to make another request for PR objects. Also add an input that allows us to test without sending to Zulip.
1 parent 5f3c3cb commit 7064723

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

.github/workflows/monitor_runners.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ jobs:
224224
225225
# Check if this is a weekly report trigger
226226
is_weekly_report="false"
227-
if [ "${{ github.event.schedule }}" = "0 9 * * 1" ] || [ "${{ inputs.send_weekly_report }}" = "true" ]; then
227+
if [ "${{ github.event.schedule }}" = "0 9 * * 1" ] || [ "${{ toJSON(inputs.send_weekly_report) }}" = "true" ]; then
228228
is_weekly_report="true"
229229
fi
230230

.github/workflows/random_issue.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ on:
44
schedule:
55
- cron: '0 14 * * *'
66
workflow_dispatch:
7+
inputs:
8+
send_zulip_message:
9+
description: 'Send message to Zulip'
10+
required: false
11+
default: false
12+
type: boolean
713

814
jobs:
915
post_issues:
@@ -25,7 +31,7 @@ jobs:
2531
pip install PyGithub zulip
2632
2733
- name: Post issue on Zulip
28-
run: python post_issue_on_zulip.py "${{ secrets.RANDOM_ISSUE_BOT_ZULIP_TOKEN }}" "${{ secrets.LCB_TOKEN }}"
34+
run: python post_issue_on_zulip.py "${{ secrets.RANDOM_ISSUE_BOT_ZULIP_TOKEN }}" "${{ secrets.LCB_TOKEN }}" "${{ toJSON(github.event_name == 'schedule' || inputs.send_zulip_message) }}"
2935

3036
workflow-keepalive:
3137
if: github.event_name == 'schedule'

post_issue_on_zulip.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
zulip_token = sys.argv[1]
1212
gh_token = sys.argv[2]
13+
should_send_to_zulip = sys.argv[3]
1314

1415
zulip_client = zulip.Client(email="[email protected]", api_key=zulip_token, site="https://leanprover.zulipchat.com")
1516

@@ -30,25 +31,35 @@ def message_date(id):
3031
gh = github.Github(login_or_token=gh_token)
3132
mathlib = gh.get_repo('leanprover-community/mathlib4')
3233

33-
open_items = mathlib.get_issues(state='open')
34-
open_prs = []
34+
now = datetime.datetime.now(tz=datetime.timezone.utc)
35+
delta = datetime.timedelta(days=7)
36+
min_age = now - delta
37+
38+
open_issues_raw = mathlib.get_issues(state='open')
3539
open_issues = []
40+
open_prs_raw = mathlib.get_pulls(state='open')
41+
open_prs = []
3642

37-
print(f'Found {open_items.totalCount} open item(s) (PRs and issues).')
43+
print(f'Found {open_prs_raw.totalCount} open PR(s) and {open_issues_raw.totalCount} open issue(s).')
3844

39-
for i in open_items:
40-
now = datetime.datetime.now(tz=datetime.timezone.utc)
41-
delta = datetime.timedelta(days=7)
42-
min_age = now - delta
43-
if i.updated_at < min_age \
44-
and 'blocked-by-other-PR' not in [l.name for l in i.labels] \
45-
and not (i.number in posted_topics and datetime.datetime.fromtimestamp(posted_topics[i.number], tz=datetime.timezone.utc) > min_age):
46-
if i.pull_request:
47-
open_prs.append(i)
48-
else:
49-
open_issues.append(i)
45+
# Process issues (need to filter out PRs since get_issues returns both)
46+
for issue in open_issues_raw:
47+
if not issue.pull_request: # Only process actual issues
48+
if issue.updated_at < min_age \
49+
and 'blocked-by-other-PR' not in [l.name for l in issue.labels] \
50+
and not (issue.number in posted_topics and datetime.datetime.fromtimestamp(posted_topics[issue.number], tz=datetime.timezone.utc) > min_age):
51+
open_issues.append(issue)
5052

5153
print(f'Found {len(open_issues)} open issue(s) after filtering.')
54+
55+
# Process PRs
56+
for pr in open_prs_raw:
57+
if pr.updated_at < min_age \
58+
and 'blocked-by-other-PR' not in [l.name for l in pr.labels] \
59+
and not (pr.number in posted_topics and datetime.datetime.fromtimestamp(posted_topics[pr.number], tz=datetime.timezone.utc) > min_age) \
60+
and not pr.draft:
61+
open_prs.append(pr)
62+
5263
print(f'Found {len(open_prs)} open PR(s) after filtering.')
5364

5465
def post_random(select_from, kind):
@@ -76,7 +87,8 @@ def post_random(select_from, kind):
7687

7788
print(content)
7889

79-
zulip_client.send_message(post)
90+
if should_send_to_zulip != "false":
91+
zulip_client.send_message(post)
8092

8193
post_random(open_issues, 'issue')
8294
post_random(open_prs, 'PR')

0 commit comments

Comments
 (0)