Files
prismlauncher-crack/.github/actions/delete-labels/action.yml
2025-03-14 12:58:42 -07:00

102 lines
3.2 KiB
YAML

name: Delete Label(s)
description: delete Label(s)
inputs:
gh_token:
description: gh api access token to use
required: true
repository:
description: the OWNER/REPOSITORY to operate on
default: ${{ github.repository }}
labels:
description: a single or comma separated list of labels to delete
required: true
runs:
using: "composite"
steps:
- name: Collect Repo Labels
id: collect_labels
shell: bash
env:
GH_TOKEN: ${{ inputs.gh_token }}
REPOSITORY: ${{ inputs.repository }}
LABELS: ${{ inputs.labels }}
run: |
owner=$(echo "$REPOSITORY" | cut -d '/' -f 1)
repo=$(echo "$REPOSITORY" | cut -d '/' -f 2)
query=$(
jq -nr \
--arg labels "$LABELS" \
'
(reduce ($labels | split (", *"; null) | .[]) as $i ([]; . + [$i])) as $labels
| "query ($owner: String!, $repo: String!) {\n" +
" repository(owner: $owner, name: $repo) {\n" +
(
reduce $labels[] as $i ([0, ""]; [
.[0] + 1,
.[1] + (
" _" + (.[0] | tostring) +
": label(name: \"" + $i + "\") {\n" +
" id\n" +
" name\n"+
" }\n"
)
])
| .[1]
)+
" }\n" +
"}"
'
)
data=$(
gh api graphql \
-f owner="$owner" \
-f repo="$repo" \
-f query="$query" \
| jq -c \
--arg labels "$LABELS" \
--arg colors "$COLORS" \
--arg defaultColor "$DEFAULT_COLOR" \
'
. as $in
| ($labels | split(", *"; null)) as $labels
| (
reduce (
$in.data.repository[]
| select( objects | .name as $name | any($labels[]; . == $name ) )
) as $i ({}; .[$i.name] = {"id": $i.id})
) as $found
| [$found[].id]
'
)
echo "label_ids=$data" >> "$GITHUB_OUTPUT"
echo "num_labels=$(jq -r 'length' <<< "$data")" >> "$GITHUB_OUTPUT"
- name: Delete Labels
id: delete_labels
shell: bash
if: fromJSON( steps.collect_labels.outputs.num_labels ) > 0
env:
GH_TOKEN: ${{ inputs.gh_token }}
LABELS: ${{ steps.collect_labels.outputs.label_ids }}
run: |
query=$(jq -r '
. as $in
| (
"mutation {\n" + (
reduce $in[] as $id ([0, ""]; [
.[0] + 1 ,
.[1] + (
" _" + (.[0] | tostring) + ": deleteLabel(input: {id: \"" + $id + "\"}) {\n" +
" clientMutationId\n" +
" }\n"
)
])
| .[1]
) +
"}"
)
' <<< "$LABELS"
)
gh api graphql -f query="$query"