forked from Gitlink/gitea-1156
Merge branch 'develop' of https://code.gitlink.org.cn/Gitlink/gitea-1156 into develop
This commit is contained in:
commit
923361a26b
|
@ -144,6 +144,7 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]
|
|||
})
|
||||
}
|
||||
}
|
||||
commit.LoadBranchName()
|
||||
|
||||
return &api.Commit{
|
||||
CommitDate: commit.Committer.When.Format("2006-01-02"), // new time format, year-moon-day
|
||||
|
@ -178,5 +179,6 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]
|
|||
Committer: apiCommitter,
|
||||
Parents: apiParents,
|
||||
Files: affectedFileList,
|
||||
Branch: commit.Branch,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
package repofiles
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
|
@ -12,6 +13,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
)
|
||||
|
||||
|
@ -37,7 +39,7 @@ func (ct *ContentType) String() string {
|
|||
|
||||
// GetContentsOrList gets the meta data of a file's contents (*ContentsResponse) if treePath not a tree
|
||||
// directory, otherwise a listing of file contents ([]*ContentsResponse). Ref can be a branch, commit or tag
|
||||
func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface{}, error) {
|
||||
func GetContentsOrList(ctx context.Context, repo *models.Repository, treePath, ref string) (interface{}, error) {
|
||||
if repo.IsEmpty {
|
||||
return make([]interface{}, 0), nil
|
||||
}
|
||||
|
@ -87,12 +89,38 @@ func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//add at 2021-12-27
|
||||
commitsInfo, _, err := entries.GetCommitsInfo(ctx, commit, treePath, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// end
|
||||
for _, e := range entries {
|
||||
subTreePath := path.Join(treePath, e.Name())
|
||||
|
||||
name := e.Blob().Name()
|
||||
log.Info(" entrie name = %s", name)
|
||||
|
||||
subTreePath := path.Join(treePath, name)
|
||||
fileContentResponse, err := GetContents(repo, subTreePath, origRef, true)
|
||||
for _, commitInfo := range commitsInfo {
|
||||
if commitInfo.Entry.Name() == fileContentResponse.Name {
|
||||
var entryCommit *git.Commit
|
||||
entryCommit = commitInfo.Commit
|
||||
if e.IsSubModule() {
|
||||
entryCommit = commitInfo.SubModuleFile.Commit
|
||||
}
|
||||
fileContentResponse.LatestCommit = api.ContentsResponseCommit{
|
||||
Message: entryCommit.CommitMessage,
|
||||
LatestCommitSha: entryCommit.ID.String(),
|
||||
Created: entryCommit.Author.When.Unix(),
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fileList = append(fileList, fileContentResponse)
|
||||
}
|
||||
return fileList, nil
|
||||
|
|
|
@ -49,6 +49,7 @@ type Commit struct {
|
|||
Parents []*CommitMeta `json:"parents"`
|
||||
Files []*CommitAffectedFiles `json:"files"`
|
||||
CommitDate string `json:"commit_date"`
|
||||
Branch string `json:"branch"`
|
||||
}
|
||||
|
||||
// CommitDateOptions store dates for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE
|
||||
|
|
|
@ -57,6 +57,13 @@ type FileLinksResponse struct {
|
|||
HTMLURL *string `json:"html"`
|
||||
}
|
||||
|
||||
//add
|
||||
type ContentsResponseCommit struct {
|
||||
Message string `json:"message"`
|
||||
LatestCommitSha string `json:"sha"`
|
||||
Created int64 `json:"created_at"`
|
||||
}
|
||||
|
||||
// ContentsResponse contains information about a repo's entry's (dir, file, symlink, submodule) metadata and content
|
||||
type ContentsResponse struct {
|
||||
Name string `json:"name"`
|
||||
|
@ -76,8 +83,9 @@ type ContentsResponse struct {
|
|||
GitURL *string `json:"git_url"`
|
||||
DownloadURL *string `json:"download_url"`
|
||||
// `submodule_git_url` is populated when `type` is `submodule`, otherwise null
|
||||
SubmoduleGitURL *string `json:"submodule_git_url"`
|
||||
Links *FileLinksResponse `json:"_links"`
|
||||
SubmoduleGitURL *string `json:"submodule_git_url"`
|
||||
Links *FileLinksResponse `json:"_links"`
|
||||
LatestCommit ContentsResponseCommit `json:"latest_commit"`
|
||||
}
|
||||
|
||||
// FileCommitResponse contains information generated from a Git commit for a repo's file.
|
||||
|
|
|
@ -53,3 +53,7 @@ type RepoBranchAndTagCount struct {
|
|||
BranchCount int `json:"branch_count"`
|
||||
TagCount int `json:"tag_count"`
|
||||
}
|
||||
|
||||
type BranchNameSet struct {
|
||||
BranchName []*string `json:"branch_name"`
|
||||
}
|
||||
|
|
|
@ -747,12 +747,16 @@ func Routes() *web.Route {
|
|||
})
|
||||
}, reqToken(), reqAdmin(), reqGitHook(), context.ReferencesGitRepo(true))
|
||||
|
||||
m.Group("", func() {
|
||||
// m.Get("/graph", repo.Graph)
|
||||
m.Get("/commits/{sha:([a-f0-9]{7,40})$}/diff", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.Diff)
|
||||
}, repo.MustBeNotEmpty, context.RepoRef(), reqRepoCodeReader)
|
||||
m.Group("/commits/count", func() {
|
||||
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.GetCommitsCount)
|
||||
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.GetCommitsCount)
|
||||
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.GetCommitsCount)
|
||||
})
|
||||
m.Group("/pulls/:index", func() {
|
||||
m.Group("/pulls/{index}", func() {
|
||||
m.Get("/commits", context.RepoRef(), repo.GetPullCommits)
|
||||
m.Get("/files", context.RepoRef(), repo.GetPullFiles)
|
||||
m.Get("/issues", context.RepoRef(), repo.GetPullIssues)
|
||||
|
@ -835,7 +839,7 @@ func Routes() *web.Route {
|
|||
m.Get("/*", repo.GetReadmeContentsByPath)
|
||||
})
|
||||
m.Get("/commits_slice", repo.GetAllCommitsSliceByTime)
|
||||
// m.Get("/branchtagcount", repo.BranchTagCount)
|
||||
m.Get("/branch_name_set", repo.BranchNameSet)
|
||||
m.Group("/branch_tag_count", func() {
|
||||
m.Get("", repo.BranchTagCount)
|
||||
}, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(true))
|
||||
|
@ -967,7 +971,7 @@ func Routes() *web.Route {
|
|||
m.Get(".diff", repo.DownloadPullDiff)
|
||||
m.Get(".patch", repo.DownloadPullPatch)
|
||||
m.Post("/update", reqToken(), repo.UpdatePullRequest)
|
||||
m.Get("/commits", repo.GetPullRequestCommits)
|
||||
// m.Get("/commits", repo.GetPullRequestCommits)
|
||||
m.Combo("/merge").Get(repo.IsPullRequestMerged).
|
||||
Post(reqToken(), mustNotBeArchived, bind(forms.MergePullRequestForm{}), repo.MergePullRequest)
|
||||
m.Group("/reviews", func() {
|
||||
|
|
|
@ -16,10 +16,12 @@ import (
|
|||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/validation"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
"code.gitea.io/gitea/services/gitdiff"
|
||||
)
|
||||
|
||||
// GetSingleCommit get a commit via sha
|
||||
|
@ -535,3 +537,40 @@ func GetFileAllCommits(ctx *context.APIContext) {
|
|||
|
||||
ctx.JSON(http.StatusOK, apiCommits)
|
||||
}
|
||||
|
||||
// 获取 commit diff
|
||||
func Diff(ctx *context.APIContext) {
|
||||
|
||||
commitID := ctx.Params(":sha")
|
||||
|
||||
gitRepo := ctx.Repo.GitRepo
|
||||
|
||||
log.Info("gitRepo = ", gitRepo)
|
||||
|
||||
commit, err := gitRepo.GetCommit(commitID)
|
||||
log.Info("commit=\n", commit)
|
||||
|
||||
if err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.NotFound("Repo.GitRepo.GetCommit", err)
|
||||
} else {
|
||||
ctx.Error(http.StatusInternalServerError, "Repo.GitRepo.GetCommit", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if len(commitID) != 40 {
|
||||
commitID = commit.ID.String()
|
||||
}
|
||||
diff, err := gitdiff.GetDiffCommit(gitRepo,
|
||||
commitID, setting.Git.MaxGitDiffLines,
|
||||
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles)
|
||||
if err != nil {
|
||||
ctx.NotFound("GetDiffCommitWithWhitespaceBehavior", err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
ctx.NotFound("GetDiffCommit", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, &diff)
|
||||
}
|
||||
|
|
|
@ -6,9 +6,11 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
@ -18,6 +20,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/repofiles"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
|
@ -557,7 +560,7 @@ func GetContents(ctx *context.APIContext) {
|
|||
treePath := ctx.Params("*")
|
||||
ref := ctx.QueryTrim("ref")
|
||||
|
||||
if fileList, err := repofiles.GetContentsOrList(ctx.Repo.Repository, treePath, ref); err != nil {
|
||||
if fileList, err := repofiles.GetContentsOrList(ctx, ctx.Repo.Repository, treePath, ref); err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.NotFound("GetContentsOrList", err)
|
||||
return
|
||||
|
@ -641,7 +644,7 @@ func GetReadmeContents(ctx *context.APIContext) {
|
|||
// treePath := ctx.Params("*")
|
||||
ref := ctx.QueryTrim("ref")
|
||||
|
||||
if fileList, err := repofiles.GetContentsOrList(ctx.Repo.Repository, "README.md", ref); err != nil {
|
||||
if fileList, err := repofiles.GetContentsOrList(ctx, ctx.Repo.Repository, "README.md", ref); err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.NotFound("GetContentsOrList", err)
|
||||
return
|
||||
|
@ -696,7 +699,7 @@ func GetReadmeContentsByPath(ctx *context.APIContext) {
|
|||
treePath := ctx.Params("*")
|
||||
ref := ctx.QueryTrim("ref")
|
||||
newTreePath := treePath + "/" + "README.md"
|
||||
if fileList, err := repofiles.GetContentsOrList(ctx.Repo.Repository, newTreePath, ref); err != nil {
|
||||
if fileList, err := repofiles.GetContentsOrList(ctx, ctx.Repo.Repository, newTreePath, ref); err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.NotFound("GetContentsOrList", err)
|
||||
return
|
||||
|
@ -717,7 +720,7 @@ func safeURL(address string) string {
|
|||
}
|
||||
|
||||
const (
|
||||
tplMigrating base.TplName = "repo/migrating"
|
||||
tplMigrating base.TplName = "repo/migrate/migrating"
|
||||
tplRepoEMPTY base.TplName = "repo/empty"
|
||||
)
|
||||
|
||||
|
@ -738,10 +741,19 @@ func GetFileContents(ctx *context.APIContext) {
|
|||
ctx.Data["Repo"] = ctx.Repo
|
||||
ctx.Data["MigrateTask"] = task
|
||||
ctx.Data["CloneAddr"] = safeURL(cfg.CloneAddr)
|
||||
ctx.HTML(200, tplMigrating)
|
||||
ctx.Data["Failed"] = task.Status == api.TaskStatusFailed
|
||||
ctx.HTML(http.StatusOK, tplMigrating)
|
||||
return
|
||||
}
|
||||
|
||||
if ctx.IsSigned {
|
||||
// Set repo notification-status read if unread
|
||||
if err := ctx.Repo.Repository.ReadBy(ctx.User.ID); err != nil {
|
||||
ctx.ServerError("ReadBy", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var firstUnit *models.Unit
|
||||
for _, repoUnit := range ctx.Repo.Units {
|
||||
if repoUnit.Type == models.UnitTypeCode {
|
||||
|
@ -751,6 +763,7 @@ func GetFileContents(ctx *context.APIContext) {
|
|||
}{
|
||||
Content: ctx.Data["FileContent"],
|
||||
}
|
||||
log.Info("filecontent = \n", fileContent)
|
||||
ctx.JSON(http.StatusOK, fileContent)
|
||||
return
|
||||
}
|
||||
|
@ -774,7 +787,7 @@ func renderCode(ctx *context.Context) {
|
|||
ctx.Data["PageIsViewCode"] = true
|
||||
|
||||
if ctx.Repo.Repository.IsEmpty {
|
||||
ctx.HTML(200, tplRepoEMPTY)
|
||||
ctx.HTML(http.StatusOK, tplRepoEMPTY)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -786,7 +799,7 @@ func renderCode(ctx *context.Context) {
|
|||
|
||||
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
|
||||
treeLink := branchLink
|
||||
// rawLink := ctx.Repo.RepoLink + "/raw/" + ctx.Repo.BranchNameSubURL()
|
||||
rawLink := ctx.Repo.RepoLink + "/raw/" + ctx.Repo.BranchNameSubURL()
|
||||
|
||||
if len(ctx.Repo.TreePath) > 0 {
|
||||
treeLink += "/" + ctx.Repo.TreePath
|
||||
|
@ -801,6 +814,7 @@ func renderCode(ctx *context.Context) {
|
|||
// Get current entry user currently looking at.
|
||||
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
|
||||
if err != nil {
|
||||
ctx.NotFoundOrServerError("Repo.Commit.GetTreeEntryByPath", git.IsErrNotExist, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -810,9 +824,9 @@ func renderCode(ctx *context.Context) {
|
|||
}
|
||||
|
||||
if entry.IsDir() {
|
||||
// renderDirectory(ctx, treeLink)
|
||||
repo.RenderDirectory(ctx, treeLink)
|
||||
} else {
|
||||
// renderFile(ctx, entry, treeLink, rawLink)
|
||||
repo.RenderFile(ctx, entry, treeLink, rawLink)
|
||||
}
|
||||
if ctx.Written() {
|
||||
return
|
||||
|
@ -836,9 +850,8 @@ func renderCode(ctx *context.Context) {
|
|||
ctx.Data["TreeLink"] = treeLink
|
||||
ctx.Data["TreeNames"] = treeNames
|
||||
ctx.Data["BranchLink"] = branchLink
|
||||
// ctx.HTML(200, tplRepoHome)
|
||||
// ctx.HTML(http.StatusOK, tplRepoHome)
|
||||
}
|
||||
|
||||
func renderRepoTopics(ctx *context.Context) {
|
||||
topics, err := models.FindTopics(&models.FindTopicOptions{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
|
|
|
@ -1332,10 +1332,13 @@ func GetPullRequestCommits(ctx *context.APIContext) {
|
|||
ctx.JSON(http.StatusOK, &apiCommits)
|
||||
}
|
||||
|
||||
type PullRequestCommit struct {
|
||||
models.SignCommitWithStatuses
|
||||
Sha string
|
||||
}
|
||||
|
||||
func GetPullCommits(ctx *context.APIContext) {
|
||||
// issue := checkPullInfo(ctx.Context)
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
issue := pr.Issue
|
||||
issue := checkPullInfo(ctx.Context)
|
||||
if issue == nil {
|
||||
ctx.NotFound()
|
||||
return
|
||||
|
@ -1362,63 +1365,39 @@ func GetPullCommits(ctx *context.APIContext) {
|
|||
|
||||
ctx.Data["Username"] = ctx.Repo.Owner.Name
|
||||
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
|
||||
|
||||
var commitNum int
|
||||
commits = prInfo.Commits
|
||||
commits = models.ValidateCommitsWithEmails(commits)
|
||||
commits = models.ParseCommitsWithSignature(commits, ctx.Repo.Repository)
|
||||
commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
|
||||
commitNum = commits.Len()
|
||||
//get pull changedfils
|
||||
var (
|
||||
// diffRepoPath string
|
||||
startCommitID string
|
||||
endCommitID string
|
||||
gitRepo = ctx.Repo.GitRepo
|
||||
)
|
||||
gitRepo = ctx.Repo.GitRepo
|
||||
headCommitId, err := gitRepo.GetRefCommitID(pull.GetGitRefName())
|
||||
if err != nil {
|
||||
ctx.ServerError("GetRefCommitID", err)
|
||||
return
|
||||
}
|
||||
startCommitID = prInfo.MergeBase
|
||||
endCommitID = headCommitId
|
||||
ctx.Data["WhitespaceBehavior"] = ""
|
||||
|
||||
diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(gitRepo,
|
||||
startCommitID, endCommitID, setting.Git.MaxGitDiffLines,
|
||||
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles,
|
||||
gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)))
|
||||
if err != nil {
|
||||
ctx.ServerError("GetDiffRangeWithWhitespaceBehavior", err)
|
||||
return
|
||||
result := make([]PullRequestCommit, 0)
|
||||
// result := make([]models.SignCommitWithStatuses, 0)
|
||||
for commit := commits.Front(); commit != nil; commit = commit.Next() {
|
||||
temp := commit.Value.(models.SignCommitWithStatuses)
|
||||
pullRequestCommit := PullRequestCommit{
|
||||
temp,
|
||||
temp.ID.String(),
|
||||
}
|
||||
result = append(result, pullRequestCommit)
|
||||
}
|
||||
var changedFiles int
|
||||
changedFiles = diff.NumFiles
|
||||
pr.CommitNum = commitNum
|
||||
pr.ChangedFiles = changedFiles
|
||||
ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(pr, ctx.User))
|
||||
|
||||
ctx.JSON(200, result)
|
||||
}
|
||||
func GetPullFiles(ctx *context.APIContext) {
|
||||
issue := checkPullInfo(ctx.Context)
|
||||
|
||||
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
issue := pr.Issue
|
||||
if issue == nil {
|
||||
ctx.NotFound()
|
||||
ctx.NotFound("checkPullInfo", nil)
|
||||
|
||||
return
|
||||
}
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
pull := issue.PullRequest
|
||||
|
||||
whitespaceFlags := map[string]string{
|
||||
"ignore-all": "-w",
|
||||
"ignore-change": "-b",
|
||||
"ignore-eol": "--ignore-space-at-eol",
|
||||
"": ""}
|
||||
|
||||
var (
|
||||
// diffRepoPath string
|
||||
// diffRepoPath
|
||||
startCommitID string
|
||||
endCommitID string
|
||||
gitRepo *git.Repository
|
||||
|
@ -1446,15 +1425,15 @@ func GetPullFiles(ctx *context.APIContext) {
|
|||
ctx.ServerError("GetRefCommitID", err)
|
||||
return
|
||||
}
|
||||
|
||||
// diffRepoPath = ctx.Repo.GitRepo.Path
|
||||
startCommitID = prInfo.MergeBase
|
||||
endCommitID = headCommitID
|
||||
|
||||
ctx.Data["WhitespaceBehavior"] = ""
|
||||
diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(ctx.Repo.GitRepo,
|
||||
diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(gitRepo,
|
||||
startCommitID, endCommitID, setting.Git.MaxGitDiffLines,
|
||||
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles,
|
||||
whitespaceFlags[ctx.Data["WhitespaceBehavior"].(string)])
|
||||
gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)))
|
||||
if err != nil {
|
||||
ctx.ServerError("GetDiffRangeWithWhitespaceBehavior", err)
|
||||
return
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
|
@ -306,7 +307,7 @@ func BranchTagCount(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
repo := ctx.Repo.Repository
|
||||
_, countAll, err := repo_module.GetBranches(repo, -1, -1) //get count of the branch
|
||||
_, countAll, err := repo_module.GetBranches(repo, 0, 0) //get count of the branch
|
||||
if err != nil {
|
||||
ctx.ServerError("GetBranches", err)
|
||||
return
|
||||
|
@ -317,3 +318,49 @@ func BranchTagCount(ctx *context.APIContext) {
|
|||
}
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
func BranchNameSet(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/branch_name_set repository repoBranchNameSet
|
||||
// ---
|
||||
// summary: List a repository's branch name***
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: owner of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
// in: path
|
||||
// description: name of the repo
|
||||
// type: string
|
||||
// required: true
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/BranchNameSet"
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
branches, _, err := repo_module.GetBranches(repo, 0, 0) //get count of the branch
|
||||
if err != nil {
|
||||
ctx.ServerError("GetBranches", err)
|
||||
return
|
||||
}
|
||||
|
||||
var branchNameSet = make([]*string, 0)
|
||||
|
||||
// var branchNameSet [len(branches)]string
|
||||
for _, branch := range branches {
|
||||
|
||||
log.Info("branches is \n", branch.Name)
|
||||
branchNameSet = append(branchNameSet, &branch.Name)
|
||||
|
||||
}
|
||||
|
||||
result := api.BranchNameSet{
|
||||
BranchName: branchNameSet,
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
|
||||
}
|
||||
|
|
|
@ -72,6 +72,12 @@ type swaggerResponseRepoBranchAndTagCount struct {
|
|||
Body api.RepoBranchAndTagCount `json:"body"`
|
||||
}
|
||||
|
||||
// BranchNameSet
|
||||
// swagger:response BranchNameSet
|
||||
type swaggerResponseBranchNameSet struct {
|
||||
Body api.BranchNameSet `json:"body"`
|
||||
}
|
||||
|
||||
// TagList
|
||||
// swagger:response TagList
|
||||
type swaggerResponseTagList struct {
|
||||
|
|
|
@ -128,7 +128,7 @@ func getReadmeFileFromPath(commit *git.Commit, treePath string) (*namedBlob, err
|
|||
return readmeFile, nil
|
||||
}
|
||||
|
||||
func renderDirectory(ctx *context.Context, treeLink string) {
|
||||
func RenderDirectory(ctx *context.Context, treeLink string) {
|
||||
tree, err := ctx.Repo.Commit.SubTree(ctx.Repo.TreePath)
|
||||
if err != nil {
|
||||
ctx.NotFoundOrServerError("Repo.Commit.SubTree", git.IsErrNotExist, err)
|
||||
|
@ -396,7 +396,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
|
|||
ctx.Data["SSHDomain"] = setting.SSH.Domain
|
||||
}
|
||||
|
||||
func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink string) {
|
||||
func RenderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink string) {
|
||||
ctx.Data["IsViewFile"] = true
|
||||
blob := entry.Blob()
|
||||
dataRc, err := blob.DataAsync()
|
||||
|
@ -728,9 +728,9 @@ func renderCode(ctx *context.Context) {
|
|||
}
|
||||
|
||||
if entry.IsDir() {
|
||||
renderDirectory(ctx, treeLink)
|
||||
RenderDirectory(ctx, treeLink)
|
||||
} else {
|
||||
renderFile(ctx, entry, treeLink, rawLink)
|
||||
RenderFile(ctx, entry, treeLink, rawLink)
|
||||
}
|
||||
if ctx.Written() {
|
||||
return
|
||||
|
|
|
@ -1217,6 +1217,11 @@ func GetDiffRange(gitRepo *git.Repository, beforeCommitID, afterCommitID string,
|
|||
return GetDiffRangeWithWhitespaceBehavior(gitRepo, beforeCommitID, afterCommitID, maxLines, maxLineCharacters, maxFiles, "")
|
||||
}
|
||||
|
||||
// GetDiffCommit builds a Diff representing the given commitID.
|
||||
func GetDiffCommit(gitRepo *git.Repository, commitID string, maxLines, maxLineCharacters, maxFiles int) (*Diff, error) {
|
||||
return GetDiffRange(gitRepo, "", commitID, maxLines, maxLineCharacters, maxFiles)
|
||||
}
|
||||
|
||||
// GetDiffRangeWithWhitespaceBehavior builds a Diff between two commits of a repository.
|
||||
// Passing the empty string as beforeCommitID returns a diff from the parent commit.
|
||||
// The whitespaceBehavior is either an empty string or a git flag
|
||||
|
|
|
@ -2424,6 +2424,39 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/branch_name_set": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"repository"
|
||||
],
|
||||
"summary": "List a repository's branch name***",
|
||||
"operationId": "repoBranchNameSet",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "owner of the repo",
|
||||
"name": "owner",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "name of the repo",
|
||||
"name": "repo",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/BranchNameSet"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/repos/{owner}/{repo}/branch_protections": {
|
||||
"get": {
|
||||
"produces": [
|
||||
|
@ -13037,6 +13070,19 @@
|
|||
},
|
||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||
},
|
||||
"BranchNameSet": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"branch_name": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"x-go-name": "BranchName"
|
||||
}
|
||||
},
|
||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||
},
|
||||
"BranchProtection": {
|
||||
"description": "BranchProtection represents a branch protection for a repository",
|
||||
"type": "object",
|
||||
|
@ -13268,6 +13314,10 @@
|
|||
"author": {
|
||||
"$ref": "#/definitions/User"
|
||||
},
|
||||
"branch": {
|
||||
"type": "string",
|
||||
"x-go-name": "Branch"
|
||||
},
|
||||
"commit": {
|
||||
"$ref": "#/definitions/RepoCommit"
|
||||
},
|
||||
|
@ -13458,6 +13508,9 @@
|
|||
"type": "string",
|
||||
"x-go-name": "HTMLURL"
|
||||
},
|
||||
"latest_commit": {
|
||||
"$ref": "#/definitions/ContentsResponseCommit"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"x-go-name": "Name"
|
||||
|
@ -13497,6 +13550,26 @@
|
|||
},
|
||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||
},
|
||||
"ContentsResponseCommit": {
|
||||
"description": "add",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"created_at": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"x-go-name": "Created"
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"x-go-name": "Message"
|
||||
},
|
||||
"sha": {
|
||||
"type": "string",
|
||||
"x-go-name": "LatestCommitSha"
|
||||
}
|
||||
},
|
||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||
},
|
||||
"ContributorsDto": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -14878,6 +14951,7 @@
|
|||
"x-go-name": "Visibility"
|
||||
},
|
||||
"website": {
|
||||
"description": "Website string `json:\"website\" binding:\"ValidUrl;MaxSize(255)\"`",
|
||||
"type": "string",
|
||||
"x-go-name": "Website"
|
||||
}
|
||||
|
@ -18303,6 +18377,15 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"BranchNameSet": {
|
||||
"description": "BranchNameSet",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/BranchNameSet"
|
||||
},
|
||||
"headers": {
|
||||
"body": {}
|
||||
}
|
||||
},
|
||||
"BranchProtection": {
|
||||
"description": "BranchProtection",
|
||||
"schema": {
|
||||
|
|
Loading…
Reference in New Issue