|
| 1 | +name: Move Issues from One Milestone to Another |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + from_milestone: |
| 7 | + description: 'Source milestone title (e.g., 0.80)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + to_milestone: |
| 11 | + description: 'Target milestone title (e.g., 0.81)' |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + |
| 15 | +jobs: |
| 16 | + move_issues: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Install GitHub CLI |
| 21 | + run: | |
| 22 | + sudo apt update |
| 23 | + sudo apt install -y gh |
| 24 | + - name: Authenticate GitHub CLI |
| 25 | + run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token |
| 26 | + |
| 27 | + - name: Move issues between milestones |
| 28 | + env: |
| 29 | + REPO: ${{ github.repository }} |
| 30 | + MILESTONE_FROM: ${{ github.event.inputs.from_milestone }} |
| 31 | + MILESTONE_TO: ${{ github.event.inputs.to_milestone }} |
| 32 | + run: | |
| 33 | + echo "Fetching milestone numbers for $REPO..." |
| 34 | + FROM_ID=$(gh api repos/$REPO/milestones --jq ".[] | select(.title==\"$MILESTONE_FROM\") | .number") |
| 35 | + TO_ID=$(gh api repos/$REPO/milestones --jq ".[] | select(.title==\"$MILESTONE_TO\") | .number") |
| 36 | + if [ -z "$FROM_ID" ] || [ -z "$TO_ID" ]; then |
| 37 | + echo "❌ One of the milestones was not found." |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | + echo "✅ Milestone $MILESTONE_FROM = $FROM_ID" |
| 41 | + echo "✅ Milestone $MILESTONE_TO = $TO_ID" |
| 42 | + echo "🔍 Fetching open issues in milestone '$MILESTONE_FROM'..." |
| 43 | + ISSUE_NUMBERS=$(gh api "repos/$REPO/issues?state=open&milestone=$FROM_ID&per_page=100" --jq '.[].number') |
| 44 | + if [ -z "$ISSUE_NUMBERS" ]; then |
| 45 | + echo "🎉 No open issues with milestone $MILESTONE_FROM" |
| 46 | + exit 0 |
| 47 | + fi |
| 48 | + for ISSUE in $ISSUE_NUMBERS; do |
| 49 | + echo "➡️ Moving issue #$ISSUE to milestone $MILESTONE_TO" |
| 50 | + gh api -X PATCH "repos/$REPO/issues/$ISSUE" -f milestone=$TO_ID |
| 51 | + done |
| 52 | + echo "✅ Done moving issues." |
0 commit comments