project.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. gh pr view ${{ github.event.pull_request.number }} \
  60. --repo ${{ github.repository }} \
  61. --json files --jq '.files.[].path' | awk -F/ '
  62. /^plugins\// {
  63. plugins[$2] = 1
  64. }
  65. /^themes\// {
  66. gsub(/\.zsh-theme$/, "", $2)
  67. themes[$2] = 1
  68. }
  69. END {
  70. for (plugin in plugins) {
  71. print plugin >> "plugins.list"
  72. }
  73. for (theme in themes) {
  74. print theme >> "themes.list"
  75. }
  76. }
  77. '
  78. # If only one plugin is modified, add it to the plugin field
  79. if [[ $(wc -l < plugins.list) = 1 ]]; then
  80. echo "PLUGIN=$(cat plugins.list)" >> $GITHUB_ENV
  81. fi
  82. # If only one theme is modified, add it to the theme field
  83. if [[ $(wc -l < themes.list) = 1 ]]; then
  84. echo "THEME=$(cat themes.list)" >> $GITHUB_ENV
  85. fi
  86. - name: Fill Pull Request fields in project
  87. if: github.event_name == 'pull_request_target'
  88. run: |
  89. gh api graphql -f query='
  90. mutation (
  91. $project: ID!
  92. $item: ID!
  93. $plugin_field: ID!
  94. $plugin_value: String!
  95. $theme_field: ID!
  96. $theme_value: String!
  97. ) {
  98. set_plugin: updateProjectNextItemField(input: {
  99. projectId: $project
  100. itemId: $item
  101. fieldId: $plugin_field
  102. value: $plugin_value
  103. }) {
  104. projectNextItem {
  105. id
  106. }
  107. }
  108. set_theme: updateProjectNextItemField(input: {
  109. projectId: $project
  110. itemId: $item
  111. fieldId: $theme_field
  112. value: $theme_value
  113. }) {
  114. projectNextItem {
  115. id
  116. }
  117. }
  118. }
  119. ' -f project=$PROJECT_ID -f item=$ITEM_ID \
  120. -f plugin_field=$PLUGIN_FIELD_ID -f plugin_value=$PLUGIN \
  121. -f theme_field=$THEME_FIELD_ID -f theme_value=$THEME \
  122. --silent