aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorJason Song <i@wolfogre.com>2022-12-27 21:12:49 +0800
committerGitHub <noreply@github.com>2022-12-27 21:12:49 +0800
commit6cf09ccab402fe84a5313e1d3e755e284ebbc845 (patch)
treeb1fad807c2a16fded8b6bda84583c421ec86230c /models
parent90237d8abd0e6479c1464ac0f32fff6a2ce4a0b4 (diff)
downloadgitea-6cf09ccab402fe84a5313e1d3e755e284ebbc845.tar.gz
gitea-6cf09ccab402fe84a5313e1d3e755e284ebbc845.zip
Use complete SHA to create and query commit status (#22244)
Fix #13485. Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'models')
-rw-r--r--models/activities/action.go2
-rw-r--r--models/git/commit_status.go4
2 files changed, 5 insertions, 1 deletions
diff --git a/models/activities/action.go b/models/activities/action.go
index 1ac1be7135..4baedbfe12 100644
--- a/models/activities/action.go
+++ b/models/activities/action.go
@@ -272,7 +272,7 @@ func (a *Action) GetRefLink() string {
return a.GetRepoLink() + "/src/branch/" + util.PathEscapeSegments(strings.TrimPrefix(a.RefName, git.BranchPrefix))
case strings.HasPrefix(a.RefName, git.TagPrefix):
return a.GetRepoLink() + "/src/tag/" + util.PathEscapeSegments(strings.TrimPrefix(a.RefName, git.TagPrefix))
- case len(a.RefName) == 40 && git.IsValidSHAPattern(a.RefName):
+ case len(a.RefName) == git.SHAFullLength && git.IsValidSHAPattern(a.RefName):
return a.GetRepoLink() + "/src/commit/" + a.RefName
default:
// FIXME: we will just assume it's a branch - this was the old way - at some point we may want to enforce that there is always a ref here.
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)