Skip to content

Optimize GitHub Comment Management in Action Mode #36

@mitchspano

Description

@mitchspano

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

private async writeGithubComment(config: RuntimeConfig) {
  try {
    const existingComments = await this.githubClient.getAllCommentsForPullRequest();
    const flowLensComments = new Map<string, {id: number, body: string}>();
    
    // 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions