error-db.yml 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. title
  21. url
  22. answer {
  23. url
  24. }
  25. comments {
  26. totalCount
  27. }
  28. }
  29. }
  30. }`;
  31. const variables = {
  32. owner: context.repo.owner,
  33. name: context.repo.repo,
  34. discussionNumber: context.payload.discussion.number
  35. }
  36. return await github.graphql(query, variables)
  37. - name: Get Gist
  38. id: get-gist
  39. uses: andymckay/get-gist-action@master
  40. with:
  41. gistURL: https://gist.github.com/cryptobot/accba9fb9555e7192271b85606f97230
  42. - name: Show Gist contents
  43. id: run
  44. run: |
  45. cat ${{ steps.get-gist.outputs.file }}
  46. - name: Merge Error Code Data
  47. run: |
  48. jq -c '.' ${{ steps.get-gist.outputs.file }} > original.json
  49. echo $DISCUSSION | jq -c '.repository.discussion | .comments = .comments.totalCount' | .answer = .answer.url | {(.title|tostring) : .}' > new.json
  50. jq -s '.[0] * .[1]' new.json original.json > merged.json
  51. env:
  52. DISCUSSION: ${{ steps.query-data.outputs.result }}
  53. - name: Patch Gist
  54. uses: exuanbo/actions-deploy-gist@v1
  55. with:
  56. token: ${{ secrets.CRYPTOBOT_GIST_TOKEN }}
  57. gist_id: accba9fb9555e7192271b85606f97230
  58. gist_file_name: errorcodes.json
  59. file_path: merged.json