project.yml 4.5 KB

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