Skip to content

build(deps-dev): Bump the typescript-eslint group with 3 updates #312

build(deps-dev): Bump the typescript-eslint group with 3 updates

build(deps-dev): Bump the typescript-eslint group with 3 updates #312

# Label Linked Issues
#
# Add the `status:merged`, `status:prereleased`, or `status:released` label to a pull request's
# linked issues when a pull request is merged into `main` or on workflow dispatch.
#
# References:
#
# - https://docs.github.com/actions/learn-github-actions/contexts
# - https://docs.github.com/actions/learn-github-actions/expressions
# - https://docs.github.com/actions/using-workflows/events-that-trigger-workflows#pull_request
# - https://docs.github.com/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
# - https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions
# - https://docs.github.com/graphql/overview/explorer
# - https://docs.github.com/graphql/reference/objects#pullrequest
# - https://docs.github.com/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request
# - https://docs.github.com/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_dispatch
# - https://github.com/actions/github-script
# - https://github.com/hmarr/debug-action
# - https://github.com/octokit/graphql-action
---
name: label-linked-issues
on:
pull_request:
branches:
- main
types:
- closed
workflow_dispatch:
inputs:
pr:
description: pull request number
required: true
type: number
permissions:
issues: write
jobs:
label-linked-issues:
if: github.event_name == 'workflow_dispatch' || github.event.pull_request.merged
runs-on: ubuntu-latest
steps:
- id: debug
name: Print environment variables and event payload
uses: hmarr/[email protected]
- id: checkout
name: Checkout main
uses: actions/[email protected]
with:
persist-credentials: false
ref: main
- id: version
name: Get project version
run: echo "result=$(jq .version package.json -r)" >>$GITHUB_OUTPUT
- id: query
name: Query linked issues
uses: octokit/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
query: |
query ($limit: Int = 20, $owner: String!, $pr: Int!, $repo: String!) {
repository(name: $repo, owner: $owner) {
pullRequest(number: $pr) {
closingIssuesReferences(
first: $limit
orderBy: { direction: ASC, field: CREATED_AT }
) {
edges {
node {
number
}
}
}
}
}
}
owner: ${{ github.repository_owner }}
pr: ${{ inputs.pr || github.event.number }}
repo: ${{ github.event.repository.name }}
- id: label
name: Label linked issues
uses: actions/[email protected]
env:
DATA: ${{ steps.query.outputs.data }}
PRERELEASE: ${{ contains(steps.version.outputs.result, '-') }}
RELEASE_BRANCH: ${{ contains(github.head_ref || github.ref_name, 'release/') }}
with:
script: |
const { closingIssuesReferences } = JSON.parse(process.env.DATA).repository.pullRequest
const issues = closingIssuesReferences.edges.map(edge => edge.node.number)
const release = JSON.parse(process.env.RELEASE_BRANCH || 'false')
const prerelease = JSON.parse(process.env.PRERELEASE || 'false')
for (const issue_number of issues) {
await github.rest.issues.addLabels({
...context.repo,
issue_number,
labels: [release ? `status:${prerelease ? 'pre' : ''}released` : 'status:merged']
})
}