Skip to content

Commit 823144c

Browse files
committed
Allows default branch to be set through the API for repos generated from templates
1 parent f5c855d commit 823144c

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
249249
Name: opts.Name,
250250
LowerName: strings.ToLower(opts.Name),
251251
Description: opts.Description,
252-
DefaultBranch: templateRepo.DefaultBranch,
252+
DefaultBranch: opts.DefaultBranch,
253253
IsPrivate: opts.Private,
254254
IsEmpty: !opts.GitContent || templateRepo.IsEmpty,
255255
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() {

0 commit comments

Comments
 (0)