From 0c8dbb559bb7d293d8ba331457df7c7316fd30db Mon Sep 17 00:00:00 2001 From: Owen Rumney Date: Mon, 24 Jan 2022 18:55:40 +0000 Subject: [PATCH] Support single line patches in the regex --- commenter/commenter.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/commenter/commenter.go b/commenter/commenter.go index ac59c58..5dc7ab7 100644 --- a/commenter/commenter.go +++ b/commenter/commenter.go @@ -17,7 +17,7 @@ type Commenter struct { } var ( - patchRegex = regexp.MustCompile(`^@@.*[\+\-](\d+),(\d+).+?@@`) + patchRegex = regexp.MustCompile(`^@@.*[\+\-](\d+)(?>\s[\+\-](\d)|,(\d+)).+?@@`) commitRefRegex = regexp.MustCompile(".+ref=(.+)") ) @@ -201,11 +201,18 @@ func getCommitInfo(file *github.CommitFile) (cfi *commitFileInfo, err error) { if len(groups) < 1 { return nil, fmt.Errorf("the patch details for [%s] could not be resolved", *file.Filename) } - hunkStart, err = strconv.Atoi(groups[0][1]) + + patchGroup := groups[0] + endPos := 2 + if len(patchGroup) > 2 { + endPos = 3 + } + + hunkStart, err = strconv.Atoi(patchGroup[1]) if err != nil { hunkStart = -1 } - hunkEnd, err = strconv.Atoi(groups[0][2]) + hunkEnd, err = strconv.Atoi(patchGroup[endPos]) if err != nil { hunkEnd = -1 }