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

Adding workflow for updating the custom field "Last Updated". #1144

Merged
merged 4 commits into from
Nov 6, 2024
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
45 changes: 45 additions & 0 deletions .github/workflows/issue-last-updated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Update Project Last Updated Date on Issue Update or comment

on:
issues:
types: [edited, opened]
issue_comment:
types: [created]

env:
GITHUB_TOKEN: ${{ secrets.ISSUE_TOKEN }}

jobs:
update_project_date:
runs-on: ubuntu-latest
steps:
- name: Get Issue ID
id: get_issue_id
run: |
issue_number=${{ github.event.issue.number }}
issue_details=$(curl -H "Authorization: Bearer ${{ secrets.ISSUE_TOKEN }}" -s "https://api.github.com/repos/${{ github.repository }}/issues/$issue_number")
issue_id=$(echo "$issue_details" | jq -r '.node_id')
echo "issue_id=$issue_id" >> $GITHUB_ENV

- name: Get Item ID for Issue
id: get_item_by_issue_id
run: |
ITEM_ID=$(curl -X POST -H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"query": "query($projectId: ID!) { node(id: $projectId) { ... on ProjectV2 { items(first: 100) { nodes { id content { ... on Issue { id } } } } } } }",
"variables": {
"projectId": "'"${{ secrets.TT_FORGE_PROJECT_ID }}"'"
}
}' \
https://api.github.com/graphql | jq -r '.data.node.items.nodes[] | select(.content.id=="'"${{ env.issue_id }}"'") | .id')
echo "ITEM_ID=$ITEM_ID" >> $GITHUB_ENV

- name: Update Project Field
run: |
current_date=$(date +%Y-%m-%d)
curl -H "Authorization: Bearer ${{ secrets.ISSUE_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{ \"query\": \"mutation { updateProjectV2ItemFieldValue(input: { projectId: \\\"${{ secrets.TT_FORGE_PROJECT_ID }}\\\", itemId: \\\"${{ env.ITEM_ID }}\\\", fieldId: \\\"${{ secrets.TT_FORGE_PROJECT_LAST_UPDATED_ID }}\\\", value: { date: \\\"$current_date\\\" } }) { clientMutationId } }\" }" \
-X POST \
"https://api.github.com/graphql"
Loading