project.yml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. name: Project tracking
  2. on:
  3. issues:
  4. types: [opened]
  5. pull_request_target:
  6. types: [opened, synchronize]
  7. concurrency:
  8. group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  9. cancel-in-progress: true
  10. jobs:
  11. add-to-project:
  12. name: Add to project
  13. runs-on: ubuntu-latest
  14. if: github.repository == 'ohmyzsh/ohmyzsh'
  15. env:
  16. GITHUB_TOKEN: ${{ secrets.PROJECT_TOKEN }}
  17. steps:
  18. - name: Read project data
  19. env:
  20. ORGANIZATION: ohmyzsh
  21. PROJECT_NUMBER: "1"
  22. run: |
  23. # Get Project data
  24. gh api graphql -f query='
  25. query($org: String!, $number: Int!) {
  26. organization(login: $org){
  27. projectNext(number: $number) {
  28. id
  29. fields(first:20) {
  30. nodes {
  31. id
  32. name
  33. }
  34. }
  35. }
  36. }
  37. }
  38. ' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
  39. # Parse project data
  40. cat >> $GITHUB_ENV <<EOF
  41. PROJECT_ID=$(jq '.data.organization.projectNext.id' project_data.json)
  42. PLUGIN_FIELD_ID=$(jq '.data.organization.projectNext.fields.nodes[] | select(.name == "Plugin") | .id' project_data.json)
  43. THEME_FIELD_ID=$(jq '.data.organization.projectNext.fields.nodes[] | select(.name == "Theme") | .id' project_data.json)
  44. EOF
  45. - name: Add to project
  46. env:
  47. ISSUE_OR_PR_ID: ${{ github.event.issue.node_id || github.event.pull_request.node_id }}
  48. run: |
  49. item_id="$(gh api graphql -f query='
  50. mutation($project: ID!, $content: ID!) {
  51. addProjectNextItem(input: {projectId: $project, contentId: $content}) {
  52. projectNextItem {
  53. id
  54. }
  55. }
  56. }
  57. ' -f project=$PROJECT_ID -f content=$ISSUE_OR_PR_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
  58. echo "ITEM_ID=$item_id" >> $GITHUB_ENV
  59. - name: Classify Pull Request
  60. if: github.event_name == 'pull_request_target'
  61. run: |
  62. touch plugins.list themes.list
  63. gh pr view ${{ github.event.pull_request.number }} \
  64. --repo ${{ github.repository }} \
  65. --json files --jq '.files.[].path' | awk -F/ '
  66. /^plugins\// {
  67. plugins[$2] = 1
  68. }
  69. /^themes\// {
  70. gsub(/\.zsh-theme$/, "", $2)
  71. themes[$2] = 1
  72. }
  73. END {
  74. for (plugin in plugins) {
  75. print plugin >> "plugins.list"
  76. }
  77. for (theme in themes) {
  78. print theme >> "themes.list"
  79. }
  80. }
  81. '
  82. # If only one plugin is modified, add it to the plugin field
  83. if [[ $(wc -l < plugins.list) = 1 ]]; then
  84. echo "PLUGIN=$(cat plugins.list)" >> $GITHUB_ENV
  85. fi
  86. # If only one theme is modified, add it to the theme field
  87. if [[ $(wc -l < themes.list) = 1 ]]; then
  88. echo "THEME=$(cat themes.list)" >> $GITHUB_ENV
  89. fi
  90. - name: Fill Pull Request fields in project
  91. if: github.event_name == 'pull_request_target'
  92. run: |
  93. gh api graphql -f query='
  94. mutation (
  95. $project: ID!
  96. $item: ID!
  97. $plugin_field: ID!
  98. $plugin_value: String!
  99. $theme_field: ID!
  100. $theme_value: String!
  101. ) {
  102. set_plugin: updateProjectNextItemField(input: {
  103. projectId: $project
  104. itemId: $item
  105. fieldId: $plugin_field
  106. value: $plugin_value
  107. }) {
  108. projectNextItem {
  109. id
  110. }
  111. }
  112. set_theme: updateProjectNextItemField(input: {
  113. projectId: $project
  114. itemId: $item
  115. fieldId: $theme_field
  116. value: $theme_value
  117. }) {
  118. projectNextItem {
  119. id
  120. }
  121. }
  122. }
  123. ' -f project=$PROJECT_ID -f item=$ITEM_ID \
  124. -f plugin_field=$PLUGIN_FIELD_ID -f plugin_value=$PLUGIN \
  125. -f theme_field=$THEME_FIELD_ID -f theme_value=$THEME \
  126. --silent