You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuweni.apache.org by to...@apache.org on 2023/01/11 03:41:45 UTC

[incubator-tuweni] branch main updated: add a workflow to mark issues and PR stale

This is an automated email from the ASF dual-hosted git repository.

toulmean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git


The following commit(s) were added to refs/heads/main by this push:
     new c3f49e68c add a workflow to mark issues and PR stale
     new 699702800 Merge pull request #458 from atoulme/mark_issues_stale
c3f49e68c is described below

commit c3f49e68cc58eb71e3aea748e0c3ae8790e6ab11
Author: Antoine Toulme <an...@lunar-ocean.com>
AuthorDate: Sun Jan 1 00:42:56 2023 -0800

    add a workflow to mark issues and PR stale
---
 .github/workflows/close-stale.yml                 | 38 +++++++++++++
 .github/workflows/mark-issues-as-stale.yml        | 37 ++++++++++++
 .github/workflows/scripts/mark-issues-as-stale.sh | 68 +++++++++++++++++++++++
 3 files changed, 143 insertions(+)

diff --git a/.github/workflows/close-stale.yml b/.github/workflows/close-stale.yml
new file mode 100644
index 000000000..bf2cc79a2
--- /dev/null
+++ b/.github/workflows/close-stale.yml
@@ -0,0 +1,38 @@
+#
+# 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.
+
+# This is copied from https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/.github/workflows/close-stale.yaml
+name: "Close stale issues and pull requests"
+on:
+  schedule:
+    - cron: "12 5 * * *" # arbitrary time not to DDOS GitHub
+
+jobs:
+  stale:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/stale@v6
+        with:
+          repo-token: ${{ secrets.GITHUB_TOKEN }}
+          stale-pr-message: 'This PR was marked stale due to lack of activity. It will be closed in 14 days.'
+          close-pr-message: 'Closed as inactive. Feel free to reopen if this PR is still being worked on.'
+          close-issue-message: 'This issue has been closed as inactive because it has been stale for 120 days with no activity.'
+          close-issue-label: 'closed as inactive'
+          days-before-pr-stale: 14
+          days-before-issue-stale: -1 # Stale label is applied by mark-issues-as-stale.yml
+          days-before-pr-close: 14
+          days-before-issue-close: 60
+          exempt-issue-labels: 'never stale'
\ No newline at end of file
diff --git a/.github/workflows/mark-issues-as-stale.yml b/.github/workflows/mark-issues-as-stale.yml
new file mode 100644
index 000000000..ccc58861a
--- /dev/null
+++ b/.github/workflows/mark-issues-as-stale.yml
@@ -0,0 +1,37 @@
+#
+# 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.
+
+# This is copied from https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/.github/workflows/mark-issues-as-stale.yml
+name: 'Mark issues as stale'
+on:
+  schedule:
+    - cron: "27 3 * * 1-5" # Run at an arbitrary time on weekdays.
+
+jobs:
+  mark-issues-as-stale:
+    runs-on: ubuntu-latest
+    if: ${{ github.repository_owner == 'apache' }}
+    steps:
+      - uses: actions/checkout@v3
+
+      - name: Run mark-issues-as-stale.sh
+        run: ./.github/workflows/scripts/mark-issues-as-stale.sh
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          DAYS_BEFORE_STALE: 60
+          DAYS_BEFORE_CLOSE: 60 # Only used for the stale message.
+          STALE_LABEL: 'Stale'
+          EXEMPT_LABEL: 'never stale'
\ No newline at end of file
diff --git a/.github/workflows/scripts/mark-issues-as-stale.sh b/.github/workflows/scripts/mark-issues-as-stale.sh
new file mode 100644
index 000000000..31591dd89
--- /dev/null
+++ b/.github/workflows/scripts/mark-issues-as-stale.sh
@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+#
+#   Copyright The OpenTelemetry Authors.
+#   Copyright Apache Tuweni
+#
+#   Licensed 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.
+#
+# This script checks for issues that have been inactive for a certain number
+# of days. Any inactive issues have codeowners pinged for labels corresponding
+# to a component and are marked as stale. The stale bot will then handle
+# the rest of the lifecycle, including removing the stale label and closing
+# the issue.
+#
+# This script is necessary instead of just using the stale action because
+# the stale action does not support pinging code owners, and pinging
+# code owners after marking an issue as stale will cause the issue to
+# have the stale label removed according to all documented behavior
+# of the stale action.
+
+set -euo pipefail
+
+if [[ -z ${DAYS_BEFORE_STALE:-} || -z ${DAYS_BEFORE_CLOSE:-} || -z ${STALE_LABEL:-} || -z ${EXEMPT_LABEL:-} ]]; then
+    echo "At least one of DAYS_BEFORE_STALE, DAYS_BEFORE_CLOSE, STALE_LABEL, or EXEMPT_LABEL has not been set, please ensure each is set."
+    exit 0
+fi
+
+CUR_DIRECTORY=$(dirname "$0")
+STALE_MESSAGE="This issue has been inactive for ${DAYS_BEFORE_STALE} days. It will be closed in ${DAYS_BEFORE_CLOSE} days if there is no activity. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it."
+
+# Check for the least recently-updated issues that aren't currently stale.
+# If no issues in this list are stale, the repo has no stale issues.
+ISSUES=$(gh issue list --limit 100 --search "is:issue is:open -label:\"${STALE_LABEL}\" -label:\"${EXEMPT_LABEL}\" sort:updated-asc" --json number --jq '.[].number')
+
+for ISSUE in ${ISSUES}; do
+    OWNER_MENTIONS=''
+
+    UPDATED_AT=$(gh issue view "${ISSUE}" --json updatedAt --jq '.updatedAt')
+    UPDATED_UNIX=$(date +%s --date="${UPDATED_AT}")
+    NOW=$(date +%s)
+    DIFF_DAYS=$(((NOW-UPDATED_UNIX)/(3600*24)))
+
+    if (( DIFF_DAYS < DAYS_BEFORE_STALE )); then
+        echo "Issue #${ISSUE} is not stale. Issues are sorted by updated date in ascending order, so all remaining issues must not be stale. Exiting."
+        exit 0
+    fi
+
+    gh issue comment "${ISSUE}" -b "${STALE_MESSAGE}"
+
+    # We want to add a label after making a comment for two reasons:
+    # 1. If there is some error making a comment, a stale label should not be applied.
+    #    We want code owners to be pinged before closing an issue as stale.
+    # 2. The stale bot (as of v6) uses the timestamp for when the stale label was
+    #    applied to determine when an issue was marked stale. We want to ensure that
+    #    was the last activity on the issue, or the stale bot will remove the stale
+    #    label if our comment to ping code owners comes too long after the stale
+    #    label is applied.
+    gh issue edit "${ISSUE}" --add-label "${STALE_LABEL}"
+done
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tuweni.apache.org
For additional commands, e-mail: commits-help@tuweni.apache.org