|
6 | 6 | GITHUB_TOKEN: |
7 | 7 | description: 'GitHub token' |
8 | 8 | required: true |
| 9 | + suffix: |
| 10 | + description: 'Suffix to append to the gitmoji label' |
| 11 | + required: true |
| 12 | + default: '_gitmoji' |
| 13 | + cleanup_other_gitmoji_labels: |
| 14 | + description: 'Remove gitmoji labels with different suffixes from this PR' |
| 15 | + required: false |
| 16 | + default: 'false' |
9 | 17 |
|
10 | 18 | runs: |
11 | 19 | using: "composite" |
@@ -41,42 +49,72 @@ runs: |
41 | 49 | env: |
42 | 50 | GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} |
43 | 51 | run: | |
| 52 | + suffix="${{ inputs.suffix }}" |
44 | 53 | echo ${{steps.get-gitmoji.outputs.gitmoji}} |
45 | 54 | |
46 | 55 | # try to create label with gitmoji_clean and if it fails create with gitmoji_clean_nv |
47 | 56 | |
48 | | - (gh label list --json name | jq -er '.[] | select(.name | test("${{steps.get-gitmoji.outputs.gitmoji_clean}}_gitmoji")) | .name' || gh label create ${{steps.get-gitmoji.outputs.gitmoji_clean}}_gitmoji -c "$(openssl rand -hex 3)" -d "PRs with ${{steps.outputs.get-gitmoji.outputs.gitmoji_clean}}_gitmoji" --force) || (gh label create ${{steps.get-gitmoji.outputs.gitmoji_clean_nv}}_gitmoji -c "$(openssl rand -hex 3)" -d "PRs with ${{steps.outputs.get-gitmoji.outputs.gitmoji_clean_nv}}_gitmoji" --force) |
| 57 | + (gh label list --json name | jq -er --arg gitmoji "${{steps.get-gitmoji.outputs.gitmoji_clean}}" --arg suffix "$suffix" '.[] | select(.name | test("\($gitmoji)$suffix")) | .name' || gh label create "${{steps.get-gitmoji.outputs.gitmoji_clean}}$suffix" -c "$(openssl rand -hex 3)" -d "PRs with ${{steps.get-gitmoji.outputs.gitmoji_clean}}$suffix" --force) || (gh label create "${{steps.get-gitmoji.outputs.gitmoji_clean_nv}}$suffix" -c "$(openssl rand -hex 3)" -d "PRs with ${{steps.get-gitmoji.outputs.gitmoji_clean_nv}}$suffix" --force) |
49 | 58 | |
50 | 59 | - name: Check if PR already has the correct label |
51 | 60 | id: check-existing-label |
52 | 61 | shell: bash |
53 | 62 | env: |
54 | 63 | GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} |
55 | 64 | run: | |
| 65 | + suffix="${{ inputs.suffix }}" |
56 | 66 | gh pr checkout ${{ github.event.pull_request.number }} |
57 | 67 | # Check for primary gitmoji label |
58 | | - if gh pr view --json labels -q '.labels[].name' | grep -q "${{steps.get-gitmoji.outputs.gitmoji_clean}}_gitmoji"; then |
59 | | - echo "PR already has the correct gitmoji label (${{steps.get-gitmoji.outputs.gitmoji_clean}}_gitmoji)" |
| 68 | + if gh pr view --json labels -q '.labels[].name' | grep -q "${{steps.get-gitmoji.outputs.gitmoji_clean}}$suffix"; then |
| 69 | + echo "PR already has the correct gitmoji label (${{steps.get-gitmoji.outputs.gitmoji_clean}}$suffix)" |
60 | 70 | echo "has_correct_label=true" >> $GITHUB_OUTPUT |
61 | 71 | # Check for alternative gitmoji label (no variation selectors) |
62 | | - elif gh pr view --json labels -q '.labels[].name' | grep -q "${{steps.get-gitmoji.outputs.gitmoji_clean_nv}}_gitmoji"; then |
63 | | - echo "PR already has the correct gitmoji label (${{steps.get-gitmoji.outputs.gitmoji_clean_nv}}_gitmoji)" |
| 72 | + elif gh pr view --json labels -q '.labels[].name' | grep -q "${{steps.get-gitmoji.outputs.gitmoji_clean_nv}}$suffix"; then |
| 73 | + echo "PR already has the correct gitmoji label (${{steps.get-gitmoji.outputs.gitmoji_clean_nv}}$suffix)" |
64 | 74 | echo "has_correct_label=true" >> $GITHUB_OUTPUT |
65 | 75 | else |
66 | 76 | echo "PR does not have the correct gitmoji label" |
67 | 77 | echo "has_correct_label=false" >> $GITHUB_OUTPUT |
68 | 78 | fi |
69 | 79 |
|
70 | | - - name: remove labels ending in _gitmoji from PR |
| 80 | + - name: Clean up gitmoji labels with different suffixes |
| 81 | + id: cleanup-old-suffix |
| 82 | + if: inputs.cleanup_other_gitmoji_labels == 'true' |
| 83 | + shell: bash |
| 84 | + env: |
| 85 | + GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} |
| 86 | + run: | |
| 87 | + suffix="${{ inputs.suffix }}" |
| 88 | + current_gitmoji_clean="${{steps.get-gitmoji.outputs.gitmoji_clean}}" |
| 89 | + current_gitmoji_clean_nv="${{steps.get-gitmoji.outputs.gitmoji_clean_nv}}" |
| 90 | + gh pr checkout ${{ github.event.pull_request.number }} |
| 91 | + echo "Cleaning up gitmoji labels with different suffixes..." |
| 92 | + gh pr view --json labels -q '.labels[].name' | tr -d '"' | while read -r label; do |
| 93 | + # Check if label matches current gitmoji but doesn't have current suffix |
| 94 | + if [[ "$label" == "$current_gitmoji_clean"* && "$label" != "$current_gitmoji_clean$suffix" ]] || |
| 95 | + [[ "$label" == "$current_gitmoji_clean_nv"* && "$label" != "$current_gitmoji_clean_nv$suffix" ]]; then |
| 96 | + echo "Removing outdated gitmoji label: $label" |
| 97 | + gh pr edit --remove-label "$label" |
| 98 | + fi |
| 99 | + done |
| 100 | +
|
| 101 | + - name: remove labels ending in current suffix from PR |
71 | 102 | id: remove-label |
72 | 103 | if: steps.check-existing-label.outputs.has_correct_label != 'true' |
73 | 104 | shell: bash |
74 | 105 | env: |
75 | 106 | GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} |
76 | 107 | run: | |
| 108 | + suffix="${{ inputs.suffix }}" |
77 | 109 | gh pr checkout ${{ github.event.pull_request.number }} |
78 | | - gh pr view --json labels -q '.labels[] | select(.name | endswith("_gitmoji")) | .name' | tr -d '"' | while read -r label; do |
79 | | - gh pr edit --remove-label $label |
| 110 | + # Get all labels ending with suffix and store in array |
| 111 | + mapfile -t labels_to_remove < <(gh pr view --json labels -q --arg suffix "$suffix" '.labels[] | select(.name | endswith($suffix)) | .name') |
| 112 | + # Remove each label |
| 113 | + for label in "${labels_to_remove[@]}"; do |
| 114 | + if [ -n "$label" ]; then |
| 115 | + echo "Removing label: $label" |
| 116 | + gh pr edit --remove-label "$label" || true |
| 117 | + fi |
80 | 118 | done |
81 | 119 | - name: Add label to PR |
82 | 120 | id: add-label |
|
85 | 123 | env: |
86 | 124 | GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} |
87 | 125 | run: | |
| 126 | + suffix="${{ inputs.suffix }}" |
88 | 127 | gh pr checkout ${{ github.event.pull_request.number }} |
89 | | - gh pr edit --add-label ${{steps.get-gitmoji.outputs.gitmoji_clean}}_gitmoji || gh pr edit --add-label ${{steps.get-gitmoji.outputs.gitmoji_clean_nv}}_gitmoji |
| 128 | + gh pr edit --add-label "${{steps.get-gitmoji.outputs.gitmoji_clean}}$suffix" || gh pr edit --add-label "${{steps.get-gitmoji.outputs.gitmoji_clean_nv}}$suffix" |
90 | 129 |
|
91 | 130 | branding: |
92 | 131 | icon: 'check-circle' |
|
0 commit comments