From 6cf09ccab402fe84a5313e1d3e755e284ebbc845 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 27 Dec 2022 21:12:49 +0800 Subject: Use complete SHA to create and query commit status (#22244) Fix #13485. Co-authored-by: delvh Co-authored-by: Lauris BH Co-authored-by: Lunny Xiao --- models/git/commit_status.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'models/git/commit_status.go') diff --git a/models/git/commit_status.go b/models/git/commit_status.go index 0fb0bc66af..07e0b9fb73 100644 --- a/models/git/commit_status.go +++ b/models/git/commit_status.go @@ -279,6 +279,10 @@ func NewCommitStatus(opts NewCommitStatusOptions) error { return fmt.Errorf("NewCommitStatus[%s, %s]: no user specified", repoPath, opts.SHA) } + if _, err := git.NewIDFromString(opts.SHA); err != nil { + return fmt.Errorf("NewCommitStatus[%s, %s]: invalid sha: %w", repoPath, opts.SHA, err) + } + ctx, committer, err := db.TxContext(db.DefaultContext) if err != nil { return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %w", opts.Repo.ID, opts.Creator.ID, opts.SHA, err) -- cgit v1.2.3