project.yml 4.4 KB

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