The Wayback Machine - https://web.archive.org/web/20220806101607/https://github.com/go-gitea/gitea/pull/19136
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

Set the default branch for repositories generated from templates #19136

Merged
merged 15 commits into from Mar 27, 2022

Conversation

ADawesomeguy
Copy link
Contributor

@ADawesomeguy ADawesomeguy commented Mar 19, 2022

Should fix #19082

The generate repository function generates a repository from a template, but when used from the API, it does not seem to have any value returned for the default branch. Seeing as the API was simply returning the generated repository object converted to JSON using a function (which did indeed have the default branch filled out), it seemed likely that the default branch was just not being set for the generate repository. This was fixed simply enough (hopefully correctly) with this PR. Please let me know if I missed something, did something wrong, or anything else :)

@techknowlogick techknowlogick requested a review from jolheiser Mar 19, 2022
@ADawesomeguy
Copy link
Contributor Author

@ADawesomeguy ADawesomeguy commented Mar 19, 2022

Not sure if the most recent commit will work, if anyone has any suggestions please let me know how to best approach making this simple change functional.

@jolheiser
Copy link
Member

@jolheiser jolheiser commented Mar 19, 2022

Will review when I get to my machine, but the CI is failing because you need to make generate-swagger

@ADawesomeguy
Copy link
Contributor Author

@ADawesomeguy ADawesomeguy commented Mar 19, 2022

Yep, thanks :)

Oh wait I did it manually based on the diff in the Drone console, hopefully it works just fine 👀

Ok it didn't, I'm just gonna run the command now. I think it was some weird formatting stuff with Vim.

Copy link
Member

@jolheiser jolheiser left a comment

Firstly, this should also be added to the UI, as currently it only uses default branch.

Second, the current changes are only setting the default in the database, however they are not being passed along to any of the git commands when the repo is initialized.
The API response gives the input default branch, but the actual repository doesn't reflect it.

Particularly, if you follow

if err = repo_module.GenerateGitContent(ctx, templateRepo, generateRepo); err != nil {
you should run into spots that are currently using default branch that will need to change.

@ADawesomeguy
Copy link
Contributor Author

@ADawesomeguy ADawesomeguy commented Mar 19, 2022

repo.DefaultBranch = templateRepo.DefaultBranch

It seems this is where the default branch for the generated repo is being defined. A request missing the key for default_branch would just fill in the object with an empty string for DefaultBranch right? So would it make sense to check whether repo.DefaultBranch is an empty string and only define the default branch using the template repo if it is?

Something like:

if strings.TrimSpace(repo.DefaultBranch) == "" {
    repo.DefaultBranch = templateRepo.DefaultBranch
}

@ADawesomeguy ADawesomeguy requested a review from jolheiser Mar 19, 2022
@ADawesomeguy
Copy link
Contributor Author

@ADawesomeguy ADawesomeguy commented Mar 19, 2022

I think once the API is figured out the UI can be implemented as well.

@jolheiser
Copy link
Member

@jolheiser jolheiser commented Mar 20, 2022

Default branch is also used here

func initRepoCommit(ctx context.Context, tmpPath string, repo *repo_model.Repository, u *user_model.User, defaultBranch string) (err error) {

@ADawesomeguy
Copy link
Contributor Author

@ADawesomeguy ADawesomeguy commented Mar 20, 2022

@jolheiser think that should also be implemented in a similar way as of the latest commit.

@Gusted Gusted added this to the 1.17.0 milestone Mar 20, 2022
@ADawesomeguy
Copy link
Contributor Author

@ADawesomeguy ADawesomeguy commented Mar 23, 2022

Hey @jolheiser sorry to bother you but I think I got it now, would you mind taking a look?

@jolheiser
Copy link
Member

@jolheiser jolheiser commented Mar 23, 2022

It looks like this is working via API now.

@ADawesomeguy
Copy link
Contributor Author

@ADawesomeguy ADawesomeguy commented Mar 23, 2022

Is there anything left for me to do or is this PR mostly set?

Copy link
Member

@jolheiser jolheiser left a comment

I would like to see this available in the UI for parity, but I suppose that can be a separate PR since this one also fixes a bug.

@codecov-commenter
Copy link

@codecov-commenter codecov-commenter commented Mar 24, 2022

Codecov Report

Merging #19136 (ef47540) into main (49c5fc5) will increase coverage by 0.00%.
The diff coverage is 38.60%.

Current head ef47540 differs from pull request most recent head 6446cd3. Consider uploading reports for the commit 6446cd3 to get more accurate results

@@           Coverage Diff            @@
##             main   #19136    +/-   ##
========================================
  Coverage   46.55%   46.56%            
========================================
  Files         856      857     +1     
  Lines      123018   123341   +323     
========================================
+ Hits        57277    57428   +151     
- Misses      58814    58967   +153     
- Partials     6927     6946    +19     
Impacted Files Coverage Δ
cmd/admin.go 0.00% <0.00%> (ø)
cmd/hook.go 7.11% <0.00%> (ø)
cmd/serv.go 2.39% <0.00%> (ø)
cmd/web_acme.go 0.00% <0.00%> (ø)
models/asymkey/ssh_key_deploy.go 55.55% <ø> (+1.13%) ⬆️
models/helper_environment.go 100.00% <ø> (ø)
models/repo_generate.go 21.05% <ø> (ø)
modules/context/permission.go 25.39% <0.00%> (ø)
modules/doctor/checkOldArchives.go 22.85% <0.00%> (ø)
modules/doctor/fix16961.go 35.06% <0.00%> (ø)
... and 187 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5fe764b...6446cd3. Read the comment docs.

@ADawesomeguy
Copy link
Contributor Author

@ADawesomeguy ADawesomeguy commented Mar 27, 2022

Any clue why this is failing CI?

@zeripath
Copy link
Contributor

@zeripath zeripath commented Mar 27, 2022

Any clue why this is failing CI?

it's not your fault - it's this TestRepoIndexer. The test is inherently racey and things have now started to become super racey there. I've added #19225 which should resolve the issue.

@ADawesomeguy
Copy link
Contributor Author

@ADawesomeguy ADawesomeguy commented Mar 27, 2022

Alright, nice! Seems like it finally passed this time.

@zeripath zeripath merged commit f316582 into go-gitea:main Mar 27, 2022
2 checks passed
@ADawesomeguy ADawesomeguy deleted the repogen-default-branch branch Mar 27, 2022
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 <[email protected]>
Co-authored-by: zeripath <[email protected]>
Ta180m pushed a commit to Ta180m/gitea that referenced this issue Apr 22, 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 <[email protected]>
Co-authored-by: zeripath <[email protected]>
Ta180m pushed a commit to Ta180m/gitea that referenced this issue Apr 22, 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 <[email protected]>
Co-authored-by: zeripath <[email protected]>
@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.
Development

Successfully merging this pull request may close these issues.

7 participants