2022-01-02 02:30:00 +01:00
|
|
|
name: Project tracking
|
|
|
|
on:
|
|
|
|
issues:
|
2022-04-04 21:40:08 +02:00
|
|
|
types: [opened, reopened]
|
2022-01-02 02:30:00 +01:00
|
|
|
pull_request_target:
|
2022-04-04 21:40:08 +02:00
|
|
|
types: [opened, reopened, synchronize]
|
2022-01-02 02:30:00 +01:00
|
|
|
|
2022-02-21 19:27:21 +01:00
|
|
|
concurrency:
|
|
|
|
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
|
|
|
cancel-in-progress: true
|
|
|
|
|
2022-10-07 14:39:00 +02:00
|
|
|
permissions: {}
|
2022-01-02 02:30:00 +01:00
|
|
|
jobs:
|
|
|
|
add-to-project:
|
|
|
|
name: Add to project
|
|
|
|
runs-on: ubuntu-latest
|
2022-01-03 13:10:53 +01:00
|
|
|
if: github.repository == 'ohmyzsh/ohmyzsh'
|
2022-01-02 02:30:00 +01:00
|
|
|
steps:
|
2023-12-28 21:21:09 +01:00
|
|
|
- name: Authenticate as @ohmyzsh
|
|
|
|
id: generate_token
|
|
|
|
uses: ohmyzsh/github-app-token@v2
|
|
|
|
with:
|
|
|
|
app_id: ${{ secrets.OHMYZSH_APP_ID }}
|
|
|
|
private_key: ${{ secrets.OHMYZSH_APP_PRIVATE_KEY }}
|
|
|
|
- name: Store app token
|
|
|
|
run: echo "GH_TOKEN=${{ steps.generate_token.outputs.token }}" >> "$GITHUB_ENV"
|
2022-01-02 02:30:00 +01:00
|
|
|
- name: Read project data
|
|
|
|
env:
|
|
|
|
ORGANIZATION: ohmyzsh
|
|
|
|
PROJECT_NUMBER: "1"
|
|
|
|
run: |
|
|
|
|
# Get Project data
|
2022-01-02 03:37:05 +01:00
|
|
|
gh api graphql -f query='
|
2022-01-02 02:30:00 +01:00
|
|
|
query($org: String!, $number: Int!) {
|
|
|
|
organization(login: $org){
|
2022-11-03 18:30:30 +01:00
|
|
|
projectV2(number: $number) {
|
2022-01-02 02:30:00 +01:00
|
|
|
id
|
|
|
|
fields(first:20) {
|
|
|
|
nodes {
|
2022-11-03 18:30:30 +01:00
|
|
|
... on ProjectV2Field {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
2022-01-02 02:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-03 18:30:30 +01:00
|
|
|
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
|
2022-01-02 02:30:00 +01:00
|
|
|
|
|
|
|
# Parse project data
|
|
|
|
cat >> $GITHUB_ENV <<EOF
|
2022-11-03 18:30:30 +01:00
|
|
|
PROJECT_ID=$(jq '.data.organization.projectV2.id' project_data.json)
|
|
|
|
PLUGIN_FIELD_ID=$(jq '.data.organization.projectV2.fields.nodes[] | select(.name == "Plugin") | .id' project_data.json)
|
|
|
|
THEME_FIELD_ID=$(jq '.data.organization.projectV2.fields.nodes[] | select(.name == "Theme") | .id' project_data.json)
|
2022-01-02 02:30:00 +01:00
|
|
|
EOF
|
2022-01-02 03:09:52 +01:00
|
|
|
|
2022-01-02 02:30:00 +01:00
|
|
|
- name: Add to project
|
|
|
|
env:
|
2022-01-03 13:02:28 +01:00
|
|
|
ISSUE_OR_PR_ID: ${{ github.event.issue.node_id || github.event.pull_request.node_id }}
|
2022-01-02 02:30:00 +01:00
|
|
|
run: |
|
|
|
|
item_id="$(gh api graphql -f query='
|
2022-01-10 17:22:31 +01:00
|
|
|
mutation($project: ID!, $content: ID!) {
|
2022-11-03 18:30:30 +01:00
|
|
|
addProjectV2ItemById(input: {projectId: $project, contentId: $content}) {
|
|
|
|
item {
|
2022-01-02 02:30:00 +01:00
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-03 18:30:30 +01:00
|
|
|
' -f project=$PROJECT_ID -f content=$ISSUE_OR_PR_ID --jq '.data.addProjectV2ItemById.item.id')"
|
2022-01-02 02:30:00 +01:00
|
|
|
|
|
|
|
echo "ITEM_ID=$item_id" >> $GITHUB_ENV
|
2022-01-02 03:09:52 +01:00
|
|
|
|
2022-01-02 02:30:00 +01:00
|
|
|
- name: Classify Pull Request
|
|
|
|
if: github.event_name == 'pull_request_target'
|
|
|
|
run: |
|
2022-01-11 23:40:33 +01:00
|
|
|
touch plugins.list themes.list
|
|
|
|
|
2022-01-10 17:22:31 +01:00
|
|
|
gh pr view ${{ github.event.pull_request.number }} \
|
|
|
|
--repo ${{ github.repository }} \
|
|
|
|
--json files --jq '.files.[].path' | awk -F/ '
|
2022-01-02 02:30:00 +01:00
|
|
|
/^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
|
2022-01-02 03:09:52 +01:00
|
|
|
|
2022-01-02 02:30:00 +01:00
|
|
|
- name: Fill Pull Request fields in project
|
|
|
|
if: github.event_name == 'pull_request_target'
|
|
|
|
run: |
|
|
|
|
gh api graphql -f query='
|
|
|
|
mutation (
|
|
|
|
$project: ID!
|
|
|
|
$item: ID!
|
|
|
|
$plugin_field: ID!
|
|
|
|
$plugin_value: String!
|
|
|
|
$theme_field: ID!
|
|
|
|
$theme_value: String!
|
|
|
|
) {
|
2022-11-03 18:30:30 +01:00
|
|
|
set_plugin: updateProjectV2ItemFieldValue(input: {
|
2022-01-02 02:30:00 +01:00
|
|
|
projectId: $project
|
|
|
|
itemId: $item
|
|
|
|
fieldId: $plugin_field
|
2022-11-04 19:16:54 +01:00
|
|
|
value: {
|
|
|
|
text: $plugin_value
|
|
|
|
}
|
2022-01-02 02:30:00 +01:00
|
|
|
}) {
|
2022-11-03 18:30:30 +01:00
|
|
|
projectV2Item {
|
2022-01-02 02:30:00 +01:00
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
2022-11-03 18:30:30 +01:00
|
|
|
set_theme: updateProjectV2ItemFieldValue(input: {
|
2022-01-02 02:30:00 +01:00
|
|
|
projectId: $project
|
|
|
|
itemId: $item
|
|
|
|
fieldId: $theme_field
|
2022-11-04 19:16:54 +01:00
|
|
|
value: {
|
|
|
|
text: $theme_value
|
|
|
|
}
|
2022-01-02 02:30:00 +01:00
|
|
|
}) {
|
2022-11-03 18:30:30 +01:00
|
|
|
projectV2Item {
|
2022-01-02 02:30:00 +01:00
|
|
|
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
|