Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 50 additions & 7 deletions .github/workflows/autoassign-issue-v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ jobs:
triggers=("bora" "bora!" "dibs" "dibs!")

should_assign=false

for word in "${triggers[@]}"; do
if [[ "$normalized_comment" == "$word" ]]; then
should_assign=true
Expand All @@ -45,21 +44,53 @@ jobs:

echo "should_assign=$should_assign" >> "$GITHUB_OUTPUT"

- name: Assign issue to commenter
- name: Check if issue already has assignees
id: check_existing_assignees
if: steps.check_comment.outputs.should_assign == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Fetch issue details and count assignees
issue_json=$(curl -sSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER)

assignee_count=$(echo "$issue_json" | jq '.assignees | length')

if [[ "$assignee_count" -ge 1 ]]; then
echo "already_assigned=true" >> "$GITHUB_OUTPUT"
else
echo "already_assigned=false" >> "$GITHUB_OUTPUT"
fi

# Build a comma-separated string of @logins of current assignees
assignee_logins=$(echo "$issue_json" | jq -r '[.assignees[].login] | map("@"+.) | join(", ")')
# If empty, set a friendly fallback
if [[ -z "$assignee_logins" || "$assignee_logins" == "null" ]]; then
assignee_logins="(no assignees)"
fi

echo "assignee_logins=$assignee_logins" >> "$GITHUB_OUTPUT"

- name: Assign issue to commenter
if: steps.check_comment.outputs.should_assign == 'true' && steps.check_existing_assignees.outputs.already_assigned == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "::notice::Assigning issue #$ISSUE_NUMBER to $ASSIGNEE"

curl -L \
curl -sSL \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER/assignees \
-d '{"assignees":["${{ env.ASSIGNEE }}"]}'
-d '{"assignees":["'${ASSIGNEE}'"]}'

- name: Create Comment
if: steps.check_comment.outputs.should_assign == 'true'
- name: Create Comment (assignment success)
if: steps.check_comment.outputs.should_assign == 'true' && steps.check_existing_assignees.outputs.already_assigned == 'false'
uses: peter-evans/[email protected]
with:
issue-number: ${{ env.ISSUE_NUMBER }}
Expand All @@ -69,3 +100,15 @@ jobs:

🇬🇧 **English**
✅ 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.

- name: Create Comment (already assigned)
if: steps.check_comment.outputs.should_assign == 'true' && steps.check_existing_assignees.outputs.already_assigned == 'true'
uses: peter-evans/[email protected]
with:
issue-number: ${{ env.ISSUE_NUMBER }}
body: |
🇧🇷 **Português**
⚠️ 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.

🇬🇧 **English**
⚠️ 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.