project.yml 4.1 KB

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