-
Notifications
You must be signed in to change notification settings - Fork 4.3k
chore: add addedon field automation in prioritization board #33856
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| name: PR Prioritization AddedOn update | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 */6 * * 1-5' # Runs every 6 hours during weekdays | ||
| workflow_dispatch: # Manual trigger | ||
|
|
||
| jobs: | ||
| update_added_on: | ||
| if: github.repository == 'aws/aws-cdk' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Update AddedOn field | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| github-token: ${{ secrets.PROJEN_GITHUB_TOKEN }} | ||
| script: | | ||
| const script = require('./scripts/prioritization/update-added-on.js') | ||
| await script({github}) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /** | ||
| * Updates the "Added On" date for project items that have empty "Added On" field | ||
| * by using the project item's createdAt timestamp from GitHub API. | ||
| * This handles items that were added to the board manually. | ||
| */ | ||
|
|
||
| const { ...PROJECT_CONFIG } = require('./project-config'); | ||
| const { | ||
| fetchProjectItems, | ||
| updateProjectDateField, | ||
| } = require('./project-api'); | ||
|
|
||
| module.exports = async ({ github }) => { | ||
| // Get today's date at start of day (UTC) | ||
| const today = new Date(); | ||
| today.setUTCHours(0, 0, 0, 0); | ||
|
|
||
| try { | ||
| let allItems = []; | ||
| let hasNextPage = true; | ||
| let cursor = null; | ||
|
|
||
| // Fetch project items with pagination | ||
| while (hasNextPage) { | ||
| const result = await fetchProjectItems({ | ||
| github, | ||
| org: PROJECT_CONFIG.org, | ||
| number: PROJECT_CONFIG.projectNumber, | ||
| cursor, | ||
| }); | ||
|
|
||
| const items = result.organization.projectV2.items; | ||
|
|
||
| // Filter items created today | ||
| const todayItems = items.nodes.filter(item => { | ||
| const itemDate = new Date(item.createdAt); | ||
| return itemDate >= today; | ||
| }); | ||
|
|
||
| if (todayItems.length > 0) { | ||
| allItems = allItems.concat(todayItems); | ||
| } | ||
|
|
||
| hasNextPage = items.pageInfo.hasNextPage; | ||
| cursor = items.pageInfo.endCursor; | ||
| } | ||
|
|
||
| console.log(`Processing ${allItems.length} items created today for AddedOn dates`); | ||
|
|
||
| // Process each item | ||
| for (const item of allItems) { | ||
| const itemType = item.type; | ||
| const itemNumber = item.content?.number; | ||
|
|
||
| try { | ||
| // Find the AddedOn field value | ||
| const addedOnField = item.fieldValues.nodes.find( | ||
| (field) => field.field?.name === 'AddedOn' | ||
| ); | ||
|
|
||
| // If AddedOn is empty | ||
| if (!addedOnField || !addedOnField.date) { | ||
| console.log(`Processing ${itemType} #${itemNumber} - Adding missing AddedOn date`); | ||
|
|
||
| await updateProjectDateField({ | ||
| github, | ||
| projectId: PROJECT_CONFIG.projectId, | ||
| itemId: item.id, | ||
| fieldId: PROJECT_CONFIG.addedOnFieldId, | ||
| date: item.createdAt, | ||
| }); | ||
|
|
||
| console.log(`Updated AddedOn date for ${itemType} #${itemNumber} with creation date ${item.createdAt}`); | ||
| } else { | ||
| console.log(`Skipping ${itemType} #${itemNumber} - AddedOn date already set`); | ||
| } | ||
| } catch (error) { | ||
| console.error(`Error processing ${itemType} #${itemNumber}:`, error.message); | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
| if (allItems.length === 0) { | ||
| console.log('No items found that were created today'); | ||
| } else { | ||
| console.log(`Successfully processed ${allItems.length} items`); | ||
| } | ||
|
|
||
| console.log('Completed processing today\'s items for AddedOn dates'); | ||
| } catch (error) { | ||
| console.error('Error updating AddedOn dates:', error.message); | ||
| throw error; | ||
| } | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a design question: why do we decide to have separate workflow files? i.e. If there's 5 more columns we want to add in the future then there'll be 5 separate workflows for it right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid concern. we decided to have separate workflow based on the trigger type for specific automation. For this case, this workflow will have a cron schedule to check every 6 hours. We will be using the same workflow or any other existing workflow in future for other columns as a additional job step if it is also needed similar schedule.