Skip to content

Commit 40a7660

Browse files
6543techknowlogick
andauthored
Fix error create comment on outdated file (go-gitea#13041) (go-gitea#13042)
* FIX * more specific Co-authored-by: techknowlogick <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent b05e178 commit 40a7660

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

services/pull/review.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package pull
88
import (
99
"bytes"
1010
"fmt"
11+
"regexp"
1112
"strings"
1213

1314
"code.gitea.io/gitea/models"
@@ -104,6 +105,8 @@ func CreateCodeComment(doer *models.User, gitRepo *git.Repository, issue *models
104105
return comment, nil
105106
}
106107

108+
var notEnoughLines = regexp.MustCompile(`exit status 128 - fatal: file .* has only \d+ lines?`)
109+
107110
// createCodeComment creates a plain code comment at the specified line / path
108111
func createCodeComment(doer *models.User, repo *models.Repository, issue *models.Issue, content, treePath string, line, reviewID int64) (*models.Comment, error) {
109112
var commitID, patch string
@@ -127,7 +130,7 @@ func createCodeComment(doer *models.User, repo *models.Repository, issue *models
127130
commit, err := gitRepo.LineBlame(pr.GetGitRefName(), gitRepo.Path, treePath, uint(line))
128131
if err == nil {
129132
commitID = commit.ID.String()
130-
} else if !strings.Contains(err.Error(), "exit status 128 - fatal: no such path") {
133+
} else if !(strings.Contains(err.Error(), "exit status 128 - fatal: no such path") || notEnoughLines.MatchString(err.Error())) {
131134
return nil, fmt.Errorf("LineBlame[%s, %s, %s, %d]: %v", pr.GetGitRefName(), gitRepo.Path, treePath, line, err)
132135
}
133136
}

0 commit comments

Comments
 (0)