9a5720e8ad
Universal: PR Check / Branch Policy (pull_request) Successful in 1s
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 3s
Universal: PR Check / Validate PR (pull_request) Failing after 6s
Branch Cleanup / Delete merged branch (pull_request) Successful in 1s
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Full namespace migration: update the Go module path and all import statements from git.mokoconsulting.tech to code.mokoconsulting.tech. Also updates all URL references in templates, workflows, configs, tests, and documentation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
63 lines
2.2 KiB
Go
63 lines
2.2 KiB
Go
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package utils
|
|
|
|
import (
|
|
"errors"
|
|
|
|
git_model "code.mokoconsulting.tech/MokoConsulting/MokoGitea/models/git"
|
|
repo_model "code.mokoconsulting.tech/MokoConsulting/MokoGitea/models/repo"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/git"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/gitrepo"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/reqctx"
|
|
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/services/context"
|
|
)
|
|
|
|
type RefCommit struct {
|
|
InputRef string
|
|
RefName git.RefName
|
|
Commit *git.Commit
|
|
CommitID string
|
|
}
|
|
|
|
// ResolveRefCommit resolve ref to a commit if exist
|
|
func ResolveRefCommit(ctx reqctx.RequestContext, repo *repo_model.Repository, inputRef string, minCommitIDLen ...int) (_ *RefCommit, err error) {
|
|
gitRepo, err := gitrepo.RepositoryFromRequestContextOrOpen(ctx, repo)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
refCommit := RefCommit{InputRef: inputRef}
|
|
if exist, _ := git_model.IsBranchExist(ctx, repo.ID, inputRef); exist {
|
|
refCommit.RefName = git.RefNameFromBranch(inputRef)
|
|
} else if gitrepo.IsTagExist(ctx, repo, inputRef) {
|
|
refCommit.RefName = git.RefNameFromTag(inputRef)
|
|
} else if git.IsStringLikelyCommitID(git.ObjectFormatFromName(repo.ObjectFormatName), inputRef, minCommitIDLen...) {
|
|
refCommit.RefName = git.RefNameFromCommit(inputRef)
|
|
}
|
|
if refCommit.RefName == "" {
|
|
return nil, git.ErrNotExist{ID: inputRef}
|
|
}
|
|
if refCommit.Commit, err = gitRepo.GetCommit(refCommit.RefName.String()); err != nil {
|
|
return nil, err
|
|
}
|
|
refCommit.CommitID = refCommit.Commit.ID.String()
|
|
return &refCommit, nil
|
|
}
|
|
|
|
func NewRefCommit(refName git.RefName, commit *git.Commit) *RefCommit {
|
|
return &RefCommit{InputRef: refName.ShortName(), RefName: refName, Commit: commit, CommitID: commit.ID.String()}
|
|
}
|
|
|
|
// GetGitRefs return git references based on filter
|
|
func GetGitRefs(ctx *context.APIContext, filter string) ([]*git.Reference, string, error) {
|
|
if ctx.Repo.GitRepo == nil {
|
|
return nil, "", errors.New("no open git repo found in context")
|
|
}
|
|
if len(filter) > 0 {
|
|
filter = "refs/" + filter
|
|
}
|
|
refs, err := ctx.Repo.GitRepo.GetRefsFiltered(filter)
|
|
return refs, "GetRefsFiltered", err
|
|
}
|