add logging
All checks were successful
test-build / build (push) Successful in 1m1s
renovate / renovate (push) Successful in 19s

This commit is contained in:
2025-06-10 12:15:47 -05:00
parent 3017668cd2
commit cb52c169a3

View File

@@ -4,6 +4,8 @@ on:
schedule: schedule:
- cron: '@daily' - cron: '@daily'
workflow_dispatch:
jobs: jobs:
tag-old-issues: tag-old-issues:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -23,20 +25,21 @@ jobs:
REQUIRED_TAG: 'automerge' REQUIRED_TAG: 'automerge'
run: | run: |
# Install necessary tools # Install necessary tools
apt-get update && apt-get install -y jq curl sudo apt-get -qq update && sudo apt-get -qq install -y jq curl
# --- Conditionally build the API URL --- # --- Conditionally build the API URL ---
API_URL="${GITEA_INSTANCE_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/issues?state=open" API_URL="${GITEA_INSTANCE_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/issues?state=open"
if [[ -n "${REQUIRED_TAG}" ]]; then if [[ -n "${REQUIRED_TAG}" ]]; then
echo "Filtering for issues with the required tag: ${REQUIRED_TAG}" echo ">> Filtering for issues with the required tag: ${REQUIRED_TAG}"
# URL-encode the tag to handle special characters # URL-encode the tag to handle special characters
ENCODED_TAG=$(jq -s -R -r @uri <<< "${REQUIRED_TAG}") ENCODED_TAG=$(jq -s -R -r @uri <<< "${REQUIRED_TAG}")
API_URL="${API_URL}&labels=${ENCODED_TAG}" API_URL="${API_URL}&labels=${ENCODED_TAG}"
else else
echo "No required tag specified. Checking all open issues." echo ">> No required tag specified. Checking all open issues."
fi fi
# Fetch issues using the constructed URL # Fetch issues using the constructed URL
echo ">> Fetching issues ..."
ISSUES=$(curl -s -X GET \ ISSUES=$(curl -s -X GET \
-H "Authorization: token ${BOT_TOKEN}" \ -H "Authorization: token ${BOT_TOKEN}" \
-H "Accept: application/json" \ -H "Accept: application/json" \
@@ -44,6 +47,7 @@ jobs:
# Calculate the date ${DAYS_OLD} days ago in ISO 8601 format # Calculate the date ${DAYS_OLD} days ago in ISO 8601 format
OLDER_THAN_DATE=$(date -d "-${DAYS_OLD} days" -u +"%Y-%m-%dT%H:%M:%SZ") OLDER_THAN_DATE=$(date -d "-${DAYS_OLD} days" -u +"%Y-%m-%dT%H:%M:%SZ")
echo ">> Filtering for older than ${OLDER_THAN_DATE}"
# Filter issues older than the specified date and without the exclusion tag # Filter issues older than the specified date and without the exclusion tag
echo "$ISSUES" | jq -c '.[] | select(.created_at < "'"$OLDER_THAN_DATE"'")' | while read -r issue; do echo "$ISSUES" | jq -c '.[] | select(.created_at < "'"$OLDER_THAN_DATE"'")' | while read -r issue; do
@@ -52,7 +56,7 @@ jobs:
# Check if the issue has the exclusion tag # Check if the issue has the exclusion tag
if ! echo "$LABELS" | grep -q -w "${EXCLUDE_TAG_NAME}"; then if ! echo "$LABELS" | grep -q -w "${EXCLUDE_TAG_NAME}"; then
echo "Tagging issue #${ISSUE_NUMBER} as ${TAG_NAME}" echo ">> Tagging issue #${ISSUE_NUMBER} as ${TAG_NAME}"
# Get existing labels for the issue # Get existing labels for the issue
EXISTING_LABELS=$(curl -s -X GET \ EXISTING_LABELS=$(curl -s -X GET \
@@ -64,12 +68,15 @@ jobs:
NEW_LABELS=$(echo -e "${EXISTING_LABELS}\n${TAG_NAME}" | sort -u | jq -R -s -c 'split("\n") | map(select(length > 0))') NEW_LABELS=$(echo -e "${EXISTING_LABELS}\n${TAG_NAME}" | sort -u | jq -R -s -c 'split("\n") | map(select(length > 0))')
# Update the issue with the new set of labels # Update the issue with the new set of labels
echo ">> Updating issue on Gitea ..."
curl -s -X PUT \ curl -s -X PUT \
-H "Authorization: token ${BOT_TOKEN}" \ -H "Authorization: token ${BOT_TOKEN}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "{\"labels\": $(echo "$NEW_LABELS" | jq -r 'map(select(. != ""))')}" \ -d "{\"labels\": $(echo "$NEW_LABELS" | jq -r 'map(select(. != ""))')}" \
"${INSTANCE_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/issues/${ISSUE_NUMBER}/labels" "${INSTANCE_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/issues/${ISSUE_NUMBER}/labels"
else else
echo "Skipping issue #${ISSUE_NUMBER} because it has the '${EXCLUDE_TAG_NAME}' tag." echo ">> Skipping issue #${ISSUE_NUMBER} because it has the '${EXCLUDE_TAG_NAME}' tag."
fi fi
done done
echo ">> Finished applying tags."