Skip to content

Commit 41bdcba

Browse files
fix: autoassign-issue-v1.yml (#35)
1 parent 2535d15 commit 41bdcba

File tree

1 file changed

+50
-7
lines changed

1 file changed

+50
-7
lines changed

.github/workflows/autoassign-issue-v1.yml

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ jobs:
3535
triggers=("bora" "bora!" "dibs" "dibs!")
3636
3737
should_assign=false
38-
3938
for word in "${triggers[@]}"; do
4039
if [[ "$normalized_comment" == "$word" ]]; then
4140
should_assign=true
@@ -45,21 +44,53 @@ jobs:
4544
4645
echo "should_assign=$should_assign" >> "$GITHUB_OUTPUT"
4746
48-
- name: Assign issue to commenter
47+
- name: Check if issue already has assignees
48+
id: check_existing_assignees
4949
if: steps.check_comment.outputs.should_assign == 'true'
50+
env:
51+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
run: |
53+
# Fetch issue details and count assignees
54+
issue_json=$(curl -sSL \
55+
-H "Accept: application/vnd.github+json" \
56+
-H "Authorization: Bearer $GH_TOKEN" \
57+
-H "X-GitHub-Api-Version: 2022-11-28" \
58+
https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER)
59+
60+
assignee_count=$(echo "$issue_json" | jq '.assignees | length')
61+
62+
if [[ "$assignee_count" -ge 1 ]]; then
63+
echo "already_assigned=true" >> "$GITHUB_OUTPUT"
64+
else
65+
echo "already_assigned=false" >> "$GITHUB_OUTPUT"
66+
fi
67+
68+
# Build a comma-separated string of @logins of current assignees
69+
assignee_logins=$(echo "$issue_json" | jq -r '[.assignees[].login] | map("@"+.) | join(", ")')
70+
# If empty, set a friendly fallback
71+
if [[ -z "$assignee_logins" || "$assignee_logins" == "null" ]]; then
72+
assignee_logins="(no assignees)"
73+
fi
74+
75+
echo "assignee_logins=$assignee_logins" >> "$GITHUB_OUTPUT"
76+
77+
- name: Assign issue to commenter
78+
if: steps.check_comment.outputs.should_assign == 'true' && steps.check_existing_assignees.outputs.already_assigned == 'false'
79+
env:
80+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5081
run: |
5182
echo "::notice::Assigning issue #$ISSUE_NUMBER to $ASSIGNEE"
5283
53-
curl -L \
84+
curl -sSL \
5485
-X POST \
5586
-H "Accept: application/vnd.github+json" \
56-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
87+
-H "Authorization: Bearer $GH_TOKEN" \
5788
-H "X-GitHub-Api-Version: 2022-11-28" \
5889
https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER/assignees \
59-
-d '{"assignees":["${{ env.ASSIGNEE }}"]}'
90+
-d '{"assignees":["'${ASSIGNEE}'"]}'
6091
61-
- name: Create Comment
62-
if: steps.check_comment.outputs.should_assign == 'true'
92+
- name: Create Comment (assignment success)
93+
if: steps.check_comment.outputs.should_assign == 'true' && steps.check_existing_assignees.outputs.already_assigned == 'false'
6394
uses: peter-evans/[email protected]
6495
with:
6596
issue-number: ${{ env.ISSUE_NUMBER }}
@@ -69,3 +100,15 @@ jobs:
69100
70101
🇬🇧 **English**
71102
✅ Issue #${{ github.event.issue.number }} assigned to @${{ github.event.comment.user.login }}. Check the [contributing guide](${{ env.CONTRIBUTING_URL }}) for instructions on submitting your Pull Request.
103+
104+
- name: Create Comment (already assigned)
105+
if: steps.check_comment.outputs.should_assign == 'true' && steps.check_existing_assignees.outputs.already_assigned == 'true'
106+
uses: peter-evans/[email protected]
107+
with:
108+
issue-number: ${{ env.ISSUE_NUMBER }}
109+
body: |
110+
🇧🇷 **Português**
111+
⚠️ Issue #${{ github.event.issue.number }} já está atribuída a ${{ steps.check_existing_assignees.outputs.assignee_logins }}. Se você acredita que deveria ser reatribuída, converse com a pessoa atual ou com os mantenedores.
112+
113+
🇬🇧 **English**
114+
⚠️ Issue #${{ github.event.issue.number }} is already assigned to ${{ steps.check_existing_assignees.outputs.assignee_logins }}. If you think it should be reassigned, please coordinate with the current assignee or the maintainers.

0 commit comments

Comments
 (0)