Skip to content

Commit

Permalink
fix: placeholder comment edit/delete (#30)
Browse files Browse the repository at this point in the history
If a comment exists and placeholder comment is enabled, update comment
If a comment exists and placeholder comment is disabled, delete comment
  • Loading branch information
jazanne authored Jun 30, 2023
1 parent 4fbfc94 commit 36c09b5
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,26 @@ func postGithubComment(ctx context.Context, flagsRef ghc.FlagsRef, config *lcr.C
}

// Check if this is already the body, flags could have originally been included then removed in later commit
if config.PlaceholderComment && existingCommentId > 0 {
if strings.Contains(*existingComment.Body, "No flag references found in PR") {
return nil
if existingCommentId > 0 {
if config.PlaceholderComment {
if strings.Contains(*existingComment.Body, "No flag references found in PR") {
return nil
}

_, _, err := config.GHClient.Issues.EditComment(ctx, config.Owner, config.Repo, existingCommentId, ghc.GithubNoFlagComment())
return err
}

_, _, err := config.GHClient.Issues.EditComment(ctx, config.Owner, config.Repo, existingCommentId, ghc.GithubNoFlagComment())
_, err := config.GHClient.Issues.DeleteComment(ctx, config.Owner, config.Repo, existingCommentId)
return err
}

if config.PlaceholderComment {
_, _, err := config.GHClient.Issues.CreateComment(ctx, config.Owner, config.Repo, prNumber, ghc.GithubNoFlagComment())
return err
}

_, _, err := config.GHClient.Issues.CreateComment(ctx, config.Owner, config.Repo, prNumber, ghc.GithubNoFlagComment())
return err
return nil
}

func getDiffs(ctx context.Context, config *lcr.Config, prNumber int) ([]*diff.FileDiff, error) {
Expand Down

0 comments on commit 36c09b5

Please sign in to comment.