65 lines
2.3 KiB
YAML
65 lines
2.3 KiB
YAML
name: Milestone Rename
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
repo:
|
|
required: true
|
|
type: string
|
|
currentName:
|
|
required: true
|
|
type: string
|
|
newName:
|
|
required: true
|
|
type: string
|
|
outputs:
|
|
milestoneId:
|
|
description: "Milestone Id"
|
|
value: ${{ jobs.rename.outputs.milestoneId }}
|
|
jobs:
|
|
rename:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
milestoneId: ${{ steps.Rename.outputs.milestoneId }}
|
|
steps:
|
|
- id: Rename
|
|
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
|
|
milestoneId=$(echo "$milestones" | jq '.[] | select(.title == "${{ inputs.currentName }}") | .id')
|
|
|
|
if [ -z "$milestoneId" ]; then
|
|
echo "No milestone named '${{ inputs.currentName }}' found. Exiting."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Found '${{ inputs.currentName }}' milestone with ID: $milestoneId"
|
|
|
|
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\"}" \
|
|
"$GITEA_API_URL/repos/$OWNER/${{ inputs.repo }}/milestones/$milestoneId")
|
|
|
|
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")
|
|
|
|
echo "milestoneId=$milestoneId" >> $GITHUB_OUTPUT
|
|
echo "Created new '${{ inputs.currentName }}' milestone: $response" |