How the GitHub Asana Request Review Action Handles Synchronize Events to Update Changed File Counts
When a pull request receives a synchronize event (new commits pushed), the action triggers shouldUpdateReviewerEvent, rebuilds the Asana comment text using createPullRequestCommentText with fresh GetChangedFiles() data, and pushes the update via UpdateTaskComment to keep file statistics current.
The keitap/github-asana-request-review-action integrates GitHub pull requests with Asana tasks by automatically posting PR details as comments. When developers push additional commits to an open PR, the action must refresh the Asana task description to reflect accurate changed file counts, additions, and deletions.
Detecting the Synchronize Event in handler.go
The workflow begins in handler.go where incoming webhooks are dispatched. The Handle method receives the pull_request event and forwards it to handlePullRequestEvent according to the source at lines 35-45.
Inside updateReviewers, the code evaluates shouldUpdateReviewerEvent by checking the action type. When pr.GetAction() equals prEventActionSynchronize, the system flags the event for an update refresh as implemented at lines 101-110:
// Detect a synchronize event
if pr.GetAction() == prEventActionSynchronize {
// mark the event as needing an update
shouldUpdateReviewerEvent = true
}
This boolean trigger forces the handler to proceed with refreshing both reviewer assignments and the PR description comment containing the file statistics.
Refreshing the Asana Comment
Once flagged for update, handlePullRequestEvent calls updateTask to manage the Asana story lifecycle. This function searches for an existing comment containing the unique signature #github-asana-request-review. If found, it prepares an update; otherwise, it creates a new story as shown at lines 82-93.
Generating Updated File Statistics
The comment text regeneration happens in createPullRequestCommentText within asana.go (lines 84-95). This function extracts current metrics using pr.PullRequest.GetChangedFiles(), GetAdditions(), and GetDeletions():
// Build the HTML comment that includes changed-file counts
func createPullRequestCommentText(requester *Account, pr *github.PullRequestEvent) string {
return fmt.Sprintf(
`<body>📋 <code>[<b>%s</b>] <a href="%s">Pull request #%d: %s</a> by %s
<b>%d</b> changed files (<b>+%d -%d</b>)
%s
%s
</code></body>`,
pr.PullRequest.GetState(),
pr.PullRequest.GetHTMLURL(),
pr.PullRequest.GetNumber(),
pr.PullRequest.GetTitle(),
requester.GetUserPermalink(),
pr.PullRequest.GetChangedFiles(),
pr.PullRequest.GetAdditions(),
pr.PullRequest.GetDeletions(),
getLabelsText(pr),
signature,
)
}
Pushing Updates to Asana
The action determines whether to create or update based on the existence of the signature comment. If the story exists, UpdateTaskComment (lines 63-70) overwrites the HTML content with the freshly generated text:
// Push the updated comment back to Asana
func UpdateTaskComment(client *asana.Client, storyID string, requester *Account, pr *github.PullRequestEvent) (*asana.Story, error) {
story := &asana.Story{ID: storyID}
newStory := &asana.StoryBase{
HTMLText: createPullRequestCommentText(requester, pr),
IsPinned: true,
}
return story.UpdateStory(client, newStory)
}
If no existing comment is found, AddPullRequestCommentToTask (lines 34-42) creates a new pinned story with the same generated content.
Key Implementation Files
The synchronize event handling spans two primary files in the repository:
handler.go: Contains the main webhook dispatcher atHandle, the synchronize detection logic inupdateReviewers, and theupdateTaskorchestration function.asana.go: HousescreatePullRequestCommentTextfor building HTML content andUpdateTaskCommentfor persisting changes to Asana stories.
Summary
- The
synchronizewebhook action triggersshouldUpdateReviewerEvent = trueinhandler.go, forcing a refresh of the Asana task data. - The action calls
updateTask, which locates existing comments via the#github-asana-request-reviewsignature or creates new ones if absent. - File statistics are regenerated using
pr.PullRequest.GetChangedFiles(),GetAdditions(), andGetDeletions()increatePullRequestCommentText. - Updated comments are pushed to Asana via
UpdateTaskCommentorAddPullRequestCommentToTask, ensuring the task reflects the latest PR metrics after every push.
Frequently Asked Questions
What triggers a changed file count update in the Asana task?
A changed file count update triggers when GitHub sends a pull_request webhook with the action type set to synchronize, which occurs whenever new commits are pushed to the pull request branch. The handler.go file detects this action type and sets shouldUpdateReviewerEvent to true, initiating the comment refresh workflow.
How does the action identify which Asana comment to update?
The action searches for a unique signature string (#github-asana-request-review) embedded in existing task stories. This signature is appended to every comment created by the action, allowing updateTask to distinguish between manually added comments and those managed by the automation.
What specific file statistics are included in the updated Asana comment?
The updated HTML comment includes three key metrics retrieved from the GitHub API: the total number of changed files (GetChangedFiles()), additions (GetAdditions()), and deletions (GetDeletions()). These values appear in the formatted output as <b>%d</b> changed files (<b>+%d -%d</b>).
Where is the synchronize event logic implemented in the codebase?
The synchronize event detection resides in handler.go within the updateReviewers function (lines 101-110), while the actual comment regeneration and Asana API calls are implemented in asana.go through the createPullRequestCommentText and UpdateTaskComment functions.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →