feat: automations for project management (#2434)

This commit is contained in:
Simon Hyll
2024-07-21 10:01:01 +02:00
committed by GitHub
parent 88e55c3e78
commit d1bc28034b
6 changed files with 259 additions and 4 deletions

21
.github/workflows/assign.yml vendored Normal file
View File

@@ -0,0 +1,21 @@
name: 'Auto Assign'
on:
pull_request:
types: [opened]
jobs:
auto_assign:
runs-on: ubuntu-latest
steps:
- name: Auto-assign PR to author
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pr_number=${{ github.event.pull_request.number }}
pr_author=${{ github.event.pull_request.user.login }}
gh api -X POST \
-H "Accept: application/vnd.github+json" \
"/repos/${{ github.repository }}/issues/${pr_number}/assignees" \
-f assignees='["'${pr_author}'"]'

View File

@@ -1,6 +1,6 @@
# Adapted from https://github.com/withastro/starlight/blob/main/.github/workflows/format.yml
name: Check formatting
name: 'Check formatting'
on:
pull_request:

View File

@@ -1,4 +1,4 @@
name: Congrats
name: 'Congrats'
on:
push:

View File

@@ -1,9 +1,10 @@
name: 'Pull Request Labeler'
on:
- pull_request_target
pull_request_target:
jobs:
triage:
add_labels:
permissions:
contents: read
pull-requests: write

100
.github/workflows/priority.yml vendored Normal file
View File

@@ -0,0 +1,100 @@
name: 'Priority Updater'
on:
issues:
types: [opened]
pull_request:
types: [opened]
jobs:
set_statuses:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.issue.labels.*.name, 'manual') && !contains(github.event.pull_request.labels.*.name, 'manual') }}
permissions:
pull-requests: write
issues: write
steps:
- name: Get project data
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ORGANIZATION: tauri-apps
PROJECT_NUMBER: 27
run: |
gh api graphql -f query='
query($org: String!, $number: Int!) {
organization(login: $org){
projectV2(number: $number) {
id
fields(first: 20) {
nodes {
... on ProjectV2Field {
id
name
}
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
}
}
}
}
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV
echo 'PRIORITY_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Priority") | .id' project_data.json) >> $GITHUB_ENV
echo 'LOW_PRIORITY_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Priority") | .options[] | select(.name=="Low") |.id' project_data.json) >> $GITHUB_ENV
echo 'MEDIUM_PRIORITY_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Priority") | .options[] | select(.name=="Medium") |.id' project_data.json) >> $GITHUB_ENV
echo 'HIGH_PRIORITY_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Priority") | .options[] | select(.name=="High") |.id' project_data.json) >> $GITHUB_ENV
echo 'CRITICAL_PRIORITY_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Priority") | .options[] | select(.name=="Critical") |.id' project_data.json) >> $GITHUB_ENV
- name: Default priority
run: |
echo 'PRIORITY_ID='${{ env.LOW_PRIORITY_ID }} >> $GITHUB_ENV
- name: Add/get item id
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "${{ github.event.pull_request.node_id }}" != "" ]; then
echo "NODE_ID=${{ github.event.pull_request.node_id }}" >> $GITHUB_ENV
else
echo "NODE_ID=${{ github.event.issue.node_id }}" >> $GITHUB_ENV
fi
item_id=$(gh api graphql -f query='
mutation($project: ID!, $node: ID!) {
addProjectV2ItemById(input: {projectId: $project, contentId: $node}) {
item {
id
}
}
}' -f project=$PROJECT_ID -f node=$NODE_ID --jq '.data.addProjectV2ItemById.item.id')
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
- name: Set fields
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api graphql -f query='
mutation (
$project: ID!
$item: ID!
$priority_field: ID!
$priority_value: String!
) {
set_priority: updateProjectV2ItemFieldValue(input: {
projectId: $project
itemId: $item
fieldId: $priority_field
value: {
singleSelectOptionId: $priority_value
}
}) {
projectV2Item {
id
}
}
}' -f project=${{ env.PROJECT_ID }} -f item=${{ env.ITEM_ID }} -f priority_field=${{ env.PRIORITY_FIELD_ID }} -f priority_value=${{ env.PRIORITY_ID }} --silent

133
.github/workflows/status.yml vendored Normal file
View File

@@ -0,0 +1,133 @@
name: 'Status Updater'
on:
issues:
pull_request:
jobs:
set_statuses:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.issue.labels.*.name, 'manual') && !contains(github.event.pull_request.labels.*.name, 'manual') }}
permissions:
contents: write
pull-requests: write
issues: write
steps:
- name: Set up GitHub CLI
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
- name: Get project data
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ORGANIZATION: tauri-apps
PROJECT_NUMBER: 27
run: |
gh api graphql -f query='
query($org: String!, $number: Int!) {
organization(login: $org){
projectV2(number: $number) {
id
fields(first: 20) {
nodes {
... on ProjectV2Field {
id
name
}
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
}
}
}
}
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
echo 'BACKLOG_STATUS_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name=="🪵 Backlog") |.id' project_data.json) >> $GITHUB_ENV
echo 'READY_STATUS_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name=="💪 Ready") |.id' project_data.json) >> $GITHUB_ENV
echo 'IN_PROGRESS_STATUS_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name=="🏗️ In progress") |.id' project_data.json) >> $GITHUB_ENV
echo 'IN_REVIEW_STATUS_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name=="📋 In review") |.id' project_data.json) >> $GITHUB_ENV
echo 'DONE_STATUS_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name=="✅ Done") |.id' project_data.json) >> $GITHUB_ENV
- name: Add/get item id
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "${{ github.event.pull_request.node_id }}" != "" ]; then
echo "NODE_ID=${{ github.event.pull_request.node_id }}" >> $GITHUB_ENV
else
echo "NODE_ID=${{ github.event.issue.node_id }}" >> $GITHUB_ENV
fi
item_id=$(gh api graphql -f query='
mutation($project: ID!, $node: ID!) {
addProjectV2ItemById(input: {projectId: $project, contentId: $node}) {
item {
id
}
}
}' -f project=$PROJECT_ID -f node=$NODE_ID --jq '.data.addProjectV2ItemById.item.id')
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
#===== PULL REQUESTS =====#
- name: Is In progress
if: ${{ github.event_name == 'pull_request' && (github.event.pull_request.draft == true || github.event.pull_request.mergeable == false) }}
run: |
echo 'STATUS_ID='${{ env.IN_PROGRESS_STATUS_ID }} >> $GITHUB_ENV
- name: Is In review
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.draft == false && github.event.pull_request.mergeable == true }}
run: |
echo 'STATUS_ID='${{ env.IN_REVIEW_STATUS_ID }} >> $GITHUB_ENV
#===== END PULL REQUESTS =====#
#===== ISSUES =====#
- name: Is Ready
if: ${{ github.event_name == 'issues' && (github.event.issue.labels[0] != null && github.event.issue.milestone != null) }}
run: |
echo 'STATUS_ID='${{ env.READY_STATUS_ID }} >> $GITHUB_ENV
- name: Is In progress
if: ${{ github.event_name == 'issues' && (github.event.issue.labels[0] != null && github.event.issue.milestone != null && github.event.issue.assignees[0] != null) }}
run: |
echo 'STATUS_ID='${{ env.IN_PROGRESS_STATUS_ID }} >> $GITHUB_ENV
- name: Is In review
if: ${{ github.event_name == 'issues' && (github.event.issue.labels[0] != null && github.event.issue.pull_request.merged_at != null) }}
run: |
echo 'STATUS_ID='${{ env.IN_REVIEW_STATUS_ID }} >> $GITHUB_ENV
- name: Is Backlog
if: ${{ github.event_name == 'issues' && (github.event.issue.labels[0] == null || github.event.issue.milestone == null || contains(github.event.issue.labels.*.name, 'upstream') || contains(github.event.issue.labels.*.name, 'discuss')) }}
run: |
echo 'STATUS_ID='${{ env.BACKLOG_STATUS_ID }} >> $GITHUB_ENV
#===== END ISSUES =====#
- name: Set fields
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api graphql -f query='
mutation (
$project: ID!
$item: ID!
$status_field: ID!
$status_value: String!
) {
set_status: updateProjectV2ItemFieldValue(input: {
projectId: $project
itemId: $item
fieldId: $status_field
value: {
singleSelectOptionId: $status_value
}
}) {
projectV2Item {
id
}
}
}' -f project=${{ env.PROJECT_ID }} -f item=${{ env.ITEM_ID }} -f status_field=${{ env.STATUS_FIELD_ID }} -f status_value=${{ env.STATUS_ID }} --silent