Skip to content

Commit 4dd40de

Browse files
authored
Merge branch 'main' into dont-include-global-args-in-process-manager
2 parents 90f787c + f316582 commit 4dd40de

File tree

5 files changed

+40
-20
lines changed

5 files changed

+40
-20
lines changed

models/repo_generate.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ import (
2020

2121
// GenerateRepoOptions contains the template units to generate
2222
type GenerateRepoOptions struct {
23-
Name string
24-
Description string
25-
Private bool
26-
GitContent bool
27-
Topics bool
28-
GitHooks bool
29-
Webhooks bool
30-
Avatar bool
31-
IssueLabels bool
23+
Name string
24+
DefaultBranch string
25+
Description string
26+
Private bool
27+
GitContent bool
28+
Topics bool
29+
GitHooks bool
30+
Webhooks bool
31+
Avatar bool
32+
IssueLabels bool
3233
}
3334

3435
// IsValid checks whether at least one option is chosen for generation

modules/repository/generate.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,13 @@ func generateRepoCommit(ctx context.Context, repo, templateRepo, generateRepo *r
184184
return fmt.Errorf("git remote add: %v", err)
185185
}
186186

187-
return initRepoCommit(ctx, tmpDir, repo, repo.Owner, templateRepo.DefaultBranch)
187+
// set default branch based on whether it's specified in the newly generated repo or not
188+
defaultBranch := repo.DefaultBranch
189+
if strings.TrimSpace(defaultBranch) == "" {
190+
defaultBranch = templateRepo.DefaultBranch
191+
}
192+
193+
return initRepoCommit(ctx, tmpDir, repo, repo.Owner, defaultBranch)
188194
}
189195

190196
func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *repo_model.Repository) (err error) {
@@ -208,7 +214,11 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *r
208214
return fmt.Errorf("getRepositoryByID: %v", err)
209215
}
210216

211-
repo.DefaultBranch = templateRepo.DefaultBranch
217+
// if there was no default branch supplied when generating the repo, use the default one from the template
218+
if strings.TrimSpace(repo.DefaultBranch) == "" {
219+
repo.DefaultBranch = templateRepo.DefaultBranch
220+
}
221+
212222
gitRepo, err := git.OpenRepositoryCtx(ctx, repo.RepoPath())
213223
if err != nil {
214224
return fmt.Errorf("openRepository: %v", err)
@@ -249,6 +259,7 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
249259
Name: opts.Name,
250260
LowerName: strings.ToLower(opts.Name),
251261
Description: opts.Description,
262+
DefaultBranch: opts.DefaultBranch,
252263
IsPrivate: opts.Private,
253264
IsEmpty: !opts.GitContent || templateRepo.IsEmpty,
254265
IsFsckEnabled: templateRepo.IsFsckEnabled,

modules/structs/repo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ type GenerateRepoOption struct {
201201
// required: true
202202
// unique: true
203203
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
204+
// Default branch of the new repository
205+
DefaultBranch string `json:"default_branch"`
204206
// Description of the repository to create
205207
Description string `json:"description" binding:"MaxSize(255)"`
206208
// Whether the repository is private

routers/api/v1/repo/repo.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,16 @@ func Generate(ctx *context.APIContext) {
359359
}
360360

361361
opts := models.GenerateRepoOptions{
362-
Name: form.Name,
363-
Description: form.Description,
364-
Private: form.Private,
365-
GitContent: form.GitContent,
366-
Topics: form.Topics,
367-
GitHooks: form.GitHooks,
368-
Webhooks: form.Webhooks,
369-
Avatar: form.Avatar,
370-
IssueLabels: form.Labels,
362+
Name: form.Name,
363+
DefaultBranch: form.DefaultBranch,
364+
Description: form.Description,
365+
Private: form.Private,
366+
GitContent: form.GitContent,
367+
Topics: form.Topics,
368+
GitHooks: form.GitHooks,
369+
Webhooks: form.Webhooks,
370+
Avatar: form.Avatar,
371+
IssueLabels: form.Labels,
371372
}
372373

373374
if !opts.IsValid() {

templates/swagger/v1_json.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15412,6 +15412,11 @@
1541215412
"type": "boolean",
1541315413
"x-go-name": "Avatar"
1541415414
},
15415+
"default_branch": {
15416+
"description": "Default branch of the new repository",
15417+
"type": "string",
15418+
"x-go-name": "DefaultBranch"
15419+
},
1541515420
"description": {
1541615421
"description": "Description of the repository to create",
1541715422
"type": "string",

0 commit comments

Comments
 (0)