Skip to content

Move Project Cards by /command #620

Move Project Cards by /command

Move Project Cards by /command #620

on:
issue_comment:
types: [created]
name: Move Project Cards by /command
jobs:
validate_and_get_card:
name: Validate command and get project card info
runs-on: ubuntu-latest
permissions:
issues: read
# Run the job only if the new comment starts with '/'
if: |
!github.event.issue.pull_request && startsWith(github.event.comment.body, '/')
outputs:
valid_command: ${{ steps.command_check.outputs.valid_command }}
command: ${{ steps.command_check.outputs.command }}
target_status: ${{ steps.command_check.outputs.target_status }} # Which status to move the card to
card_id: ${{ steps.get_card.outputs.card_id }}
project_url: ${{ steps.get_card.outputs.project_url }}
project_name: ${{ steps.get_card.outputs.project_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Validate command
id: command_check
uses: actions/github-script@v7
with:
script: |
const script = require('./scripts/validateCommand.js');
await script.main({github, context, core});
- name: Get project card
id: get_card
if: steps.command_check.outputs.valid_command == 'true'
uses: actions/github-script@v7
with:
script: |
const script = require('./scripts/getProjectCard.js');
await script.main({github, context, core});
github-token: ${{ secrets.MOVE_CARDS_TOKEN }}
assign_issue:
name: Assign issue and update project card
needs: validate_and_get_card
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Add comment for invalid command # Reply to the user if the command was invalid
if: needs.validate_and_get_card.outputs.valid_command != 'true'
uses: actions/github-script@v7
env:
USER_LOGIN: ${{ github.event.comment.user.login }}
with:
script: |
const issueComment = `
@${process.env.USER_LOGIN} The command was invalid. The comment must start with /postedit or /review.
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: issueComment
});
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout # Checkout the scripts in this repo onto the runner
if: needs.validate_and_get_card.outputs.valid_command == 'true'
uses: actions/checkout@v4
- name: Assign issue to the commenter as posteditor
id: assign_posteditor
# We can remove the check for 'translate' when we move to /postedit command completely.
if: needs.validate_and_get_card.outputs.valid_command == 'true' && (needs.validate_and_get_card.outputs.command == 'postedit' || needs.validate_and_get_card.outputs.command == 'translate' )
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const script = require('./scripts/assignPosteditor.js');
await script({github, context, core});
- name: Assign issue to the reviewer
id: assign_reviewer
if: needs.validate_and_get_card.outputs.valid_command == 'true' && needs.validate_and_get_card.outputs.command == 'review'
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const script = require('./scripts/assignReviewer.js');
await script({github, context, core, projectName: '${{ needs.validate_and_get_card.outputs.project_name }}'});
- name: Update project card status
if: steps.assign_posteditor.outcome == 'success' || steps.assign_reviewer.outcome == 'success'
uses: titoportas/[email protected]
with:
project-url: ${{ needs.validate_and_get_card.outputs.project_url }}
github-token: ${{ secrets.MOVE_CARDS_TOKEN }}
item-id: ${{ needs.validate_and_get_card.outputs.card_id }}
field-keys: Status
field-values: ${{ needs.validate_and_get_card.outputs.target_status }}