Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: automatically set the start date for issues in GitHub projects #1033

Merged
merged 5 commits into from
Mar 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions .github/workflows/set-date.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Set the End Date in the project
name: Set the Date in the project

on:
issues:
types: [closed]
types: [assigned, closed]
jobs:
set_date:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -38,8 +38,9 @@ jobs:
}
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json
echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV
echo 'DATE_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "End Date") | .id' project_data.json) >> $GITHUB_ENV

echo 'START_DATE_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Start Date") | .id' project_data.json) >> $GITHUB_ENV
echo 'END_DATE_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "End Date") | .id' project_data.json) >> $GITHUB_ENV

- name: Get date
run: echo "DATE=$(date +"%Y-%m-%d")" >> $GITHUB_ENV

Expand All @@ -58,9 +59,36 @@ jobs:
}' -f project=$PROJECT_ID -f issue=$ISSUE_ID --jq '.data.addProjectV2ItemById.item.id')"
echo 'ITEM_ID='$item_id >> $GITHUB_ENV

- name: Set Start Date
env:
GITHUB_TOKEN: ${{ secrets.KEPTN_BOT_PROJECT_TOKEN }}
if: github.event.action == 'assigned'
run: |
gh api graphql -f query='
mutation (
$project: ID!
$item: ID!
$date_field: ID!
$date_value: Date!
) {
set_start_date: updateProjectV2ItemFieldValue(input: {
projectId: $project
itemId: $item
fieldId: $date_field
value: {
date: $date_value
}
}) {
projectV2Item {
id
}
}
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f date_field=$START_DATE_FIELD_ID -f date_value=$DATE

- name: Set End Date
env:
GITHUB_TOKEN: ${{ secrets.KEPTN_BOT_PROJECT_TOKEN }}
if: github.event.action == 'closed'
run: |
gh api graphql -f query='
mutation (
Expand All @@ -81,5 +109,5 @@ jobs:
id
}
}
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f date_field=$DATE_FIELD_ID -f date_value=$DATE
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f date_field=$END_DATE_FIELD_ID -f date_value=$DATE