forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync releases table with tags on push and for mirrors (go-gitea#2459)
* Sync releases table with tags on push and for mirrors * Code style fixes * Fix api to return only releases * Optimize release creation and update Minimize posibility of race conditions * Fix release lower tag name updating * handle tag reference update by addionally comparing commit id
- Loading branch information
Showing
10 changed files
with
366 additions
and
118 deletions.
There are no files selected for viewing
This file contains 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 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,57 @@ | ||
// Copyright 2017 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 migrations | ||
|
||
import ( | ||
"fmt" | ||
|
||
"code.gitea.io/git" | ||
"code.gitea.io/gitea/models" | ||
"code.gitea.io/gitea/modules/log" | ||
|
||
"github.com/go-xorm/xorm" | ||
) | ||
|
||
// ReleaseV39 describes the added field for Release | ||
type ReleaseV39 struct { | ||
IsTag bool `xorm:"NOT NULL DEFAULT false"` | ||
} | ||
|
||
// TableName will be invoked by XORM to customrize the table name | ||
func (*ReleaseV39) TableName() string { | ||
return "release" | ||
} | ||
|
||
func releaseAddColumnIsTagAndSyncTags(x *xorm.Engine) error { | ||
if err := x.Sync2(new(ReleaseV39)); err != nil { | ||
return fmt.Errorf("Sync2: %v", err) | ||
} | ||
|
||
// For the sake of SQLite3, we can't use x.Iterate here. | ||
offset := 0 | ||
pageSize := 20 | ||
for { | ||
repos := make([]*models.Repository, 0, pageSize) | ||
if err := x.Table("repository").Asc("id").Limit(pageSize, offset).Find(&repos); err != nil { | ||
return fmt.Errorf("select repos [offset: %d]: %v", offset, err) | ||
} | ||
for _, repo := range repos { | ||
gitRepo, err := git.OpenRepository(repo.RepoPath()) | ||
if err != nil { | ||
log.Warn("OpenRepository: %v", err) | ||
continue | ||
} | ||
|
||
if err = models.SyncReleasesWithTags(repo, gitRepo); err != nil { | ||
log.Warn("SyncReleasesWithTags: %v", err) | ||
} | ||
} | ||
if len(repos) < pageSize { | ||
break | ||
} | ||
offset += pageSize | ||
} | ||
return nil | ||
} |
This file contains 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 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 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 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 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.