Fix duplicate commit comments in the github formatter - #511
Open
leochab wants to merge 2 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
githubformatter 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_commentsends the diff position using the API'spositionparameter:Pronto::Github#commit_commentsreads the response'slinefield instead:According to the commit-comments API docs,
lineis closing down. It is not set when a comment is created withposition. So reading a comment back returnsline: null, withpositionholding the value instead.Where this came from
Commit 61beff7 ("compatibility fixes for supporting octokit 8.x", fixing #453) changed the GitHub client from
positiontoline.This was correct for the pull-request review comments endpoint, where
positionis closing down andlineis current. But the same commit also changedcommit_comments, where it is the opposite.Fix
Read
comment.positionincommit_commentsto match whatcreate_commit_commentwrites.Tests
The first commit updates the
github_formatter_spec.rbdoubles to use a real diff position. Without the one-line fix, these tests fail; with it, they pass. It also adds agithub_spec.rbtest that pins which fieldcommit_commentsreads.The second commit is optional. It removes the remaining position:
nilvalues, which can never occur in production, and checks the exact arguments passed tocreate_commit_comment. This checks that the call is made with the right arguments, not just the right number of times.