Skip to content

Fix duplicate commit comments in the github formatter - #511

Open
leochab wants to merge 2 commits into
prontolabs:masterfrom
leochab:fix-commit-comment-dedupe
Open

Fix duplicate commit comments in the github formatter#511
leochab wants to merge 2 commits into
prontolabs:masterfrom
leochab:fix-commit-comment-dedupe

Conversation

@leochab

@leochab leochab commented Aug 12, 2026

Copy link
Copy Markdown

Problem

The github formatter posts every offense as a new commit comment on every run, even when nothing changed. On a branch with N offenses, M CI reruns create N×M commit comments. Each one is a separate notification.

Root cause

The read path and the write path for comments use different fields.

Pronto::Github#create_commit_comment sends the diff position using the API's position parameter:

client.create_commit_comment(slug, comment.sha, comment.body,
                             comment.path, nil, comment.position)

Pronto::Github#commit_comments reads the response's line field instead:

Comment.new(sha, comment.body, comment.path, comment.line)

According to the commit-comments API docs, line is closing down. It is not set when a comment is created with position. So reading a comment back returns line: null, with position holding the value instead.

Where this came from

Commit 61beff7 ("compatibility fixes for supporting octokit 8.x", fixing #453) changed the GitHub client from position to line.

This was correct for the pull-request review comments endpoint, where position is closing down and line is current. But the same commit also changed commit_comments, where it is the opposite.

Fix

Read comment.position in commit_comments to match what create_commit_comment writes.

Tests

The first commit updates the github_formatter_spec.rb doubles to use a real diff position. Without the one-line fix, these tests fail; with it, they pass. It also adds a github_spec.rb test that pins which field commit_comments reads.

The second commit is optional. It removes the remaining position: nil values, which can never occur in production, and checks the exact arguments passed to create_commit_comment. This checks that the call is made with the right arguments, not just the right number of times.

https://docs.github.com/en/rest/commits/comments?apiVersion=2026-03-10#create-a-commit-comment
GitHub is closing down the "line" number and "position" should be used
instead.

We are already using the position when writing comment with
create_commit_comment, but not when reading them.
The position Pronto computes for a diff line is always a positive
integer, so the nil positions these doubles used cannot occur.

The create_commit_comment expectations only counted calls, so nothing
pinned which argument slot carries the diff position.
@leochab
leochab requested a review from a team as a code owner August 12, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant