合并develop分支代码到master #49

Merged
yystopf merged 15 commits from develop into master 2022-03-11 09:41:39 +08:00
15 changed files with 220 additions and 39 deletions

View File

@ -19,7 +19,7 @@ func registerUpdateMirrorTask() {
RegisterTaskFatal("update_mirrors", &BaseConfig{
Enabled: true,
RunAtStart: false,
Schedule: "@every 10m",
Schedule: "@every 24h",
NoSuccessNotice: true,
}, func(ctx context.Context, _ *models.User, _ Config) error {
return mirror_service.Update(ctx)

View File

@ -212,7 +212,9 @@ func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*
if err != nil {
return nil, err
}
contentsResponse.SubmoduleGitURL = &submodule.URL
if submodule != nil {
contentsResponse.SubmoduleGitURL = &submodule.URL
}
}
// Handle links
if entry.IsRegular() || entry.IsLink() {

View 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"`
}

View File

@ -747,6 +747,10 @@ 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)
@ -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))

View File

@ -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)
}

View File

@ -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"
@ -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,

View File

@ -1144,6 +1144,7 @@ func PrepareCompareDiff(
// gitRepo, _ := git.OpenRepository(repoPath)
gitRepo, _ := git.OpenRepository(repoPath)
defer gitRepo.Close()
diff, err := gitdiff.GetDiffRange(gitRepo,
compareInfo.MergeBase, headCommitID, setting.Git.MaxGitDiffLines,

View File

@ -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"
@ -300,20 +301,66 @@ func BranchTagCount(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/RepoBranchAndTagCount"
tags, err := ctx.Repo.GitRepo.GetTagInfos(0, 0) // tags info
tagsCount, err := ctx.Repo.GitRepo.GetTagCount() // tags info
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetTags", err)
ctx.Error(http.StatusInternalServerError, "GetTagCount", err)
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
}
result := api.RepoBranchAndTagCount{
BranchCount: countAll,
TagCount: len(tags),
TagCount: int(tagsCount),
}
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)
}

View File

@ -13,6 +13,7 @@ import (
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/web"
webWiki "code.gitea.io/gitea/routers/web/repo"
"github.com/russross/blackfriday/v2"
wiki_service "code.gitea.io/gitea/services/wiki"
)
@ -282,6 +283,7 @@ func GetWiki(ctx *context.APIContext) {
}
var buf strings.Builder
content := blackfriday.Run(data)
if err := markdown.Render(rctx, bytes.NewReader(data), &buf); err != nil {
if wikiRepo != nil {
wikiRepo.Close()
@ -320,7 +322,7 @@ func GetWiki(ctx *context.APIContext) {
},
CommitCounts: commitsCount,
MdContent: string(data),
SimpleContent: buf.String(),
SimpleContent: string(content),
}
ctx.JSON(http.StatusOK, wiki)
}

View File

@ -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 {

View File

@ -111,7 +111,8 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID
URL: form.Config["url"],
ContentType: models.ToHookContentType(form.Config["content_type"]),
Secret: form.Config["secret"],
HTTPMethod: "POST",
// HTTPMethod: "POST",
HTTPMethod: form.Config["http_method"],
HookEvent: &models.HookEvent{
ChooseEvents: true,
HookEvents: models.HookEvents{

View File

@ -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

View File

@ -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

View File

@ -92,30 +92,32 @@ func StartRepositoryTransfer(doer, newOwner *models.User, repo *models.Repositor
if allowed {
return TransferOwnership(doer, newOwner, repo, teams)
}
} else {
return TransferOwnership(doer, newOwner, repo, teams)
}
// In case the new owner would not have sufficient access to the repo, give access rights for read
hasAccess, err := models.HasAccess(newOwner.ID, repo)
if err != nil {
return err
}
if !hasAccess {
if err := repo.AddCollaborator(newOwner); err != nil {
return err
}
if err := repo.ChangeCollaborationAccessMode(newOwner.ID, models.AccessModeRead); err != nil {
return err
}
}
// hasAccess, err := models.HasAccess(newOwner.ID, repo)
// if err != nil {
// return err
// }
// if !hasAccess {
// if err := repo.AddCollaborator(newOwner); err != nil {
// return err
// }
// if err := repo.ChangeCollaborationAccessMode(newOwner.ID, models.AccessModeRead); err != nil {
// return err
// }
// }
// Make repo as pending for transfer
repo.Status = models.RepositoryPendingTransfer
if err := models.CreatePendingRepositoryTransfer(doer, newOwner, repo.ID, teams); err != nil {
return err
}
// repo.Status = models.RepositoryPendingTransfer
// if err := models.CreatePendingRepositoryTransfer(doer, newOwner, repo.ID, teams); err != nil {
// return err
// }
// notify users who are able to accept / reject transfer
notification.NotifyRepoPendingTransfer(doer, newOwner, repo)
// notification.NotifyRepoPendingTransfer(doer, newOwner, repo)
return nil
}

View File

@ -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",
@ -18331,6 +18377,15 @@
}
}
},
"BranchNameSet": {
"description": "BranchNameSet",
"schema": {
"$ref": "#/definitions/BranchNameSet"
},
"headers": {
"body": {}
}
},
"BranchProtection": {
"description": "BranchProtection",
"schema": {