error-db.yml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. name: Update Error Database
  2. on:
  3. discussion:
  4. types: [created, edited, deleted, 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. if: github.event_name == 'discussion_comment' || github.event_name == 'discussion' && github.event.action != 'deleted'
  14. id: query-data
  15. uses: actions/github-script@v7
  16. with:
  17. script: |
  18. const query = `query ($owner: String!, $name: String!, $discussionNumber: Int!) {
  19. repository(owner: $owner, name: $name) {
  20. discussion(number: $discussionNumber) {
  21. id
  22. upvoteCount
  23. title
  24. url
  25. answer {
  26. url
  27. upvoteCount
  28. }
  29. comments {
  30. totalCount
  31. }
  32. }
  33. }
  34. }`;
  35. const variables = {
  36. owner: context.repo.owner,
  37. name: context.repo.repo,
  38. discussionNumber: context.payload.discussion.number
  39. }
  40. return await github.graphql(query, variables)
  41. - name: Get Gist
  42. id: get-gist
  43. uses: andymckay/get-gist-action@master
  44. with:
  45. gistURL: https://gist.github.com/cryptobot/accba9fb9555e7192271b85606f97230
  46. - name: Merge Error Code Data
  47. run: |
  48. jq -c '.' ${{ steps.get-gist.outputs.file }} > original.json
  49. if [ ! -z "$DISCUSSION" ]
  50. then
  51. echo $DISCUSSION | jq -c '.repository.discussion | .comments = .comments.totalCount | {(.id|tostring) : .}' > new.json
  52. jq -s '.[0] * .[1]' original.json new.json > merged.json
  53. else
  54. cat original.json | jq 'del(.[] | select(.url=="https://github.com/cryptomator/cryptomator/discussions/${{ github.event.discussion.number }}"))' > merged.json
  55. fi
  56. env:
  57. DISCUSSION: ${{ steps.query-data.outputs.result }}
  58. - name: Patch Gist
  59. uses: exuanbo/actions-deploy-gist@v1
  60. with:
  61. token: ${{ secrets.CRYPTOBOT_GIST_TOKEN }}
  62. gist_id: accba9fb9555e7192271b85606f97230
  63. gist_file_name: errorcodes.json
  64. file_path: merged.json