Optimize GitHub Comment Management in Action Mode
- Dominant language
- TypeScript
- Stars
- 81
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
## Description
Currently, when running in `github_action` mode, Flow Lens deletes all previous Flow Lens comments before publishing new ones, regardless of whether the content has changed. This creates unnecessary GitHub API calls and comment notifications, especially in PRs with multiple flow files where only some have changed.
### Current Behavior
In `uml_writer.ts`:
1. Fetches all PR comments
2. Deletes all comments containing "flow-lens-hidden-comment"
3. Creates new comments for all flows
### Proposed Behavior
Only delete and republish comments when the content has actually changed:
1. Fetch existing comments
2. For each flow file:
- Check if an existing comment exists for this file
- Compare new comment content with existing content
- Only delete and republish if content differs
#### Proposed Implementation
```typescript
private async writeGithubComment(config: RuntimeConfig) {
try {
const existingComments = await this.githubClient.getAllCommentsForPullRequest();
const flowLensComments = new Map();
// Index existing comments by file path
for (const comment of existingComments) {
if (comment.body.includes(HIDDEN_COMMENT_PREFIX)) {
const filePath = extractFilePathFromComment(comment.body);
flowLensComments.set(filePath, {
id: comment.id,
body: comment.body
});
}
}
// Process each flow difference
for (const [filePath, flowDifference] of this.filePathToFlowDifference) {
const newCommentBody = this.githubClient.translateToComment(
getBody(flowDifference),
filePath
);
const existingComment = flowLensComments.get(filePath);
if (!existingComment || existingComment.body !== newCommentBody) {
// Delete old comment if it exists
if (existingComment) {
await this.githubClient.deleteReviewComment(existingComment.id);
}
// Post new comment
await this.githubClient.writeComment(newCommentBody);
}
}
} catch (error) {
console.error("Failed to update GitHub comments:", error);
throw error;
}
}
```
**Related Files**
- `src/main/uml_writer.ts`
- `src/main/github_client.ts`
Contributor guide
Assessment
This issue has not been assessed yet.