project.yml 4.8 KB

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