duplicate-issues.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. name: duplicate-issues
  2. on:
  3. issues:
  4. types: [opened, edited]
  5. jobs:
  6. check-duplicates:
  7. if: github.event.action == 'opened'
  8. runs-on: blacksmith-4vcpu-ubuntu-2404
  9. permissions:
  10. contents: read
  11. issues: write
  12. steps:
  13. - name: Checkout repository
  14. uses: actions/checkout@v4
  15. with:
  16. fetch-depth: 1
  17. - name: Install opencode
  18. run: curl -fsSL https://opencode.ai/install | bash
  19. - name: Check duplicates and compliance
  20. env:
  21. OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
  22. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  23. OPENCODE_PERMISSION: |
  24. {
  25. "bash": "deny",
  26. "webfetch": "deny",
  27. "edit": "deny",
  28. "write": "deny"
  29. }
  30. ISSUE_NUMBER: ${{ github.event.issue.number }}
  31. REPO: ${{ github.repository }}
  32. run: |
  33. ISSUE_TITLE=$(gh issue view "$ISSUE_NUMBER" --repo "$REPO" --json title --jq .title)
  34. ISSUE_BODY=$(gh issue view "$ISSUE_NUMBER" --repo "$REPO" --json body --jq .body)
  35. PROMPT=$(cat <<EOF
  36. Check this new issue for compliance and duplicates:
  37. CURRENT_ISSUE_NUMBER: $ISSUE_NUMBER
  38. Title: $ISSUE_TITLE
  39. Description:
  40. $ISSUE_BODY
  41. EOF
  42. )
  43. COMMENT=$(opencode run --agent duplicate-issue "$PROMPT")
  44. if [ "$COMMENT" = "No action required" ]; then
  45. exit 0
  46. fi
  47. BODY="_The following comment was made by an LLM, it may be inaccurate:_
  48. $COMMENT"
  49. gh issue comment "$ISSUE_NUMBER" --repo "$REPO" --body "$BODY"
  50. if [[ "$COMMENT" == *"<!-- issue-compliance -->"* ]]; then
  51. gh issue edit "$ISSUE_NUMBER" --repo "$REPO" --add-label needs:compliance
  52. fi
  53. recheck-compliance:
  54. if: github.event.action == 'edited' && contains(github.event.issue.labels.*.name, 'needs:compliance')
  55. runs-on: blacksmith-4vcpu-ubuntu-2404
  56. permissions:
  57. contents: read
  58. issues: write
  59. steps:
  60. - name: Checkout repository
  61. uses: actions/checkout@v4
  62. with:
  63. fetch-depth: 1
  64. - name: Install opencode
  65. run: curl -fsSL https://opencode.ai/install | bash
  66. - name: Recheck compliance
  67. env:
  68. OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
  69. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  70. OPENCODE_PERMISSION: |
  71. {
  72. "bash": "deny",
  73. "webfetch": "deny",
  74. "edit": "deny",
  75. "write": "deny"
  76. }
  77. ISSUE_NUMBER: ${{ github.event.issue.number }}
  78. REPO: ${{ github.repository }}
  79. run: |
  80. ISSUE_TITLE=$(gh issue view "$ISSUE_NUMBER" --repo "$REPO" --json title --jq .title)
  81. ISSUE_BODY=$(gh issue view "$ISSUE_NUMBER" --repo "$REPO" --json body --jq .body)
  82. PROMPT=$(cat <<EOF
  83. Recheck this edited issue for compliance:
  84. MODE: recheck-compliance
  85. CURRENT_ISSUE_NUMBER: $ISSUE_NUMBER
  86. Title: $ISSUE_TITLE
  87. Description:
  88. $ISSUE_BODY
  89. EOF
  90. )
  91. COMMENT=$(opencode run --agent duplicate-issue "$PROMPT")
  92. if [ "$COMMENT" = "No action required" ]; then
  93. gh issue edit "$ISSUE_NUMBER" --repo "$REPO" --remove-label needs:compliance || true
  94. IDS=$(gh api "repos/$REPO/issues/$ISSUE_NUMBER/comments" --jq '.[] | select(.body | contains("<!-- issue-compliance -->")) | .id')
  95. for id in $IDS; do
  96. gh api -X DELETE "repos/$REPO/issues/comments/$id"
  97. done
  98. gh issue comment "$ISSUE_NUMBER" --repo "$REPO" --body "Thanks for updating your issue. It now meets our contributing guidelines. :+1:"
  99. exit 0
  100. fi
  101. gh issue edit "$ISSUE_NUMBER" --repo "$REPO" --add-label needs:compliance
  102. BODY="_The following comment was made by an LLM, it may be inaccurate:_
  103. $COMMENT"
  104. EXISTING=$(gh api "repos/$REPO/issues/$ISSUE_NUMBER/comments" --jq '[.[] | select(.body | contains("<!-- issue-compliance -->")) | .id] | last // empty')
  105. if [ -n "$EXISTING" ]; then
  106. gh api -X PATCH "repos/$REPO/issues/comments/$EXISTING" -f body="$BODY"
  107. exit 0
  108. fi
  109. gh issue comment "$ISSUE_NUMBER" --repo "$REPO" --body "$BODY"