Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When generating repo from template, default_branch returns as blank string #19082

Closed
truesteps opened this issue Mar 14, 2022 · 8 comments · Fixed by #19136
Closed

When generating repo from template, default_branch returns as blank string #19082

truesteps opened this issue Mar 14, 2022 · 8 comments · Fixed by #19136
Labels
modifies/api This PR adds API routes or modifies them type/bug

Comments

@truesteps
Copy link

truesteps commented Mar 14, 2022

Gitea Version

1.16.3

Git Version

2.25.1

Operating System

Ubuntu 20.04.3 LTS (Focal Fossa)

How are you running Gitea?

I'm running gitea from the binary, through systemctl. I installed it from a tutorial I found online, recently updating it to the latest version, so I can use the generate repo endpoint.

Database

MySQL

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Description

Whenever I create a new repo from a template repo, I get back the repository detail as the request response, but the default_branch property is returned as an empty string. I think It should be the default branch, since when I fetch the detail of it in the next request, it's there, therefore I concluded this is a bug.

Allow me to send a gist with the entire response from the API https://gist.github.com/truesteps/43b4b13ac3619c92cbdc70c5622c6e02

Screenshots

Screenshot 2022-03-14 at 16 08 41

@lunny lunny added type/bug modifies/api This PR adds API routes or modifies them labels Mar 14, 2022
@abheekda1
Copy link
Contributor

ctx.JSON(http.StatusCreated, convert.ToRepo(repo, perm.AccessModeOwner))
not sure, but I think the issue stems from here where the created repo object does not have that value and is created by
func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templateRepo *repo_model.Repository, opts models.GenerateRepoOptions) (_ *repo_model.Repository, err error) {
generateRepo := &repo_model.Repository{
OwnerID: owner.ID,
Owner: owner,
OwnerName: owner.Name,
Name: opts.Name,
LowerName: strings.ToLower(opts.Name),
Description: opts.Description,
IsPrivate: opts.Private,
IsEmpty: !opts.GitContent || templateRepo.IsEmpty,
IsFsckEnabled: templateRepo.IsFsckEnabled,
TemplateID: templateRepo.ID,
TrustModel: templateRepo.TrustModel,
}

@truesteps
Copy link
Author

@ADawesomeguy I think it would make perfect sense to include the default_branch... Maybe even an option to define default_branch? 👼

@abheekda1
Copy link
Contributor

I just had the generated repo define its default branch using the template repo's default branch, so hopefully that should work @truesteps.

@truesteps
Copy link
Author

truesteps commented Mar 19, 2022

@ADawesomeguy I have an app where I use the api to generate new repos from templates, I allow the user to select a default branch of the generated repo, because it defaults to template default branch, I need to create new branch, change it to default, remove master basically :). It's a workable workaround It just feels like too many extra steps where it could fail for a basic operation.

Thanks for the tip tho!

@abheekda1
Copy link
Contributor

@truesteps wait sorry could you explain that again? I'm a bit confused as to what you want but I'd be happy to give implementing the ideal situation a shot even though I'm a bit lacking in experience.

@truesteps
Copy link
Author

truesteps commented Mar 19, 2022

Basically I would love to be able to pass a default_branch argument to the generate api, so the generated repo has a specific default branch, if left empty, defaults to default branch in template as the current behaviour dictates.

@ADawesomeguy

@abheekda1
Copy link
Contributor

Awesome, I'll see if I can add that to my PR.

@truesteps
Copy link
Author

@ADawesomeguy thanks dude :) 👍

zeripath added a commit that referenced this issue Mar 27, 2022
)

* Set the default branch for repositories generated from templates
* Allows default branch to be set through the API for repos generated from templates
* Update swagger API template
* Only set default branch to the one from the template if not specified
* Use specified default branch if it exists while generating git commits

Fix #19082 

Co-authored-by: John Olheiser <john.olheiser@gmail.com>
Co-authored-by: zeripath <art27@cantab.net>
Chianina pushed a commit to Chianina/gitea that referenced this issue Mar 28, 2022
…gitea#19136)

* Set the default branch for repositories generated from templates
* Allows default branch to be set through the API for repos generated from templates
* Update swagger API template
* Only set default branch to the one from the template if not specified
* Use specified default branch if it exists while generating git commits

Fix go-gitea#19082 

Co-authored-by: John Olheiser <john.olheiser@gmail.com>
Co-authored-by: zeripath <art27@cantab.net>
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
modifies/api This PR adds API routes or modifies them type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants