project.yml 4.2 KB

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