project.yml 4.3 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. steps:
  12. - name: Read project data
  13. env:
  14. GITHUB_TOKEN: ${{ secrets.PROJECT_TOKEN }}
  15. ORGANIZATION: ohmyzsh
  16. PROJECT_NUMBER: "1"
  17. run: |
  18. # Get Project data
  19. gh api graphql -f query='
  20. query($org: String!, $number: Int!) {
  21. organization(login: $org){
  22. projectNext(number: $number) {
  23. id
  24. fields(first:20) {
  25. nodes {
  26. id
  27. name
  28. }
  29. }
  30. }
  31. }
  32. }
  33. ' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
  34. # Parse project data
  35. cat >> $GITHUB_ENV <<EOF
  36. PROJECT_ID=$(jq '.data.organization.projectNext.id' project_data.json)
  37. PLUGIN_FIELD_ID=$(jq '.data.organization.projectNext.fields.nodes[] | select(.name == "Plugin") | .id' project_data.json)
  38. THEME_FIELD_ID=$(jq '.data.organization.projectNext.fields.nodes[] | select(.name == "Theme") | .id' project_data.json)
  39. EOF
  40. - name: Add to project
  41. env:
  42. GITHUB_TOKEN: ${{ secrets.PROJECT_TOKEN }}
  43. ISSUE_ID: ${{ github.event.issue.node_id }}
  44. PR_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_ID:-$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. env:
  59. GITHUB_TOKEN: ${{ secrets.PROJECT_TOKEN }}
  60. run: |
  61. gh pr view ${{ github.event.pull_request.number }} --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. env:
  89. GITHUB_TOKEN: ${{ secrets.PROJECT_TOKEN }}
  90. run: |
  91. gh api graphql -f query='
  92. mutation (
  93. $project: ID!
  94. $item: ID!
  95. $plugin_field: ID!
  96. $plugin_value: String!
  97. $theme_field: ID!
  98. $theme_value: String!
  99. ) {
  100. set_plugin: updateProjectNextItemField(input: {
  101. projectId: $project
  102. itemId: $item
  103. fieldId: $plugin_field
  104. value: $plugin_value
  105. }) {
  106. projectNextItem {
  107. id
  108. }
  109. }
  110. set_theme: updateProjectNextItemField(input: {
  111. projectId: $project
  112. itemId: $item
  113. fieldId: $theme_field
  114. value: $theme_value
  115. }) {
  116. projectNextItem {
  117. id
  118. }
  119. }
  120. }
  121. ' -f project=$PROJECT_ID -f item=$ITEM_ID \
  122. -f plugin_field=$PLUGIN_FIELD_ID -f plugin_value=$PLUGIN \
  123. -f theme_field=$THEME_FIELD_ID -f theme_value=$THEME \
  124. --silent