Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2c02c2e
Cleanup resources when create/adopt/generate repository failed
lunny May 21, 2024
d66b905
Add transaction for CreateRepoByExample
lunny May 27, 2024
0bd9aa0
Merge branch 'main' into lunny/cleanup_failure_creation_of_repo
lunny Sep 23, 2024
f0917c4
Merge branch 'main' into lunny/cleanup_failure_creation_of_repo
lunny Mar 14, 2025
0a9a6c7
Merge branch 'main' into lunny/cleanup_failure_creation_of_repo
lunny Mar 26, 2025
60c85e7
Some improvements
lunny Mar 26, 2025
ec58717
Fix bug
lunny Mar 26, 2025
1d13cc3
Add tests
lunny Mar 27, 2025
96069bf
Merge branch 'main' into lunny/cleanup_failure_creation_of_repo
lunny Mar 27, 2025
eb8884c
Fix creating repository
lunny Mar 27, 2025
f6b6850
Merge branch 'main' into lunny/cleanup_failure_creation_of_repo
lunny Mar 27, 2025
dfc1d46
Merge branch 'main' into lunny/cleanup_failure_creation_of_repo
lunny Mar 28, 2025
a494a69
merge some functions
lunny Mar 30, 2025
34c8445
Merge branch 'main' into lunny/cleanup_failure_creation_of_repo
lunny Mar 30, 2025
9b0d0dd
Merge branch 'lunny/cleanup_failure_creation_of_repo' of github.com:l…
lunny Mar 30, 2025
0a54603
Fix bug
lunny Mar 30, 2025
2322172
some improvements
lunny Mar 30, 2025
0142df4
Refactor to make test easier
lunny Apr 8, 2025
b01bab6
Merge branch 'main' into lunny/cleanup_failure_creation_of_repo
lunny Apr 8, 2025
b61f417
Remove duplicated checks
lunny Apr 8, 2025
8d85006
Fix test
lunny Apr 8, 2025
5feb0dd
Update comments
lunny Apr 8, 2025
5a041cc
update test
lunny Apr 8, 2025
2053bc2
Merge branch 'main' into lunny/cleanup_failure_creation_of_repo
lunny Apr 8, 2025
131b458
Merge branch 'main' into lunny/cleanup_failure_creation_of_repo
lunny Apr 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
some improvements
  • Loading branch information
lunny committed Mar 30, 2025
commit 232217253dfbba2f7a3faa7293b514f83c79f547
7 changes: 4 additions & 3 deletions services/repository/adopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
"github.com/gobwas/glob"
)

func deleteFailedAdoptRepository(ctx context.Context, repoID int64) error {
return db.WithTx(ctx, func(ctx context.Context) error {
func deleteFailedAdoptRepository(repoID int64) error {
return db.WithTx(db.DefaultContext, func(ctx context.Context) error {
if err := deleteDBRepository(ctx, repoID); err != nil {
return fmt.Errorf("deleteDBRepository: %w", err)
}
Expand Down Expand Up @@ -75,7 +75,8 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
// WARNING: Don't override all later err with local variables
defer func() {
if err != nil {
if errDel := deleteFailedAdoptRepository(ctx, repo.ID); errDel != nil {
// we can not use the ctx because it maybe canceled or timeout
if errDel := deleteFailedAdoptRepository(repo.ID); errDel != nil {
log.Error("Failed to delete repository %s that could not be adopted: %v", repo.FullName(), errDel)
}
}
Expand Down
2 changes: 1 addition & 1 deletion services/repository/adopt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestAdoptRepository(t *testing.T) {
assert.Equal(t, "sha1", repoTestAdopt.ObjectFormatName)

// just delete the adopted repo's db records
err = deleteFailedAdoptRepository(db.DefaultContext, adoptedRepo.ID)
err = deleteFailedAdoptRepository(adoptedRepo.ID)
assert.NoError(t, err)

unittest.AssertNotExistsBean(t, &repo_model.Repository{OwnerName: "user2", Name: "test-adopt"})
Expand Down
1 change: 1 addition & 0 deletions services/repository/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
// WARNING: Don't override all later err with local variables
defer func() {
if err != nil {
// we can not use the ctx because it maybe canceled or timeout
cleanupRepository(doer, repo.ID)
}
}()
Expand Down
1 change: 1 addition & 0 deletions services/repository/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
// WARNING: Don't override all later err with local variables
defer func() {
if err != nil {
// we can not use the ctx because it maybe canceled or timeout
cleanupRepository(doer, repo.ID)
}
}()
Expand Down
1 change: 1 addition & 0 deletions services/repository/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
// last - clean up the repository if something goes wrong
defer func() {
if err != nil {
// we can not use the ctx because it maybe canceled or timeout
cleanupRepository(doer, generateRepo.ID)
}
}()
Expand Down