name: Issue Management Bot on: issues: types: [opened, edited, labeled, unlabeled] jobs: issue-triage: runs-on: ubuntu-latest env: API_TOKEN: ${{ secrets.BOT_ACCESS_TOKEN }} API_BASE_URL: https://git.psmattas.com/api/v1 REPO: ${{ gitea.repository }} ISSUE_NUMBER: ${{ gitea.event.issue.number }} ISSUE_AUTHOR: ${{ gitea.event.issue.user.login }} ISSUE_TITLE: ${{ gitea.event.issue.title }} ISSUE_BODY: ${{ gitea.event.issue.body }} steps: - name: Welcome new contributors if: gitea.event.action == 'opened' run: | AUTHOR_ISSUES=$(curl -s -H "Authorization: token $API_TOKEN" "$API_BASE_URL/repos/$REPO/issues?state=all&created_by=$ISSUE_AUTHOR" | jq '. | length') if [ "$AUTHOR_ISSUES" -eq 1 ]; then WELCOME_MSG="👋 Welcome @$ISSUE_AUTHOR! Thanks for opening your first issue in Evercatch!\n\nOur team will review this shortly. In the meantime:\n- Check our [documentation](https://docs.evercatch.dev) for common solutions\n- Join our [community](https://community.evercatch.dev) for discussions\n- Review our [Code of Conduct](CODE_OF_CONDUCT.md)\n\nWe appreciate your contribution! 🎉" COMMENT_JSON=$(jq -n --arg body "$WELCOME_MSG" '{"body": $body}') curl -s -f -X POST -H "Authorization: token $API_TOKEN" -H "Content-Type: application/json" -d "$COMMENT_JSON" "$API_BASE_URL/repos/$REPO/issues/$ISSUE_NUMBER/comments" fi - name: Auto-label bug reports run: | if echo "$ISSUE_TITLE" | grep -q "\[BUG\]"; then LABELS='{"labels": ["bug", "status: investigating"]}' curl -s -f -X POST -H "Authorization: token $API_TOKEN" -H "Content-Type: application/json" -d "$LABELS" "$API_BASE_URL/repos/$REPO/issues/$ISSUE_NUMBER/labels" fi - name: Auto-label feature requests run: | if echo "$ISSUE_TITLE" | grep -q "\[FEATURE\]"; then LABELS='{"labels": ["feature", "status: under-review"]}' curl -s -f -X POST -H "Authorization: token $API_TOKEN" -H "Content-Type: application/json" -d "$LABELS" "$API_BASE_URL/repos/$REPO/issues/$ISSUE_NUMBER/labels" fi - name: Auto-label support requests run: | if echo "$ISSUE_TITLE" | grep -q "\[SUPPORT\]"; then LABELS='{"labels": ["question", "status: needs-response"]}' curl -s -f -X POST -H "Authorization: token $API_TOKEN" -H "Content-Type: application/json" -d "$LABELS" "$API_BASE_URL/repos/$REPO/issues/$ISSUE_NUMBER/labels" fi - name: Auto-label documentation issues run: | if echo "$ISSUE_TITLE" | grep -q "\[DOCS\]"; then LABELS='{"labels": ["documentation", "status: under-review"]}' curl -s -f -X POST -H "Authorization: token $API_TOKEN" -H "Content-Type: application/json" -d "$LABELS" "$API_BASE_URL/repos/$REPO/issues/$ISSUE_NUMBER/labels" fi - name: Assign to team for critical bugs run: | LABELS=$(curl -s -H "Authorization: token $API_TOKEN" "$API_BASE_URL/repos/$REPO/issues/$ISSUE_NUMBER/labels") HAS_CRITICAL=$(echo "$LABELS" | jq -r '.[] | select(.name == "priority: critical") | .name') if [ -n "$HAS_CRITICAL" ]; then ASSIGNEES='{"assignees": ["psmattas"]}' curl -s -f -X PATCH -H "Authorization: token $API_TOKEN" -H "Content-Type: application/json" -d "$ASSIGNEES" "$API_BASE_URL/repos/$REPO/issues/$ISSUE_NUMBER" URGENT_MSG="🚨 **Critical Issue Detected**\n\nThis issue has been marked as critical and assigned to @psmattas for immediate attention.\n\nExpected response time: **4 hours**" COMMENT_JSON=$(jq -n --arg body "$URGENT_MSG" '{"body": $body}') curl -s -f -X POST -H "Authorization: token $API_TOKEN" -H "Content-Type: application/json" -d "$COMMENT_JSON" "$API_BASE_URL/repos/$REPO/issues/$ISSUE_NUMBER/comments" fi - name: Request more info for incomplete issues if: gitea.event.action == 'opened' run: | LABELS=$(curl -s -H "Authorization: token $API_TOKEN" "$API_BASE_URL/repos/$REPO/issues/$ISSUE_NUMBER/labels") IS_BUG=$(echo "$LABELS" | jq -r '.[] | select(.name == "bug") | .name') if [ -n "$IS_BUG" ] && ! echo "$ISSUE_BODY" | grep -q "Steps to Reproduce"; then INFO_MSG="Hi @$ISSUE_AUTHOR! 👋\n\nTo help us investigate this bug, could you please provide:\n\n1. **Steps to reproduce** the issue\n2. **Expected behavior** vs **actual behavior**\n3. Your **subscription tier**\n4. **Event IDs** or **timestamps** (if applicable)\n\nThis will help us resolve the issue faster. Thanks!" COMMENT_JSON=$(jq -n --arg body "$INFO_MSG" '{"body": $body}') curl -s -f -X POST -H "Authorization: token $API_TOKEN" -H "Content-Type: application/json" -d "$COMMENT_JSON" "$API_BASE_URL/repos/$REPO/issues/$ISSUE_NUMBER/comments" LABELS='{"labels": ["status: needs-info"]}' curl -s -f -X POST -H "Authorization: token $API_TOKEN" -H "Content-Type: application/json" -d "$LABELS" "$API_BASE_URL/repos/$REPO/issues/$ISSUE_NUMBER/labels" fi