I've googled this and read the GH documentation and can't see anything. I'm guessing it can't be done automatically but can probably be done with an action (which I have very limited experience with).
I would like to have an issue which automatically populates a task list with any issues which are tagged with a given label.
CodePudding user response:
You can use the GitHub CLI for this.
To get a list of all issues in a repo that have a specific label, something like this would work:
label='mylabel'
gh issue list --label "$label" --json number --jq 'map("- #\(.number)")[]'
This produces something like
- #232
- #150
which is unfurled into the full issue titles.
To update an issue, you can use
issuenum=100
gh issue edit "$issuenum" --body-file file.md
where file.md
contains what you want in the description of the issue.
To use the output of the first command directly, you can use -
as the input file:
label='mylabel'
issuenum=100
gh issue list --label "$label" --json number --jq 'map("- #\(.number)")[]' \
| gh issue edit "$issuenum" --body-file -
And all of this can be done as part of a GitHub Actions workflow. For example, with a manual trigger, expecting the label and the issue to update as inputs:
name: Update issue with task list for label
on:
workflow_dispatch:
inputs:
issue:
description: Number of the issue to update
required: true
label:
description: Label to build list for
required: true
jobs:
buildlist:
name: Build task list
runs-on: ubuntu-20.04
steps:
- name: Get issues and update list
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
label: ${{ github.event.inputs.label }}
issuenum: ${{ github.event.inputs.issue }}
run: |
gh issue list --repo "$GITHUB_REPOSITORY --label "$label" \
--json number --jq 'map("- #\(.number)")[]' \
| gh issue edit "$issuenum" \
--repo "$GITHUB_REPOSITORY" --body-file -