1
0
reusable-workflows/.gitea/workflows/milestoneRenameAndRecreate.yaml

65 lines
2.3 KiB
YAML
Raw Permalink Normal View History

2024-10-24 08:59:16 +00:00
name: Milestone Rename
on:
workflow_call:
inputs:
repo:
required: true
type: string
currentName:
required: true
type: string
newName:
required: true
type: string
2025-01-16 11:15:20 +00:00
outputs:
milestoneId:
description: "Milestone Id"
value: ${{ jobs.rename.outputs.milestoneId }}
2024-10-24 08:59:16 +00:00
jobs:
rename:
runs-on: ubuntu-latest
2025-01-16 11:15:20 +00:00
outputs:
2025-01-16 11:26:05 +00:00
milestoneId: ${{ steps.Rename.outputs.milestoneId }}
2024-10-24 08:59:16 +00:00
steps:
2025-01-16 11:15:20 +00:00
- id: Rename
2024-10-24 08:59:16 +00:00
run: |
GITEA_API_URL="https://gitea.greyhound-software.com/api/v1"
OWNER="greyhound"
API_TOKEN=${{ vars.PAT_TOKEN }}
# Fetch milestones from the repository
milestones=$(curl -s -H "Authorization: token $API_TOKEN" \
"$GITEA_API_URL/repos/$OWNER/${{ inputs.repo }}/milestones")
# Extract the ID of the ${{ inputs.currentName }} milestone
2025-01-16 11:26:05 +00:00
milestoneId=$(echo "$milestones" | jq '.[] | select(.title == "${{ inputs.currentName }}") | .id')
2024-10-24 08:59:16 +00:00
2025-01-16 11:26:05 +00:00
if [ -z "$milestoneId" ]; then
2024-10-24 08:59:16 +00:00
echo "No milestone named '${{ inputs.currentName }}' found. Exiting."
exit 1
fi
2025-01-16 11:26:05 +00:00
echo "Found '${{ inputs.currentName }}' milestone with ID: $milestoneId"
2024-10-24 08:59:16 +00:00
echo "Rename the '${{ inputs.currentName }}' milestone to '${{ inputs.newName }}"
new_name="${{ inputs.newName }}"
milestone_update=$(curl -s -X PATCH -H "Authorization: token $API_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"title\": \"$new_name\", \"state\": \"closed\"}" \
2025-01-16 11:26:05 +00:00
"$GITEA_API_URL/repos/$OWNER/${{ inputs.repo }}/milestones/$milestoneId")
2024-10-24 08:59:16 +00:00
echo "Renamed '${{ inputs.currentName }}' milestone to $new_name: $milestone_update"
# Create a new milestone named "${{ inputs.currentName }}"
milestone_data=$(jq -n \
--arg title "${{ inputs.currentName }}" \
'{"title": $title}')
response=$(curl -s -X POST -H "Authorization: token $API_TOKEN" \
-H "Content-Type: application/json" \
-d "$milestone_data" \
"$GITEA_API_URL/repos/$OWNER/${{ inputs.repo }}/milestones")
2025-01-16 11:26:05 +00:00
echo "milestoneId=$milestoneId" >> $GITHUB_OUTPUT
2024-10-18 06:46:44 +00:00
echo "Created new '${{ inputs.currentName }}' milestone: $response"