Transfer Issues by Label #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Transfer Issues by Label | |
| on: | |
| issues: | |
| types: [labeled] | |
| jobs: | |
| TransferIssueByLabel: | |
| runs-on: ubuntu-latest | |
| env: | |
| # Change this "env" variables at yor convenience. | |
| # More info at: https://github.com/Astorcamon/Transfer_Issues_by_Label_Workflow | |
| LabelNames: '0 Security Risk,1 Critical,2 High' # The name of the label or labels (comma-separated) that triggers the issue transfer | |
| GITHUB_TOKEN: ${{ secrets.ACTIONSYNC }} # The personal access token (PAT) or repository secret containing the PAT. (You must create it) | |
| SourceOwner: ${{ github.repository_owner }} # The owner username of the source repository where the action runs and the issue is taken. (Default: this repo owner) | |
| SourceRepo: ${{ github.event.repository.name }} # The source repository where the action runs and the issue is taken. (Default: this repo) | |
| TargetOwner: ${{ github.repository_owner }} # The owner username of the target repository where the issue will be sent. (Default: this repo owner) | |
| TargetRepo: ${{ github.event.repository.name }}_Private # The target repository where the issue will be sent. (Default: SourceRepoName_Private) | |
| steps: | |
| - name: Determine if issue should be transferred | |
| id: check_labels | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ env.GITHUB_TOKEN }} | |
| script: | | |
| const allowed = "${{ env.LabelNames }}".split(',').map(s => s.trim().toLowerCase()); | |
| const issueLabels = context.payload.issue.labels.map(l => l.name.toLowerCase()); | |
| const match = issueLabels.some(l => allowed.includes(l)); | |
| core.setOutput("shouldRun", match); | |
| - name: Get Issue ID | |
| if: ${{ steps.check_labels.outputs.shouldRun == 'true' }} | |
| id: get_issue_id | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ env.GITHUB_TOKEN }} | |
| # Your GraphQL query, see https://developer.github.com/v4/ | |
| script: | | |
| const result = await github.graphql(` | |
| query { repository(owner: "${{ env.SourceOwner }}", name: "${{ env.SourceRepo }}") { | |
| issue(number: ${{ github.event.issue.number }}) { id } } } | |
| `); | |
| core.setOutput("issueId", result.repository.issue.id); | |
| - name: Get Target Repo ID | |
| if: ${{ steps.check_labels.outputs.shouldRun == 'true' }} | |
| id: get_target_id | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ env.GITHUB_TOKEN }} | |
| # Your GraphQL query, see https://developer.github.com/v4/ | |
| script: | | |
| const result = await github.graphql(` | |
| query { | |
| repository(owner: "${{ env.TargetOwner }}", name: "${{ env.TargetRepo }}") { id } } | |
| `); | |
| core.setOutput("repoId", result.repository.id); | |
| - name: Transfer Issue | |
| if: ${{ steps.check_labels.outputs.shouldRun == 'true' }} | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ env.GITHUB_TOKEN }} | |
| script: | | |
| const issueId = "${{ steps.get_issue_id.outputs.issueId }}"; | |
| const repoId = "${{ steps.get_target_id.outputs.repoId }}"; | |
| const result = await github.graphql(` | |
| mutation { transferIssue( input: { issueId: "${issueId}", repositoryId: "${repoId}" } ) { issue { id title } } } | |
| `); | |
| console.log("Transferred:", result.transferIssue.issue.title); |