c572fcfe04
Rename the Go module path from code.gitea.io/gitea to git.mokoconsulting.tech/MokoConsulting/MokoGitea across the entire codebase. Scope: - go.mod module declaration - 2,235 Go source files (import paths) - Dockerfile WORKDIR and COPY paths - Swagger API templates - golangci.yml linter config External dependencies (code.gitea.io/gitea-vet, code.gitea.io/sdk/gitea, gitea.com/gitea/act, etc.) are intentionally NOT renamed — they are separate upstream modules. Closes #132 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 "git.mokoconsulting.tech/MokoConsulting/MokoGitea/models/git"
|
|
repo_model "git.mokoconsulting.tech/MokoConsulting/MokoGitea/models/repo"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/git"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/gitrepo"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/reqctx"
|
|
"git.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
|
|
}
|