summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Cornellà <hello@mcornella.com>2022-01-02 02:30:00 +0100
committerMarc Cornellà <hello@mcornella.com>2022-01-02 02:30:00 +0100
commitd1c07f9569f4f7bb90345ccc363d71a8b8507687 (patch)
tree32331bc62687b3d01fad9f685a37be84d2d6df54
parent78c91ccbf99c77bd4d9cdb74279a40776721f66d (diff)
downloadzsh-d1c07f9569f4f7bb90345ccc363d71a8b8507687.tar.gz
zsh-d1c07f9569f4f7bb90345ccc363d71a8b8507687.tar.bz2
zsh-d1c07f9569f4f7bb90345ccc363d71a8b8507687.zip
chore: add Projects Beta GitHub Action
-rw-r--r--.github/workflows/project.yml134
1 files changed, 134 insertions, 0 deletions
diff --git a/.github/workflows/project.yml b/.github/workflows/project.yml
new file mode 100644
index 000000000..ba3e115c9
--- /dev/null
+++ b/.github/workflows/project.yml
@@ -0,0 +1,134 @@
+name: Project tracking
+on:
+ issues:
+ types: [opened]
+ pull_request_target:
+ types: [opened, synchronize]
+
+jobs:
+ add-to-project:
+ name: Add to project
+ runs-on: ubuntu-latest
+ steps:
+ - name: Generate token
+ id: generate_token
+ uses: tibdex/github-app-token@36464acb844fc53b9b8b2401da68844f6b05ebb0
+ with:
+ app_id: ${{ secrets.OHMYZSH_BOT_APP_ID }}
+ private_key: ${{ secrets.OHMYZSH_BOT_APP_PEM }}
+ - name: Read project data
+ env:
+ GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
+ ORGANIZATION: ohmyzsh
+ PROJECT_NUMBER: "1"
+ run: |
+ # Get Project data
+ gh api graphql -f query='
+ query($org: String!, $number: Int!) {
+ organization(login: $org){
+ projectNext(number: $number) {
+ id
+ fields(first:20) {
+ nodes {
+ id
+ name
+ }
+ }
+ }
+ }
+ }
+ ' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
+
+ # Parse project data
+ cat >> $GITHUB_ENV <<EOF
+ PROJECT_ID=$(jq '.data.organization.projectNext.id' project_data.json)
+ PLUGIN_FIELD_ID=$(jq '.data.organization.projectNext.fields.nodes[] | select(.name == "Plugin") | .id' project_data.json)
+ THEME_FIELD_ID=$(jq '.data.organization.projectNext.fields.nodes[] | select(.name == "Theme") | .id' project_data.json)
+ EOF
+ - name: Add to project
+ env:
+ GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
+ ISSUE_ID: ${{ github.event.issue.node_id }}
+ PR_ID: ${{ github.event.pull_request.node_id }}
+ run: |
+ item_id="$(gh api graphql -f query='
+ mutation($project: ID!, $item: ID!) {
+ addProjectNextItem(input: {projectId: $project, contentId: $item}) {
+ projectNextItem {
+ id
+ }
+ }
+ }
+ ' -f project=$PROJECT_ID -f item=${ISSUE_ID:-$PR_ID} --jq '.data.addProjectNextItem.projectNextItem.id')"
+
+ echo "ITEM_ID=$item_id" >> $GITHUB_ENV
+ - name: Classify Pull Request
+ if: github.event_name == 'pull_request_target'
+ env:
+ GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
+ run: |
+ gh pr view ${{ github.event.pull_request.number }} --json files --jq '.files.[].path' | awk -F/ '
+ /^plugins\// {
+ plugins[$2] = 1
+ }
+ /^themes\// {
+ gsub(/\.zsh-theme$/, "", $2)
+ themes[$2] = 1
+ }
+ END {
+ for (plugin in plugins) {
+ print plugin >> "plugins.list"
+ }
+ for (theme in themes) {
+ print theme >> "themes.list"
+ }
+ }
+ '
+ # If only one plugin is modified, add it to the plugin field
+ if [[ $(wc -l < plugins.list) = 1 ]]; then
+ echo "PLUGIN=$(cat plugins.list)" >> $GITHUB_ENV
+ fi
+ # If only one theme is modified, add it to the theme field
+ if [[ $(wc -l < themes.list) = 1 ]]; then
+ echo "THEME=$(cat themes.list)" >> $GITHUB_ENV
+ fi
+ - name: Fill Pull Request fields in project
+ if: github.event_name == 'pull_request_target'
+ env:
+ GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
+ run: |
+ gh api graphql -f query='
+ mutation (
+ $project: ID!
+ $item: ID!
+ $plugin_field: ID!
+ $plugin_value: String!
+ $theme_field: ID!
+ $theme_value: String!
+ ) {
+ set_plugin: updateProjectNextItemField(input: {
+ projectId: $project
+ itemId: $item
+ fieldId: $plugin_field
+ value: $plugin_value
+ }) {
+ projectNextItem {
+ id
+ }
+ }
+ set_theme: updateProjectNextItemField(input: {
+ projectId: $project
+ itemId: $item
+ fieldId: $theme_field
+ value: $theme_value
+ }) {
+ projectNextItem {
+ id
+ }
+ }
+ }
+ ' -f project=$PROJECT_ID -f item=$ITEM_ID \
+ -f plugin_field=$PLUGIN_FIELD_ID -f plugin_value=$PLUGIN \
+ -f theme_field=$THEME_FIELD_ID -f theme_value=$THEME \
+ --silent
+