forked from woocommerce/woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (139 loc) · 7.63 KB
/
Copy pathstalebot.yml
File metadata and controls
151 lines (139 loc) · 7.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: 'Process stale issues and PRs'
on:
schedule:
- cron: '21 0 * * *'
workflow_dispatch:
pull_request:
types: [converted_to_draft]
permissions: {}
jobs:
stale:
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
steps:
- name: Process stale issues and PRs
uses: actions/stale@v9.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: "As a part of this repository's maintenance, this issue is being marked as stale due to inactivity. Please feel free to comment on it in case we missed something.\n\n###### After 7 days with no activity this issue will be automatically closed."
close-issue-message: 'This issue was closed because it has been 14 days with no activity.'
operations-per-run: 140
days-before-stale: -1
days-before-close: -1
days-before-issue-stale: 7
days-before-issue-close: 7
stale-issue-label: 'status: stale'
exempt-issue-labels: 'type: enhancement'
only-issue-labels: 'needs: author feedback'
close-issue-label: "status: can't reproduce"
days-before-pr-stale: 30
days-before-pr-close: 14
stale-pr-label: 'status: stale'
only-pr-labels: 'needs: author feedback'
stale-pr-message: "As a part of this repository's maintenance, this PR is being marked as stale due to inactivity. Please feel free to comment on it in case we missed something.\n\n###### After 14 days with no activity this PR will be automatically closed."
close-pr-message: 'This PR was closed because it has been 1.5 months with no activity.'
delete-branch: true
ascending: true
- name: Process stale flaky tests issues
uses: actions/stale@v9.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
only-issue-labels: 'metric: flaky e2e test'
exempt-issue-labels: 'type: skipped test'
days-before-stale: -1
days-before-close: -1
days-before-issue-stale: 5
days-before-issue-close: 2
stale-issue-label: 'status: stale'
stale-issue-message: 'This issue is being marked as stale due to inactivity. It will be auto-closed if no further activity occurs within the next 2 days.'
close-issue-message: 'Auto-closed due to inactivity. Please re-open if you believe this issue is still valid.'
close-issue-reason: 'not_planned'
remove-stale-when-updated: true
exempt-all-assignees: false
enable-statistics: true
ascending: true
operations-per-run: 120
- name: Remove stale PR approvals (over 30 days old)
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1
with:
script: |
const thirtyDaysAgo = new Date();
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
console.log(`Checking for approvals before: ${thirtyDaysAgo.toISOString()}`);
const prs = await github.paginate(github.rest.pulls.list, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
per_page: 100
});
for (const pr of prs) {
const reviews = await github.paginate(github.rest.pulls.listReviews, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number
});
// Find the latest approval date for this PR
let latestApproval = null;
const approvalReviews = [];
for (const review of reviews) {
if (review.state === 'APPROVED') {
const reviewDate = new Date(review.submitted_at);
approvalReviews.push(review);
if (!latestApproval || reviewDate > latestApproval) {
latestApproval = reviewDate;
}
}
}
// Process only if we found any approvals
if (latestApproval) {
console.log(`PR #${pr.number} latest approval on ${latestApproval.toISOString()}`);
if (latestApproval < thirtyDaysAgo) {
console.log(`Found ${approvalReviews.length} approvals to dismiss on PR #${pr.number} (latest approval was on ${latestApproval.toISOString()})`);
// Dismiss all approvals
for (const review of approvalReviews) {
console.log(`Dismissing approval from ${review.user.login}`);
await github.rest.pulls.dismissReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
review_id: review.id,
message: 'This approval has been dismissed due to being stale (latest PR approval was 30+ days old). Please request a new review.'
});
}
} else {
console.log(`Keeping approvals on PR #${pr.number} (latest approval on ${latestApproval.toISOString()})`);
}
}
}
remove-draft-approvals:
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: github.event_name == 'pull_request' && github.event.action == 'converted_to_draft'
steps:
- name: Remove approvals from draft PR
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1
with:
script: |
const pr = context.payload.pull_request;
const reviews = await github.paginate(github.rest.pulls.listReviews, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number
});
for (const review of reviews) {
if (review.state === 'APPROVED') {
console.log(`Dismissing approval on draft PR #${pr.number} from ${review.user.login}`);
await github.rest.pulls.dismissReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
review_id: review.id,
message: 'This approval has been dismissed due to the PR being moved to draft status. Please request a new review when ready.'
});
}
}