Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
Support single line patches in the regex
Browse files Browse the repository at this point in the history
  • Loading branch information
owenrumney committed Jan 24, 2022
1 parent bfb37de commit 0c8dbb5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions commenter/commenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Commenter struct {
}

var (
patchRegex = regexp.MustCompile(`^@@.*[\+\-](\d+),(\d+).+?@@`)
patchRegex = regexp.MustCompile(`^@@.*[\+\-](\d+)(?>\s[\+\-](\d)|,(\d+)).+?@@`)
commitRefRegex = regexp.MustCompile(".+ref=(.+)")
)

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0c8dbb5

Please sign in to comment.