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