Repository navigation
64 lines (60 loc) · 2.34 KB
/
Copy pathhelp-wanted-label.yml
File metadata and controls
64 lines (60 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
name: contributor label policy
on:
issues:
types: [opened, reopened, labeled]
schedule:
- cron: "13,43 * * * *"
workflow_dispatch:
inputs:
issue_number:
description: Issue or pull request number to reconcile
required: true
type: string
permissions: {}
concurrency:
group: ${{ github.workflow }}-${{ github.event.issue.number || inputs.issue_number || 'pull-requests' }}
cancel-in-progress: false
jobs:
label:
name: Mirror help wanted labels
if: github.repository == 'ClickHouse/loom'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
issues: write # The additive labels endpoint also handles pull requests.
steps:
- name: Add the contributor discovery label when needed
env:
GH_TOKEN: ${{ github.token }}
GH_HOST: github.com
ITEM_NUMBER: ${{ github.event.issue.number || inputs.issue_number }}
shell: bash
run: |
mirror_label() {
local number="$1" issue_path current
if ! [[ "$number" =~ ^[1-9][0-9]{0,9}$ ]]; then
echo "A positive issue or pull request number is required." >&2
exit 1
fi
issue_path="repos/ClickHouse/loom/issues/$number"
current=$(timeout 30s gh api "$issue_path" --jq '[.labels[].name]')
jq -e 'type == "array" and all(.[]; type == "string")' <<< "$current" >/dev/null
if jq -e 'index("help wanted") != null and index("up-for-grabs") == null' <<< "$current" >/dev/null; then
printf '%s\n' '{"labels":["up-for-grabs"]}' |
timeout 30s gh api "$issue_path/labels" --method POST --input - >/dev/null
echo "Added up-for-grabs."
else
echo "No label addition is needed."
fi
}
if [ "$GITHUB_EVENT_NAME" = schedule ]; then
pending=$(timeout 2m gh api 'repos/ClickHouse/loom/issues?state=open&labels=help%20wanted&per_page=100' --paginate \
--jq '.[] | select(has("pull_request") and ([.labels[].name] | index("up-for-grabs") == null)) | .number')
if [ -n "$pending" ]; then
while IFS= read -r number; do
mirror_label "$number"
done <<< "$pending"
fi
else
mirror_label "$ITEM_NUMBER"
fi