d1c07f9569f4f7bb90345ccc363d71a8b8507687

Author
Marc Cornellà <hello@mcornella.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

chore: add Projects Beta GitHub Action

Diff

This diff is truncated to protect this page.

  1diff --git a/.github/workflows/project.yml b/.github/workflows/project.yml
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..ba3e115c931b4bf73ed9c171e2f7e2c123644492
  4--- /dev/null
  5+++ b/.github/workflows/project.yml
  6@@ -0,0 +1,134 @@
  7+name: Project tracking
  8+on:
  9+  issues:
 10+    types: [opened]
 11+  pull_request_target:
 12+    types: [opened, synchronize]
 13+
 14+jobs:
 15+  add-to-project:
 16+    name: Add to project
 17+    runs-on: ubuntu-latest
 18+    steps:
 19+      - name: Generate token
 20+        id: generate_token
 21+        uses: tibdex/github-app-token@36464acb844fc53b9b8b2401da68844f6b05ebb0
 22+        with:
 23+          app_id: ${{ secrets.OHMYZSH_BOT_APP_ID }}
 24+          private_key: ${{ secrets.OHMYZSH_BOT_APP_PEM }}
 25+      - name: Read project data
 26+        env:
 27+          GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
 28+          ORGANIZATION: ohmyzsh
 29+          PROJECT_NUMBER: "1"
 30+        run: |
 31+          # Get Project data
 32+          gh api graphql -f query='
 33+            query($org: String!, $number: Int!) {
 34+              organization(login: $org){
 35+                projectNext(number: $number) {
 36+                  id
 37+                  fields(first:20) {
 38+                    nodes {
 39+                      id
 40+                      name
 41+                    }
 42+                  }
 43+                }
 44+              }
 45+            }
 46+          ' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
 47+
 48+          # Parse project data
 49+          cat >> $GITHUB_ENV <<EOF
 50+          PROJECT_ID=$(jq '.data.organization.projectNext.id' project_data.json)
 51+          PLUGIN_FIELD_ID=$(jq '.data.organization.projectNext.fields.nodes[] | select(.name == "Plugin") | .id' project_data.json)
 52+          THEME_FIELD_ID=$(jq '.data.organization.projectNext.fields.nodes[] | select(.name == "Theme") | .id' project_data.json)
 53+          EOF
 54+      - name: Add to project
 55+        env:
 56+          GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
 57+          ISSUE_ID: ${{ github.event.issue.node_id }}
 58+          PR_ID: ${{ github.event.pull_request.node_id }}
 59+        run: |
 60+          item_id="$(gh api graphql -f query='
 61+            mutation($project: ID!, $item: ID!) {
 62+              addProjectNextItem(input: {projectId: $project, contentId: $item}) {
 63+                projectNextItem {
 64+                  id
 65+                }
 66+              }
 67+            }
 68+          ' -f project=$PROJECT_ID -f item=${ISSUE_ID:-$PR_ID} --jq '.data.addProjectNextItem.projectNextItem.id')"
 69+
 70+          echo "ITEM_ID=$item_id" >> $GITHUB_ENV
 71+      - name: Classify Pull Request
 72+        if: github.event_name == 'pull_request_target'
 73+        env:
 74+          GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
 75+        run: |
 76+          gh pr view ${{ github.event.pull_request.number }} --json files --jq '.files.[].path' | awk -F/ '
 77+            /^plugins\// {
 78+              plugins[$2] = 1
 79+            }
 80+            /^themes\// {
 81+              gsub(/\.zsh-theme$/, "", $2)
 82+              themes[$2] = 1
 83+            }
 84+            END {
 85+              for (plugin in plugins) {
 86+                print plugin >> "plugins.list"
 87+              }
 88+              for (theme in themes) {
 89+                print theme >> "themes.list"
 90+              }
 91+            }
 92+          '
 93+          # If only one plugin is modified, add it to the plugin field
 94+          if [[ $(wc -l < plugins.list) = 1 ]]; then
 95+            echo "PLUGIN=$(cat plugins.list)" >> $GITHUB_ENV
 96+          fi
 97+          # If only one theme is modified, add it to the theme field
 98+          if [[ $(wc -l < themes.list) = 1 ]]; then
 99+            echo "THEME=$(cat themes.list)" >> $GITHUB_ENV
100+          fi
101+      - name: Fill Pull Request fields in project
102+        if: github.event_name == 'pull_request_target'
103+        env:
104+          GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
105+        run: |