error-db.yml 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. name: Update Error Database
  2. on:
  3. discussion:
  4. types: [created, edited, category_changed, answered, unanswered]
  5. discussion_comment:
  6. types: [created, edited, deleted]
  7. jobs:
  8. update-error-db:
  9. runs-on: ubuntu-latest
  10. if: github.event.discussion.category.name == 'Errors'
  11. steps:
  12. - name: Query Discussion Data
  13. id: query-data
  14. uses: actions/github-script@v6
  15. with:
  16. script: |
  17. const query = `query ($owner: String!, $name: String!, $discussionNumber: Int!) {
  18. repository(owner: $owner, name: $name) {
  19. discussion(number: $discussionNumber) {
  20. id
  21. upvoteCount
  22. title
  23. url
  24. answer {
  25. url
  26. upvoteCount
  27. }
  28. comments {
  29. totalCount
  30. }
  31. }
  32. }
  33. }`;
  34. const variables = {
  35. owner: context.repo.owner,
  36. name: context.repo.repo,
  37. discussionNumber: context.payload.discussion.number
  38. }
  39. return await github.graphql(query, variables)
  40. - name: Get Gist
  41. id: get-gist
  42. uses: andymckay/get-gist-action@master
  43. with:
  44. gistURL: https://gist.github.com/cryptobot/accba9fb9555e7192271b85606f97230
  45. - name: Merge Error Code Data
  46. run: |
  47. jq -c '.' ${{ steps.get-gist.outputs.file }} > original.json
  48. echo $DISCUSSION | jq -c '.repository.discussion | .comments = .comments.totalCount | {(.id|tostring) : .}' > new.json
  49. jq -s '.[0] * .[1]' original.json new.json > merged.json
  50. env:
  51. DISCUSSION: ${{ steps.query-data.outputs.result }}
  52. - name: Patch Gist
  53. uses: exuanbo/actions-deploy-gist@v1
  54. with:
  55. token: ${{ secrets.CRYPTOBOT_GIST_TOKEN }}
  56. gist_id: accba9fb9555e7192271b85606f97230
  57. gist_file_name: errorcodes.json
  58. file_path: merged.json