Remove ready to test labels #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (C) 2015 The Gravitee team (http://gravitee.io) | |
# | |
# 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. | |
name: Remove ready to test labels | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
jobs: | |
remove-ready-to-test-labels: | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Scan pull requests and remove ready_to_test labels" | |
env: | |
ORG_NAME: gravitee-io | |
REPO_NAME: gravitee-access-management | |
run: | | |
PR_NUMBERS=$(curl -s -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/gravitee-io/gravitee-access-management/issues?state=open&labels=ready_to_test&type=pr" | jq -r '.[].number') | |
for PR_NUMBER in $PR_NUMBERS; do | |
# Get all events for the PR | |
# Then, filter on "labeled" events with "ready_to_test" label | |
# Get the last time the PR has been labeled with "ready_to_test" | |
# Finally, remove the double quotes to be able to parse and compare the date | |
LAST_TIMESTAMP=$(curl -s "https://api.github.com/repos/gravitee-io/gravitee-access-management/issues/$PR_NUMBER/events?per_page\=1000" | jq '.[] | select(.event == "labeled" and .label.name == "ready_to_test") | .created_at' | tail -n 1 | tr -d '"') | |
echo "PR $PR_NUMBER has been labeled at $LAST_TIMESTAMP" | |
ONE_WEEK_AGO=$(($(date +%s) - 7*84600)) | |
LAST_TIMESTAMP_EPOCH=$(date -d "$LAST_TIMESTAMP" +%s) | |
if [[ $LAST_TIMESTAMP_EPOCH -lt ONE_WEEK_AGO ]]; then | |
echo "The pull request $PR_NUMBER has been labeled for more than 1 week, removing the label ready_to_test" | |
curl -s -X DELETE \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-H 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ | |
"https://api.github.com/repos/gravitee-io/gravitee-access-management/issues/$PR_NUMBER/labels/ready_to_test" | |
fi | |
done |