raulcd commented on code in PR #55885: URL: https://github.com/apache/arrow/pull/55885#discussion_r4768644754
########## .github/workflows/triage.yml: ########## @@ -0,0 +1,125 @@ +# 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 + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + issues: write + pull-requests: write + steps: + - 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 CLOSE_AFTER_DAYS = 5; + const now = Date.now(); + const repo = context.repo; + + const lastLabeledAt = async (issue_number) => { + const events = await github.paginate(github.rest.issues.listEvents, { + ...repo, + issue_number, + per_page: 100, + }); + let ts = null; + for (const e of events) { + if (e.event === 'labeled' && e.label?.name === LABEL) { + const t = Date.parse(e.created_at); + if (ts === null || t > ts) ts = t; + } + } + return ts; + }; + + // 1. Label recent PRs opened by first-time contributors + 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 lastLabeledAt(pr.number)) !== null + ) { + continue; + } + await github.rest.issues.addLabels({ + ...repo, + issue_number: pr.number, + labels: [LABEL], + }); + } + if (done) break; + } + + // 2. Close PRs still in 'Status: Needs triage' after CLOSE_AFTER_DAYS days Review Comment: minor nit, if we close before adding the label we don't have to iterate over the new ones which should just have the label set :) ########## .github/workflows/triage.yml: ########## @@ -0,0 +1,125 @@ +# 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 + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + issues: write + pull-requests: write + steps: + - 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 CLOSE_AFTER_DAYS = 5; + const now = Date.now(); + const repo = context.repo; + + const lastLabeledAt = async (issue_number) => { + const events = await github.paginate(github.rest.issues.listEvents, { + ...repo, + issue_number, + per_page: 100, + }); + let ts = null; + for (const e of events) { + if (e.event === 'labeled' && e.label?.name === LABEL) { + const t = Date.parse(e.created_at); + if (ts === null || t > ts) ts = t; + } + } + return ts; + }; + + // 1. Label recent PRs opened by first-time contributors + 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 lastLabeledAt(pr.number)) !== null + ) { + continue; + } + await github.rest.issues.addLabels({ + ...repo, + issue_number: pr.number, + labels: [LABEL], + }); + } + if (done) break; + } + + // 2. Close PRs still in 'Status: Needs triage' after CLOSE_AFTER_DAYS days + const items = await github.paginate(github.rest.issues.listForRepo, { + ...repo, + state: 'open', + labels: LABEL, + per_page: 100, + }); + + for (const item of items) { + if (!item.pull_request) continue; + const createdAt = Date.parse(item.created_at); + if (now - createdAt < CLOSE_AFTER_DAYS * DAY_MS) continue; + if (now - ((await lastLabeledAt(item.number)) ?? createdAt) < CLOSE_AFTER_DAYS * DAY_MS) continue; + + await github.rest.issues.createComment({ + ...repo, + issue_number: item.number, + body: [ + `Thank you for your contribution! This pull request has been automatically closed because it remained in \`${LABEL}\` for more than ${CLOSE_AFTER_DAYS} days without being picked up for review.`, + '', + 'This is due to limited maintainer triage and review capacity and is not necessarily a rejection of your change. We encourage you to discuss the motivation and approach with Arrow maintainers on the linked GitHub issue (or open a new issue if one does not exist yet). Once a maintainer picks it up, this PR can be reopened—feel free to leave a comment here if you believe it was closed in error.', Review Comment: I am wondering whether this will have the unintended effect of starting to be pinged by users (or bots) so we "review" their "obviously great and required" change -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
