Skip to content

Transfer issues

Transfer issues #40

Workflow file for this run

name: Transfer issues
# To run this action.
# 1. Create a personal access token (Classic) with the `repo` and `read:org` scopes.defaults:
# 2. Create a secret in the repository with whatever name you want, and paste the token as the value.
# 3. Run the action with the secret name as the `secret_name` input.
#
# Ex: gh secret set MY_TOKEN --body "<token_value>" && gh workflow run 90730614 --field count="10" --field from_name="addons-server" --field secret_name="MY_TOKEN"
#
# Note: you need to paste the PAT in body, so make sure to keep track of the value before saving it.
# Also verify the workflow ID is correct. You can run without arguments and select interactively.
#
# Note: After each run this action purges the secret from the repo action secrets.
# This prevents pollution or conflict. So you have to reset it every time.
on:
workflow_dispatch:
inputs:
count:
description: How many issues to transfer
default: "1"
required: true
from_name:
description: "the name of the mozilla/<from_name repository to transfer issues from"
required: true
secret_name:
description: "the name of the secret containing the PAT for the repository to transfer issues to"
required: true
permissions: write-all
env:
ALLOWED_REPOS: "addons-server,addons-frontend"
concurrency:
group: transfer
cancel-in-progress: true
jobs:
fetch_issues:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: meta
shell: bash
run: |
echo "from_repo=${{ github.server_url }}/${{ github.repository_owner }}/${{ inputs.from_name }}" >> $GITHUB_OUTPUT
echo "to_repo=${{ github.server_url }}/${{ github.repository }}" >> $GITHUB_OUTPUT
echo "repo_label=repository:${{ inputs.from_name }}" >> $GITHUB_OUTPUT
- name: Transfer issues
env:
GH_TOKEN: ${{ secrets[format('{0}', inputs.secret_name)] }}
shell: bash
run: |
set -x
echo "token: $GH_TOKEN"
gh auth status
if [[ ! "${{ env.ALLOWED_REPOS }}" =~ (^|,)"${{ inputs.from_name }}"(,|$) ]]; then
echo "Invalid from_name "${{ inputs.from_name }}". Exiting..."
exit 1
fi
gh label clone ${{ steps.meta.outputs.from_repo }} -R ${{ steps.meta.outputs.to_repo }} --force
gh label create ${{ steps.meta.outputs.repo_label }} -R ${{ steps.meta.outputs.to_repo }} --force
transfer_issue() {
original_issue_url=$1
from_repo=$2
to_repo=$3
repo_label=$4
echo "$original_issue_url" >> old-issues.txt
new_issue_url=$(gh issue transfer -R $from_repo "$original_issue_url" "$to_repo")
echo "$new_issue_url" >> new-issues.txt
echo "Transferred issue $original_issue_url to $new_issue_url"
gh issue -R $to_repo edit $new_issue_url --add-label $repo_label
}
export -f transfer_issue
echo "Transferring issues from \"${{ steps.meta.outputs.from_repo }}\" to \"${{ steps.meta.outputs.to_repo }}\""
gh api graphql -f query='query {
repository(owner: "${{ github.repository_owner }}", name: "${{ inputs.from_name }}") {
issues(first: ${{ inputs.count }}, orderBy: {field: CREATED_AT, direction: ASC}) {
nodes {
url
}
}
}
}' --jq '.data.repository.issues.nodes[].url' | xargs -P 4 -I % bash -c -e 'transfer_issue % '"${{ steps.meta.outputs.from_repo }}"' '"${{ steps.meta.outputs.to_repo }}"' '"${{ steps.meta.outputs.repo_label }}"''
cat old-issues.txt
cat new-issues.txt
- name: Delete secret
if: always()
shell: bash
env:
GH_TOKEN: ${{ secrets[format('{0}', inputs.secret_name)] }}
run: |
set -x
if gh secret list --json name --jq '.[] | .name' | grep -q "${{ inputs.secret_name }}"; then
gh secret delete ${{ inputs.secret_name }}
fi