diff --git a/.github/workflows/triage.yml b/.github/workflows/triage.yml new file mode 100644 index 00000000000..1d6de803d05 --- /dev/null +++ b/.github/workflows/triage.yml @@ -0,0 +1,102 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +name: PR Triage + +on: + schedule: + - cron: "15 * * * *" + workflow_dispatch: + +permissions: + contents: read + +jobs: + triage: + name: Label and Close Untriaged PRs + if: github.repository == 'apache/arrow' + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + issues: write + pull-requests: write + steps: + - name: Close untriaged PRs + uses: actions/stale@v11 + with: + only-pr-labels: "Status: needs triage" + stale-pr-label: "Status: closed-untriaged" + stale-pr-message: |- + Thank you for your contribution! This pull request has been automatically closed because it remained in `Status: needs triage` for more than 7 days without being picked up for review. + + Due to limited maintainer review capacity, first-time pull requests that are not triaged within 7 days are closed automatically. This is not necessarily a rejection of your change. If you would like to pursue it further, please discuss the problem and approach on the linked GitHub issue (or on the [dev@arrow.apache.org](https://lists.apache.org/list.html?dev@arrow.apache.org) mailing list for broader changes) rather than commenting here. Please do not `@`-mention individual maintainers to request a review or reopen. + labels-to-remove-when-stale: "Status: needs triage" + days-before-pr-stale: 7 + days-before-pr-close: 0 + ignore-pr-updates: true + remove-pr-stale-when-updated: false + # exclude issues + days-before-issue-stale: -1 + days-before-issue-close: -1 + operations-per-run: 100 + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Label untriaged PRs + uses: actions/github-script@v9 + with: + script: | + const LABEL = 'Status: needs triage'; + const TRUSTED = new Set(['OWNER', 'MEMBER', 'COLLABORATOR', 'CONTRIBUTOR']); + const EXEMPT_USERS = new Set(['dependabot[bot]', 'github-actions[bot]']); + const DAY_MS = 24 * 60 * 60 * 1000; + const now = Date.now(); + const repo = context.repo; + + const wasEverLabeled = async (issue_number) => { + const events = await github.paginate(github.rest.issues.listEvents, { + ...repo, + issue_number, + per_page: 100, + }); + return events.some((e) => e.event === 'labeled' && e.label?.name === LABEL); + }; + + let done = false; + for await (const { data: prs } of github.paginate.iterator( + github.rest.pulls.list, + { ...repo, state: 'open', sort: 'created', direction: 'desc', per_page: 100 } + )) { + for (const pr of prs) { + if (now - Date.parse(pr.created_at) > DAY_MS) { + done = true; + break; + } + if ( + TRUSTED.has(pr.author_association) || + EXEMPT_USERS.has(pr.user?.login) || + pr.labels.some((l) => l.name === LABEL) || + (await wasEverLabeled(pr.number)) + ) { + continue; + } + await github.rest.issues.addLabels({ + ...repo, + issue_number: pr.number, + labels: [LABEL], + }); + } + if (done) break; + }