-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Adopt repositories #12920
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
Merged
Merged
Adopt repositories #12920
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
0cc1bda
Don't automatically delete repository files if they are present
zeripath 2fd0292
Update swagger
zeripath bd1d182
Fix tests and migrate overwrite
zeripath 5075257
as per @lunny
zeripath e8fa2e6
Merge remote-tracking branch 'origin/master' into adopt-repositories
zeripath b06c510
Use setting.Repository.DefaultBranch for the default branch
zeripath d885a69
Always set setting.Repository.DefaultBranch
zeripath 45a6873
Merge remote-tracking branch 'origin/master' into adopt-repositories
zeripath 608031d
update swagger
zeripath ca482b7
update templates
zeripath 4c143ff
Merge branch 'master' into adopt-repositories
zeripath ee66a29
ensure repo closed
zeripath d74f3c9
Merge remote-tracking branch 'origin/master' into adopt-repositories
zeripath c18ba9b
Rewrite of adoption as per @6543 and @lunny
zeripath f535fea
Merge remote-tracking branch 'origin/master' into adopt-repositories-2
zeripath 0dc0824
Apply suggestions from code review
zeripath d4a7c0c
update swagger
zeripath 08a333f
missing not
zeripath d0d7ff8
add modals and flash reporting
zeripath 81bf964
Merge remote-tracking branch 'origin/master' into adopt-repositories-2
zeripath 1911965
Make the unadopted page searchable
zeripath b96ba62
Add API
zeripath 971585b
Fix swagger
zeripath 89e59ce
fix swagger
zeripath 56b6e16
Merge remote-tracking branch 'origin/master' into adopt-repositories-2
zeripath 8c7f896
Handle empty and non-master branched repositories
zeripath 4a65d77
placate lint
zeripath 05030b1
remove commented out code
zeripath d1a4365
Merge branch 'master' into adopt-repositories-2
techknowlogick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // Copyright 2020 The Gitea Authors. All rights reserved. | ||
| // Use of this source code is governed by a MIT-style | ||
| // license that can be found in the LICENSE file. | ||
|
|
||
| package repository | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "code.gitea.io/gitea/models" | ||
| "code.gitea.io/gitea/modules/git" | ||
| "code.gitea.io/gitea/modules/log" | ||
| "code.gitea.io/gitea/modules/setting" | ||
| "code.gitea.io/gitea/modules/util" | ||
| "github.com/unknwon/com" | ||
| ) | ||
|
|
||
| // AdoptRepository adopts a repository for the user/organization. | ||
| func AdoptRepository(doer, u *models.User, opts models.CreateRepoOptions) (*models.Repository, error) { | ||
| if !doer.IsAdmin && !u.CanCreateRepo() { | ||
| return nil, models.ErrReachLimitOfRepo{ | ||
| Limit: u.MaxRepoCreation, | ||
| } | ||
| } | ||
|
|
||
| if len(opts.DefaultBranch) == 0 { | ||
| opts.DefaultBranch = setting.Repository.DefaultBranch | ||
| } | ||
|
|
||
| repo := &models.Repository{ | ||
| OwnerID: u.ID, | ||
| Owner: u, | ||
| OwnerName: u.Name, | ||
| Name: opts.Name, | ||
| LowerName: strings.ToLower(opts.Name), | ||
| Description: opts.Description, | ||
| OriginalURL: opts.OriginalURL, | ||
| OriginalServiceType: opts.GitServiceType, | ||
| IsPrivate: opts.IsPrivate, | ||
| IsFsckEnabled: !opts.IsMirror, | ||
| CloseIssuesViaCommitInAnyBranch: setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch, | ||
| Status: opts.Status, | ||
| IsEmpty: !opts.AutoInit, | ||
| } | ||
|
|
||
| if err := models.WithTx(func(ctx models.DBContext) error { | ||
| repoPath := models.RepoPath(u.Name, repo.Name) | ||
| if !com.IsExist(repoPath) { | ||
| return models.ErrRepoNotExist{ | ||
| OwnerName: u.Name, | ||
| Name: repo.Name, | ||
| } | ||
| } | ||
|
|
||
| if err := models.CreateRepository(ctx, doer, u, repo, true); err != nil { | ||
| return err | ||
| } | ||
| if err := adoptRepository(ctx, repoPath, doer, repo, opts); err != nil { | ||
| return fmt.Errorf("createDelegateHooks: %v", err) | ||
| } | ||
|
|
||
| // Initialize Issue Labels if selected | ||
| if len(opts.IssueLabels) > 0 { | ||
| if err := models.InitializeLabels(ctx, repo.ID, opts.IssueLabels, false); err != nil { | ||
| return fmt.Errorf("InitializeLabels: %v", err) | ||
| } | ||
| } | ||
|
|
||
| if stdout, err := git.NewCommand("update-server-info"). | ||
| SetDescription(fmt.Sprintf("CreateRepository(git update-server-info): %s", repoPath)). | ||
| RunInDir(repoPath); err != nil { | ||
| log.Error("CreateRepository(git update-server-info) in %v: Stdout: %s\nError: %v", repo, stdout, err) | ||
| return fmt.Errorf("CreateRepository(git update-server-info): %v", err) | ||
| } | ||
| return nil | ||
| }); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return repo, nil | ||
| } | ||
|
|
||
| // DeleteUnadoptedRepository deletes unadopted repository files from the filesystem | ||
| func DeleteUnadoptedRepository(doer, u *models.User, repoName string) error { | ||
| if err := models.IsUsableRepoName(repoName); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| repoPath := models.RepoPath(u.Name, repoName) | ||
| if !com.IsExist(repoPath) { | ||
| return models.ErrRepoNotExist{ | ||
| OwnerName: u.Name, | ||
| Name: repoName, | ||
| } | ||
| } | ||
|
|
||
| if exist, err := models.IsRepositoryExist(u, repoName); err != nil { | ||
| return err | ||
| } else if exist { | ||
| return models.ErrRepoAlreadyExist{ | ||
| Uname: u.Name, | ||
| Name: repoName, | ||
| } | ||
| } | ||
|
|
||
| return util.RemoveAll(repoPath) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.