From 1b6acb85ec84172254cb0327ded925c5b9de5472 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Fri, 25 Sep 2020 10:56:39 +0800 Subject: [PATCH] Add IsTemplate option in create repo ui and api Signed-off-by: a1012112796 <1012112796@qq.com> --- integrations/api_helper_for_declarative_test.go | 1 + models/repo.go | 1 + modules/auth/repo_form.go | 1 + modules/repository/create.go | 1 + modules/structs/repo.go | 2 ++ routers/api/v1/repo/repo.go | 1 + routers/repo/repo.go | 1 + templates/repo/create.tmpl | 7 +++++++ templates/swagger/v1_json.tmpl | 5 +++++ 9 files changed, 20 insertions(+) diff --git a/integrations/api_helper_for_declarative_test.go b/integrations/api_helper_for_declarative_test.go index ec7f1d7496905..51335c8216874 100644 --- a/integrations/api_helper_for_declarative_test.go +++ b/integrations/api_helper_for_declarative_test.go @@ -48,6 +48,7 @@ func doAPICreateRepository(ctx APITestContext, empty bool, callback ...func(*tes Description: "Temporary repo", Name: ctx.Reponame, Private: true, + Template: true, Gitignores: "", License: "WTFPL", Readme: "Default", diff --git a/models/repo.go b/models/repo.go index 25fe3f63d39c9..879a739cccd76 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1079,6 +1079,7 @@ type CreateRepoOptions struct { DefaultBranch string IsPrivate bool IsMirror bool + IsTemplate bool AutoInit bool Status RepositoryStatus TrustModel TrustModelType diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go index e8809136c9d3c..039b0cb583a09 100644 --- a/modules/auth/repo_form.go +++ b/modules/auth/repo_form.go @@ -38,6 +38,7 @@ type CreateRepoForm struct { IssueLabels string License string Readme string + Template bool RepoTemplate int64 GitContent bool diff --git a/modules/repository/create.go b/modules/repository/create.go index c180b9b9481d7..e2128e4a15355 100644 --- a/modules/repository/create.go +++ b/modules/repository/create.go @@ -38,6 +38,7 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (_ *m OriginalServiceType: opts.GitServiceType, IsPrivate: opts.IsPrivate, IsFsckEnabled: !opts.IsMirror, + IsTemplate: opts.IsTemplate, CloseIssuesViaCommitInAnyBranch: setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch, Status: opts.Status, IsEmpty: !opts.AutoInit, diff --git a/modules/structs/repo.go b/modules/structs/repo.go index c86b19dfd0865..a8ca823ef6d12 100644 --- a/modules/structs/repo.go +++ b/modules/structs/repo.go @@ -109,6 +109,8 @@ type CreateRepoOption struct { IssueLabels string `json:"issue_labels"` // Whether the repository should be auto-intialized? AutoInit bool `json:"auto_init"` + // Whether the repository is template + Template bool `json:"template"` // Gitignores to use Gitignores string `json:"gitignores"` // License to use diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index b8a24e25329d9..116e413125bf7 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -245,6 +245,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateR AutoInit: opt.AutoInit, DefaultBranch: opt.DefaultBranch, TrustModel: models.ToTrustModel(opt.TrustModel), + IsTemplate: opt.Template, }) if err != nil { if models.IsErrRepoAlreadyExist(err) { diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 4a088ff9cd111..f4a2de0398a76 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -238,6 +238,7 @@ func CreatePost(ctx *context.Context, form auth.CreateRepoForm) { IsPrivate: form.Private || setting.Repository.ForcePrivate, DefaultBranch: form.DefaultBranch, AutoInit: form.AutoInit, + IsTemplate: form.Template, TrustModel: models.ToTrustModel(form.TrustModel), }) if err == nil { diff --git a/templates/repo/create.tmpl b/templates/repo/create.tmpl index 47f5406574763..d1f847b79f1c8 100644 --- a/templates/repo/create.tmpl +++ b/templates/repo/create.tmpl @@ -181,6 +181,13 @@ +