Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-4140. Auto-close /pending pull requests after 21 days of inactivity #1344

Merged
merged 4 commits into from Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/close-pending.sh
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
# 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.

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
MESSAGE=$(cat $SCRIPT_DIR/closing-message.txt)

while IFS= read -r number &&
IFS= read -r title; do
echo "Closing PR ($number): $title"
curl -s -o /dev/null \
-X POST \
--data "$(jq --arg body "$MESSAGE" -n '{body: $body}')" \
--header "authorization: Bearer $GITHUB_TOKEN" \
--header 'content-type: application/json' \
"https://api.github.com/repos/apache/hadoop-ozone/issues/$number/comments"

curl -s -o /dev/null \
-X PATCH \
--data '{"state": "close"}' \
--header "authorization: Bearer $GITHUB_TOKEN" \
--header 'content-type: application/json' \
"https://api.github.com/repos/apache/hadoop-ozone/pulls/$number"
done < <(curl -H "Content-Type: application/json" \
--header "authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/search/issues?q=repo:apache/hadoop-ozone+type:pr+updated:<$(date -d "-21 days" +%Y-%m-%d)+label:pending+is:open" \
| jq -r '.items[] | (.number,.title)')
7 changes: 7 additions & 0 deletions .github/closing-message.txt
@@ -0,0 +1,7 @@
Thank you very much for the patch. I am closing this PR __temporarily__ as there was no activity recently and it is waiting for response from its author.

It doesn't mean that this PR is not important or ignored: feel free to reopen the PR at any time.

It only means that attention of committers is not required. We prefer to keep the review queue clean. This ensures PRs in need of review are more visible, which results in faster feedback for all PRs.

If you need ANY help to finish this PR, please [contact the community](https://github.com/apache/hadoop-ozone#contact) on the mailing list or the slack channel."
10 changes: 2 additions & 8 deletions .github/comment-commands/close.sh
Expand Up @@ -16,14 +16,8 @@

#doc: Close pending pull request temporary
# shellcheck disable=SC2124
MESSAGE="Thank you very much for the patch. I am closing this PR __temporarily__ as there was no
activity recently and it is waiting for response from its author.

It doesn't mean that this PR is not important or ignored: feel free to reopen the PR at any time.

It only means that attention of committers is not required. We prefer to keep the review queue clean. This ensures PRs in need of review are more visible, which results in faster feedback for all PRs.

If you need ANY help to finish this PR, please [contact the community](https://github.com/apache/hadoop-ozone#contact) on the mailing list or the slack channel."
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
MESSAGE=$(cat $SCRIPT_DIR/../closing-message.txt)

set +x #GITHUB_TOKEN
curl -s -o /dev/null \
Expand Down
1 change: 1 addition & 0 deletions .github/comment-commands/pending.sh
Expand Up @@ -20,6 +20,7 @@ MESSAGE="Marking this issue as un-mergeable as requested.

Please use \`/ready\` comment when it's resolved.

Please note that the PR will be closed after 21 days of inactivity from now. (But can be re-opened anytime later...)
> $@"

URL="$(jq -r '.issue.pull_request.url' "$GITHUB_EVENT_PATH")/reviews"
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/close-pending.yaml
@@ -0,0 +1,32 @@
# 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: close-prs

on:
schedule:
- cron: '*/5 * * * *'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to run this workflow once per day instead of every 5 minutes. The list of pending PRs to be closed is filtered only by date (eg. 2020-08-03), not time, so most of the runs would be no-ops.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, I started with one day but changed it to five minutes to show if it works. Changing back.


jobs:
close-pending:
name: close-pending
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@master
- name: Execute close-pending script
if: github.repository == 'apache/hadoop-ozone'
run: ./.github/close-pending.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}