From e4795f104131f29b4706ae38af19e7867c5707ac Mon Sep 17 00:00:00 2001 From: Alex Lebens Date: Tue, 10 Jun 2025 16:46:38 -0500 Subject: [PATCH] add new workflows --- .gitea/workflows/process-issues.yaml | 35 ++++++++++ .gitea/workflows/process-pull-requests.yaml | 35 ++++++++++ .gitea/workflows/tag-old-issues.yaml | 75 --------------------- 3 files changed, 70 insertions(+), 75 deletions(-) create mode 100644 .gitea/workflows/process-issues.yaml create mode 100644 .gitea/workflows/process-pull-requests.yaml delete mode 100644 .gitea/workflows/tag-old-issues.yaml diff --git a/.gitea/workflows/process-issues.yaml b/.gitea/workflows/process-issues.yaml new file mode 100644 index 0000000..0fba817 --- /dev/null +++ b/.gitea/workflows/process-issues.yaml @@ -0,0 +1,35 @@ +name: process-issues + +on: + schedule: + - cron: '@daily' + +jobs: + process-issues: + runs-on: ubuntu-latest + steps: + - name: Checkout Python Script + uses: actions/checkout@v4 + with: + repository: alexlebens/workflow-scripts + ref: main + token: ${{ secrets.BOT_TOKEN }} + path: scripts + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.13' + + - name: Install dependencies + run: pip install requests + + - name: Run Script + env: + INSTANCE_URL: ${{ vars.INSTANCE_URL }} + REPOSITORY: ${{ gitea.repository }} + TOKEN: ${{ secrets.BOT_TOKEN }} + STALE_DAYS: 3 + STALE_TAG: 'stale' + EXCLUDE_TAG: 'renovate' + run: python ./scripts/scripts/process-issues.py diff --git a/.gitea/workflows/process-pull-requests.yaml b/.gitea/workflows/process-pull-requests.yaml new file mode 100644 index 0000000..2abbf2e --- /dev/null +++ b/.gitea/workflows/process-pull-requests.yaml @@ -0,0 +1,35 @@ +name: process-pull-requests + +on: + schedule: + - cron: '@daily' + +jobs: + process-pull-requests: + runs-on: ubuntu-latest + steps: + - name: Checkout Python Script + uses: actions/checkout@v4 + with: + repository: alexlebens/workflow-scripts + ref: main + token: ${{ secrets.BOT_TOKEN }} + path: scripts + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.13' + + - name: Install dependencies + run: pip install requests + + - name: Run Script + env: + INSTANCE_URL: ${{ vars.INSTANCE_URL }} + REPOSITORY: ${{ gitea.repository }} + TOKEN: ${{ secrets.BOT_TOKEN }} + STALE_DAYS: 3 + STALE_TAG: 'stale' + REQUIRED_TAG: 'automerge' + run: python ./scripts/scripts/process-pull-requests.py diff --git a/.gitea/workflows/tag-old-issues.yaml b/.gitea/workflows/tag-old-issues.yaml deleted file mode 100644 index 33037cc..0000000 --- a/.gitea/workflows/tag-old-issues.yaml +++ /dev/null @@ -1,75 +0,0 @@ -name: tag-old-issues - -on: - schedule: - - cron: "@daily" - -jobs: - tag-old-issues: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Tag Old Issues - env: - BOT_TOKEN: ${{ secrets.BOT_TOKEN }} - INSTANCE_URL: ${{ vars.INSTANCE_URL }} - REPO_OWNER: ${{ github.repository_owner }} - REPO_NAME: ${{ github.repository_name }} - TAG_NAME: 'stale' - DAYS_OLD: 3 - EXCLUDE_TAG_NAME: '' - REQUIRED_TAG: 'automerge' - run: | - # Install necessary tools - apt-get update && apt-get install -y jq curl - - # --- Conditionally build the API URL --- - API_URL="${GITEA_INSTANCE_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/issues?state=open" - if [[ -n "${REQUIRED_TAG}" ]]; then - echo "Filtering for issues with the required tag: ${REQUIRED_TAG}" - # URL-encode the tag to handle special characters - ENCODED_TAG=$(jq -s -R -r @uri <<< "${REQUIRED_TAG}") - API_URL="${API_URL}&labels=${ENCODED_TAG}" - else - echo "No required tag specified. Checking all open issues." - fi - - # Fetch issues using the constructed URL - ISSUES=$(curl -s -X GET \ - -H "Authorization: token ${BOT_TOKEN}" \ - -H "Accept: application/json" \ - "${API_URL}") - - # 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") - - # 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 - ISSUE_NUMBER=$(echo "$issue" | jq -r '.number') - LABELS=$(echo "$issue" | jq -r '.labels[].name') - - # Check if the issue has the exclusion tag - if ! echo "$LABELS" | grep -q -w "${EXCLUDE_TAG_NAME}"; then - echo "Tagging issue #${ISSUE_NUMBER} as ${TAG_NAME}" - - # Get existing labels for the issue - EXISTING_LABELS=$(curl -s -X GET \ - -H "Authorization: token ${BOT_TOKEN}" \ - -H "Accept: application/json" \ - "${INSTANCE_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/issues/${ISSUE_NUMBER}/labels" | jq -r '.[].name') - - # Add the new tag to the list of existing labels - 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 - curl -s -X PUT \ - -H "Authorization: token ${BOT_TOKEN}" \ - -H "Content-Type: application/json" \ - -d "{\"labels\": $(echo "$NEW_LABELS" | jq -r 'map(select(. != ""))')}" \ - "${INSTANCE_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/issues/${ISSUE_NUMBER}/labels" - else - echo "Skipping issue #${ISSUE_NUMBER} because it has the '${EXCLUDE_TAG_NAME}' tag." - fi - done