This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
350 automatically add assignee when pr opened #17
Workflow file for this run
This file contains 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
# See https://confluence.diamond.ac.uk/x/tJqQC for instructions if this needs a new token | |
name: Assign author of pull request to referenced issue that was not assigned to issue ticket beforehand | |
on: | |
pull_request: | |
types: [ready_for_review, opened, review_requested] | |
jobs: | |
assign_pr_author_as_assignee: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get project data | |
# This will get information about the project in general and add it to the environment. | |
# * ASSIGNABLE_ID - The ID for the Issue that was referenes at Fixes#999 | |
# * AUTHOR_ID - The ID of the person who made a pull request so that the author can be assigned to the Fixes#999 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GHPROJECT_TOKEN }} | |
ORGANIZATION: ${{ github.repository_owner }} | |
REPO_ORG_NAME: ${{ github.repository }} # Contains the repo_name in format org/repo_name | |
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} | |
run: | | |
gh api graphql -f query=' | |
query ($org: String!, $repo: String!, $number: Int!) { | |
repository(owner: $org, name: $repo) { | |
pullRequest(number: $number) { | |
closingIssuesReferences(first: 1) { | |
edges { | |
node { | |
id | |
} | |
} | |
} | |
author { ... on User {id} } | |
} | |
} | |
}' -f org=$ORGANIZATION -f repo=${REPO_ORG_NAME##*/} -F number=$PULL_REQUEST_NUMBER > project_data.json | |
echo 'ASSIGNABLE_ID='$(jq '.data.repository.pullRequest.closingIssuesReferences.edges[0].node.id' project_data.json) >> $GITHUB_ENV | |
echo 'AUTHOR_ID='$(jq '.data.repository.pullRequest.author.id' project_data.json) >> $GITHUB_ENV | |
# Add assingee of pull request of the references issue/ticket | |
- name: Mutation to add name of pull request assigner to fixes ticket | |
env: | |
GITHUB_TOKEN: ${{ secrets.GHPROJECT_TOKEN }} | |
run: | | |
gh api graphql -f query=' | |
mutation ($assignable_id: ID!, $author_id: [ID!]! ){ | |
addAssigneesToAssignable(input:{assignableId: $assignable_id, assigneeIds: $author_id }) { | |
clientMutationId | |
} | |
}' -f assignable_id=$ASSIGNABLE_ID -f author_id=$AUTHOR_ID |