Skip to content

Fixup PR Labels

Fixup PR Labels #1

# 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: Fixup PR Labels
on:
workflow_dispatch: # Let us run manually
schedule:
- cron: '0 3 * * *' # Run at 3:00 UTC nightly
jobs:
# This job removes the triage and needs-attention labels from any PRs that have been reviewed. Once reviewed, it is
# assumed that a PR does _not_ need extra attention from the committers, so these labels can be removed.
fixup-pr-labels:
runs-on: ubuntu-latest
strategy:
matrix:
label: [triage, needs-attention]
steps:
- name: Env
run: printenv
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
- name: Remove label
uses: actions/github-script@v7
continue-on-error: true
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
console.log("Finding PRs with label '${{ matrix.label }}'");
github.paginate("GET /search/issues{?q}", {
q: "repo:apache/kafka label:${{ matrix.label }} is:pull-request"
})
.then((pulls) => {
pulls.forEach(pull => {
github.request("GET /repos/{owner}/{repo}/pulls/{pull_number}/reviews", {
owner: "apache",
repo: "kafka",
pull_number: pull.number,
headers: {
"X-GitHub-Api-Version": "2022-11-28"
}
}).then((resp) => {
console.log("Found " + resp.data.length + " reviews for PR " + pull.number);
if (resp.data.length > 0) {
console.log("Removing '${{ matrix.label }}' label from PR " + pull.number + " : " + pull.title);
github.rest.issues.removeLabel({
owner: "apache",
repo: "kafka",
issue_number: pull.number,
name: "${{ matrix.label }}"
});
}
});
});
});
# This job adds a 'needs-attention' label to any PR that has not been updated in 7 days and has been labeled with 'triage'.
# The idea here is to give committers a quick way to see which PRs have languished and need attention.
needs-attention:
runs-on: ubuntu-latest
needs: [fixup-pr-labels]
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v9
with:
debug-only: ${{ inputs.dryRun || false }}
operations-per-run: ${{ inputs.operationsPerRun || 500 }}
days-before-stale: 7
days-before-close: -1
ignore-pr-updates: true
only-pr-labels: 'triage'
stale-pr-label: 'needs-attention'
stale-pr-message: |
A label of 'needs-attention' was automatically added to this PR in order to raise the
attention of the committers. Once this issue has been triaged, the `triage` label
should be removed to prevent this automation from happening again.