diff --git a/commenter/commenter.go b/commenter/commenter.go index 63779f9..de57357 100644 --- a/commenter/commenter.go +++ b/commenter/commenter.go @@ -156,7 +156,7 @@ func (c *Commenter) checkCommentRelevant(filename string, line int) bool { for _, file := range c.files { if relevant := func(file *commitFileInfo) bool { - if file.FileName == filename { + if file.FileName == filename && !file.isBinary() { if line >= file.hunkStart && line <= file.hunkEnd { return true } @@ -172,7 +172,7 @@ func (c *Commenter) checkCommentRelevant(filename string, line int) bool { func (c *Commenter) getFileInfo(file string, line int) (*commitFileInfo, error) { for _, info := range c.files { - if info.FileName == file { + if info.FileName == file && !info.isBinary() { if line >= info.hunkStart && line <= info.hunkEnd { return info, nil } @@ -192,18 +192,18 @@ func buildComment(file, comment string, line int, info commitFileInfo) *github.P } } -func getCommitInfo(file *github.CommitFile) (*commitFileInfo, error) { +func getCommitInfo(file *github.CommitFile) (cfi *commitFileInfo, err error) { + var hunkStart, hunkEnd int + var isBinary bool patch := file.GetPatch() - if patch == "" { - return nil, fmt.Errorf("ignoring [%s] because it has no patch informations, probably a binary?", *file.Filename) - } - - groups := patchRegex.FindAllStringSubmatch(file.GetPatch(), -1) - if len(groups) < 1 { - return nil, fmt.Errorf("the patch details for [%s] could not be resolved", *file.Filename) + if patch != "" { + groups := patchRegex.FindAllStringSubmatch(file.GetPatch(), -1) + if len(groups) < 1 { + return nil, fmt.Errorf("the patch details for [%s] could not be resolved", *file.Filename) + } + hunkStart, _ = strconv.Atoi(groups[0][1]) + hunkEnd, _ = strconv.Atoi(groups[0][2]) } - hunkStart, _ := strconv.Atoi(groups[0][1]) - hunkEnd, _ := strconv.Atoi(groups[0][2]) shaGroups := commitRefRegex.FindAllStringSubmatch(file.GetContentsURL(), -1) if len(shaGroups) < 1 { @@ -212,9 +212,10 @@ func getCommitInfo(file *github.CommitFile) (*commitFileInfo, error) { sha := shaGroups[0][1] return &commitFileInfo{ - FileName: *file.Filename, - hunkStart: hunkStart, - hunkEnd: hunkStart + (hunkEnd - 1), - sha: sha, + FileName: *file.Filename, + hunkStart: hunkStart, + hunkEnd: hunkStart + (hunkEnd - 1), + sha: sha, + likelyBinary: isBinary, }, nil } diff --git a/commenter/commitFileInfo.go b/commenter/commitFileInfo.go index 0dcc909..39925e7 100644 --- a/commenter/commitFileInfo.go +++ b/commenter/commitFileInfo.go @@ -6,10 +6,11 @@ import ( ) type commitFileInfo struct { - FileName string - hunkStart int - hunkEnd int - sha string + FileName string + hunkStart int + hunkEnd int + sha string + likelyBinary bool } func getCommitFileInfo(ghConnector *connector) ([]*commitFileInfo, error) { @@ -42,3 +43,7 @@ func (cfi commitFileInfo) calculatePosition(line int) *int { position := line - cfi.hunkStart return &position } + +func (cfi commitFileInfo) isBinary() bool { + return cfi.likelyBinary +}