Skip to content

Commit d41e30a

Browse files
authored
[infra] Use a modified no-response workflow in flutter/packages (#12745)
Resolves flutter/flutter#191756 Allows us to use the `waiting for response` label on PRs. PRs with that label will be auto-closed after 21 days of no response. Copies the existing flutter/flutter [`no-response.yaml`](https://github.com/flutter/flutter/blob/71d1e7f487a3a8fd3a220b5a5b3c9d0061af79ee/.github/workflows/no-response.yaml) and [`no-response.js`](https://github.com/flutter/flutter/blob/fdb1d09ef8187cac7dd99daf261c5a8df28a618e/.github/scripts/no-response.js) files to flutter/packages, but removes all the issue-specific logic since issues are disabled on flutter/packages so we only need this to work for PRs. ## Pre-Review Checklist **Test exemption: Github workflow change.** **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 3f7a1d4 commit d41e30a

2 files changed

Lines changed: 162 additions & 0 deletions

File tree

‎.github/scripts/no-response.js‎

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
module.exports = async ({ github, context }) => {
6+
const owner = context.repo.owner;
7+
const repo = context.repo.repo;
8+
const labelName = 'waiting for response';
9+
const daysUntilClose = 21;
10+
11+
const prCloseComment = `This pull request is being closed because it has not been updated in the last 21 days after a request for more information.
12+
13+
If you are still working on this, please feel free to reopen it or file a new pull request.
14+
15+
Thanks for your contribution.`;
16+
17+
const now = new Date();
18+
const closeDate = new Date(now.getTime() - (daysUntilClose * 24 * 60 * 60 * 1000));
19+
20+
// GitHub's pulls REST API does not support filtering by label. In GitHub's
21+
// data model, pull requests are treated as issues, so we query the issues
22+
// endpoint with the target label. Since issues are disabled in flutter/packages,
23+
// this will only return pull requests.
24+
const prs = await github.paginate(github.rest.issues.listForRepo, {
25+
owner,
26+
repo,
27+
state: 'open',
28+
labels: labelName,
29+
per_page: 100,
30+
});
31+
32+
for (const pr of prs) {
33+
if (!pr.pull_request) {
34+
continue;
35+
}
36+
37+
// Fetch timeline events to find label date
38+
const events = await github.paginate(github.rest.issues.listEvents, {
39+
owner,
40+
repo,
41+
issue_number: pr.number,
42+
per_page: 100,
43+
});
44+
45+
const labelEvent = events.reverse().find(
46+
event =>
47+
event.event === 'labeled' &&
48+
event.label?.name === labelName
49+
);
50+
51+
if (!labelEvent) {
52+
continue; // Skip if label not found in events
53+
}
54+
55+
const labeledAt = new Date(labelEvent.created_at);
56+
let isResponse = false;
57+
58+
// Check for author comments after label
59+
const comments = await github.paginate(github.rest.issues.listComments, {
60+
owner,
61+
repo,
62+
issue_number: pr.number,
63+
since: labeledAt.toISOString(),
64+
per_page: 100,
65+
});
66+
67+
for (const comment of comments) {
68+
if (pr.user?.id && comment.user?.id === pr.user.id && new Date(comment.created_at) > labeledAt) {
69+
isResponse = true;
70+
break;
71+
}
72+
}
73+
74+
// Check for commits after label
75+
if (!isResponse) {
76+
const commits = await github.paginate(github.rest.pulls.listCommits, {
77+
owner,
78+
repo,
79+
pull_number: pr.number,
80+
per_page: 100,
81+
});
82+
83+
for (const commit of commits) {
84+
const commitDate = new Date(commit.commit?.committer?.date || commit.commit?.author?.date);
85+
if (commitDate > labeledAt) {
86+
isResponse = true;
87+
break;
88+
}
89+
}
90+
}
91+
92+
if (isResponse) {
93+
console.log(`Removing label from #${pr.number} as author responded.`);
94+
await github.rest.issues.removeLabel({
95+
owner,
96+
repo,
97+
issue_number: pr.number,
98+
name: labelName,
99+
});
100+
101+
continue; // Skip stale check
102+
}
103+
104+
// Stale check
105+
if (pr.state === 'open') {
106+
if (labeledAt < closeDate) {
107+
if (pr.locked) {
108+
console.log(`Skipping #${pr.number} because the conversation is locked.`);
109+
continue;
110+
}
111+
112+
console.log(`Closing #${pr.number} due to no response.`);
113+
await github.rest.issues.createComment({
114+
owner,
115+
repo,
116+
issue_number: pr.number,
117+
body: prCloseComment,
118+
});
119+
await github.rest.issues.update({
120+
owner,
121+
repo,
122+
issue_number: pr.number,
123+
state: 'closed',
124+
});
125+
}
126+
}
127+
}
128+
};

‎.github/workflows/no-response.yaml‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2013 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
name: No Response
6+
7+
on:
8+
schedule:
9+
# Schedule for every 30 minutes.
10+
- cron: '*/30 * * * *'
11+
workflow_dispatch:
12+
13+
# By specifying the access of one of the scopes, all of those that are not
14+
# specified are set to 'none'.
15+
permissions:
16+
issues: write
17+
pull-requests: write
18+
19+
jobs:
20+
noResponse:
21+
runs-on: ubuntu-latest
22+
if: ${{ github.repository == 'flutter/packages' }}
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
26+
with:
27+
persist-credentials: false
28+
- name: No Response
29+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
30+
with:
31+
github-token: ${{ github.token }}
32+
script: |
33+
const script = require('./.github/scripts/no-response.js');
34+
await script({github, context});

0 commit comments

Comments
 (0)