fix(migrations): preserve SHA-256 pull request commit IDs (#39343)

* Fixes #39339

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
breken
2026-09-19 12:41:41 +00:00
committed by GitHub
co-authored by wxiaoguang
parent 2a3d047339
commit cc34c26172
17 changed files with 105 additions and 128 deletions
+5 -6
View File
@@ -50,19 +50,18 @@ func CheckAndEnsureSafePR(pr *base.PullRequest, commonCloneBaseURL string, g bas
valid = false
}
// SECURITY: SHAs Must be a SHA
// FIXME: hash only a SHA1
CommitType := git.Sha1ObjectFormat
if pr.MergeCommitSHA != "" && !CommitType.IsValid(pr.MergeCommitSHA) {
// SECURITY: SHAs must be valid Git object IDs.
// The repository object format is not yet available at this stage.
if pr.MergeCommitSHA != "" && !git.IsStringValidObjectID(nil, pr.MergeCommitSHA) {
WarnAndNotice("PR #%d in %s has invalid MergeCommitSHA: %s", pr.Number, g, pr.MergeCommitSHA)
pr.MergeCommitSHA = ""
}
if pr.Head.SHA != "" && !CommitType.IsValid(pr.Head.SHA) {
if pr.Head.SHA != "" && !git.IsStringValidObjectID(nil, pr.Head.SHA) {
WarnAndNotice("PR #%d in %s has invalid HeadSHA: %s", pr.Number, g, pr.Head.SHA)
pr.Head.SHA = ""
valid = false
}
if pr.Base.SHA != "" && !CommitType.IsValid(pr.Base.SHA) {
if pr.Base.SHA != "" && !git.IsStringValidObjectID(nil, pr.Base.SHA) {
WarnAndNotice("PR #%d in %s has invalid BaseSHA: %s", pr.Number, g, pr.Base.SHA)
pr.Base.SHA = ""
valid = false
+1 -1
View File
@@ -918,7 +918,7 @@ func (g *GiteaLocalUploader) CreateReviews(ctx context.Context, reviews ...*base
}
objectFormat := git.ObjectFormatFromName(g.repo.ObjectFormatName)
if !objectFormat.IsValid(comment.CommitID) {
if !git.IsStringValidObjectID(objectFormat, comment.CommitID) {
log.Warn("Invalid comment CommitID[%s] on comment[%d] in PR #%d of %s/%s replaced with %s", comment.CommitID, pr.Index, g.repoOwner, g.repoName, headCommitID)
comment.CommitID = headCommitID
}