|
| 1 | +name: Bulk migrate existing issues/PRs |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + project: |
| 7 | + description: Project board number |
| 8 | + required: true |
| 9 | + org: |
| 10 | + description: Organization that owns the project |
| 11 | + required: true |
| 12 | + repo: |
| 13 | + description: Repository to run migration on |
| 14 | + required: true |
| 15 | + |
| 16 | +env: |
| 17 | + GITHUB_TOKEN: ${{ secrets.PAT }} |
| 18 | +jobs: |
| 19 | + migrate: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + name: migrate |
| 22 | + steps: |
| 23 | + - name: Fetch project data |
| 24 | + run: | |
| 25 | + gh api graphql -f query=' |
| 26 | + query($org: String!, $num: Int!) { |
| 27 | + organization(login: $org){ |
| 28 | + projectNext(number: $num) { |
| 29 | + id |
| 30 | + fields(first: 20) { |
| 31 | + nodes { |
| 32 | + id |
| 33 | + name |
| 34 | + settings |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + }' -f org=${{ github.event.inputs.org }} -F num=${{ github.event.inputs.project }} > project_data.json |
| 40 | +
|
| 41 | + echo 'PROJECT_ID='$(jq -r '.data.organization.projectNext.id' project_data.json) >> $GITHUB_ENV |
| 42 | + echo 'STATUS_FIELD_ID='$(jq -r '.data.organization.projectNext.fields.nodes[] | select(.name == "Status").id' project_data.json) >> $GITHUB_ENV |
| 43 | + echo 'TODO_OPTION_ID='$(jq -r '.data.organization.projectNext.fields.nodes[] | select(.name == "Status").settings | fromjson.options[] | select(.name=="Todo").id' project_data.json) >> $GITHUB_ENV |
| 44 | +
|
| 45 | + - name: Store open issue/PR list |
| 46 | + run: | |
| 47 | + gh api graphql -f query=' |
| 48 | + query ($org: String!, $repo: String!) { |
| 49 | + repository(owner: $org, name: $repo) { |
| 50 | + issues: issues(states: OPEN, first: 100) { |
| 51 | + edges { |
| 52 | + node { |
| 53 | + id |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + prs: pullRequests(states: OPEN, first: 100) { |
| 58 | + edges { |
| 59 | + node { |
| 60 | + id |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + }' -f org=${{ github.event.inputs.org }} -f repo=${{ github.event.inputs.repo }} > data.json |
| 66 | +
|
| 67 | + - name: Extract issue/PR IDs and migrate |
| 68 | + run: | |
| 69 | + ISSUE_IDS=($(jq .data.repository.issues.edges[].node.id -c data.json)) |
| 70 | + PR_IDS=($(jq .data.repository.prs.edges[].node.id -c data.json)) |
| 71 | +
|
| 72 | + migrate() { |
| 73 | + ISSUE_PR_ID="$1" |
| 74 | +
|
| 75 | + ITEM_ID="$( gh api graphql -f query=' |
| 76 | + mutation($project: ID!, $id: ID!) { |
| 77 | + addProjectNextItem(input: { |
| 78 | + projectId: $project, |
| 79 | + contentId: $id, |
| 80 | + }) { |
| 81 | + projectNextItem { |
| 82 | + id |
| 83 | + } |
| 84 | + } |
| 85 | + }' -f project=$PROJECT_ID -f id=$ISSUE_PR_ID --jq '.data.addProjectNextItem.projectNextItem.id')" |
| 86 | +
|
| 87 | + gh api graphql -f query=' |
| 88 | + mutation ( |
| 89 | + $project: ID! |
| 90 | + $item: ID! |
| 91 | + $status_field: ID! |
| 92 | + $status_value: String! |
| 93 | + ) { |
| 94 | + updateProjectNextItemField(input: { |
| 95 | + projectId: $project |
| 96 | + itemId: $item |
| 97 | + fieldId: $status_field |
| 98 | + value: $status_value |
| 99 | + }) { |
| 100 | + projectNextItem { |
| 101 | + id |
| 102 | + } |
| 103 | + } |
| 104 | + }' -f project=$PROJECT_ID -f item=$ITEM_ID -f status_field=$STATUS_FIELD_ID -f status_value=$TODO_OPTION_ID |
| 105 | + } |
| 106 | +
|
| 107 | + printf "\nMigrating issues...\n" |
| 108 | + for id in "${ISSUE_IDS[@]}"; do |
| 109 | + migrate "$id" |
| 110 | + done |
| 111 | +
|
| 112 | + printf "\nMigrating PRs...\n" |
| 113 | + for id in "${PR_IDS[@]}"; do |
| 114 | + migrate "$id" |
| 115 | + done |
0 commit comments