]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/.github/workflows/project.yml
...
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / .github / workflows / project.yml
1 name: Project tracking
2 on:
3   issues:
4     types: [opened, reopened]
5   pull_request_target:
6     types: [opened, reopened, synchronize]
7
8 concurrency:
9   group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
10   cancel-in-progress: true
11
12 permissions: {}
13 jobs:
14   add-to-project:
15     name: Add to project
16     runs-on: ubuntu-latest
17     if: github.repository == 'ohmyzsh/ohmyzsh'
18     env:
19       GITHUB_TOKEN: ${{ secrets.PROJECT_TOKEN }}
20     steps:
21       - name: Read project data
22         env:
23           ORGANIZATION: ohmyzsh
24           PROJECT_NUMBER: "1"
25         run: |
26           # Get Project data
27           gh api graphql -f query='
28             query($org: String!, $number: Int!) {
29               organization(login: $org){
30                 projectNext(number: $number) {
31                   id
32                   fields(first:20) {
33                     nodes {
34                       id
35                       name
36                     }
37                   }
38                 }
39               }
40             }
41           ' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
42
43           # Parse project data
44           cat >> $GITHUB_ENV <<EOF
45           PROJECT_ID=$(jq '.data.organization.projectNext.id' project_data.json)
46           PLUGIN_FIELD_ID=$(jq '.data.organization.projectNext.fields.nodes[] | select(.name == "Plugin") | .id' project_data.json)
47           THEME_FIELD_ID=$(jq '.data.organization.projectNext.fields.nodes[] | select(.name == "Theme") | .id' project_data.json)
48           EOF
49
50       - name: Add to project
51         env:
52           ISSUE_OR_PR_ID: ${{ github.event.issue.node_id || github.event.pull_request.node_id }}
53         run: |
54           item_id="$(gh api graphql -f query='
55             mutation($project: ID!, $content: ID!) {
56               addProjectNextItem(input: {projectId: $project, contentId: $content}) {
57                 projectNextItem {
58                   id
59                 }
60               }
61             }
62           ' -f project=$PROJECT_ID -f content=$ISSUE_OR_PR_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
63
64           echo "ITEM_ID=$item_id" >> $GITHUB_ENV
65
66       - name: Classify Pull Request
67         if: github.event_name == 'pull_request_target'
68         run: |
69           touch plugins.list themes.list
70
71           gh pr view ${{ github.event.pull_request.number }} \
72             --repo ${{ github.repository }} \
73             --json files --jq '.files.[].path' | awk -F/ '
74             /^plugins\// {
75               plugins[$2] = 1
76             }
77             /^themes\// {
78               gsub(/\.zsh-theme$/, "", $2)
79               themes[$2] = 1
80             }
81             END {
82               for (plugin in plugins) {
83                 print plugin >> "plugins.list"
84               }
85               for (theme in themes) {
86                 print theme >> "themes.list"
87               }
88             }
89           '
90           # If only one plugin is modified, add it to the plugin field
91           if [[ $(wc -l < plugins.list) = 1 ]]; then
92             echo "PLUGIN=$(cat plugins.list)" >> $GITHUB_ENV
93           fi
94           # If only one theme is modified, add it to the theme field
95           if [[ $(wc -l < themes.list) = 1 ]]; then
96             echo "THEME=$(cat themes.list)" >> $GITHUB_ENV
97           fi
98
99       - name: Fill Pull Request fields in project
100         if: github.event_name == 'pull_request_target'
101         run: |
102           gh api graphql -f query='
103             mutation (
104               $project: ID!
105               $item: ID!
106               $plugin_field: ID!
107               $plugin_value: String!
108               $theme_field: ID!
109               $theme_value: String!
110             ) {
111               set_plugin: updateProjectNextItemField(input: {
112                 projectId: $project
113                 itemId: $item
114                 fieldId: $plugin_field
115                 value: $plugin_value
116               }) {
117                 projectNextItem {
118                   id
119                 }
120               }
121               set_theme: updateProjectNextItemField(input: {
122                 projectId: $project
123                 itemId: $item
124                 fieldId: $theme_field
125                 value: $theme_value
126               }) {
127                 projectNextItem {
128                   id
129                 }
130               }
131             }
132           ' -f project=$PROJECT_ID -f item=$ITEM_ID \
133             -f plugin_field=$PLUGIN_FIELD_ID -f plugin_value=$PLUGIN \
134             -f theme_field=$THEME_FIELD_ID -f theme_value=$THEME \
135             --silent
136