-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Sync releases table with tags on push and for mirrors #2459
Conversation
31c1b9e
to
5de49c8
Compare
models/release.go
Outdated
|
||
// SyncReleasesWithTags synchronizes release table with repository tags | ||
func SyncReleasesWithTags(repo *Repository, gitRepo *git.Repository) error { | ||
checked := make([]string, 100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use a map[string]struct{}
instead? It will be more efficient to check if tags have been checked below with a map.
routers/api/v1/repo/release.go
Outdated
ctx.Error(500, "Commit", err) | ||
|
||
if !rel.IsTag { | ||
ctx.Status(409) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is typo than it was also previously as I kept previous behaviour, it was returning status 409 when release already existed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is not a typo:
gitea/routers/api/v1/repo/release.go
Line 97 in 93a1de4
ctx.Status(409) |
models/migrations/v39.go
Outdated
func releaseAddColumnIsTagAndSyncTags(x *xorm.Engine) error { | ||
if err := x.Sync2(new(ReleaseV39)); err != nil { | ||
return fmt.Errorf("Sync2: %v", err) | ||
} else if _, err = x.Cols("is_tag").Update(&ReleaseV39{IsTag: false}); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why update all are false
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default, probably not needed
models/migrations/v39.go
Outdated
if len(repos) == 0 { | ||
break | ||
} | ||
offset += 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
offset += len(repos)
|
||
if _, err = x.Id(rel.ID).Delete(new(Release)); err != nil { | ||
return fmt.Errorf("Delete: %v", err) | ||
if _, err = x.Id(rel.ID).Delete(new(Release)); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update after delete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forgot to remove update, good catch, thx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually it is just in diff looks like this, if you look at the full file code there is no update before delete, update is from other function :)
So, why do we need to do this? Tags and Releases are not the same thing, they should not be treated as the same thing... If we need this list it should be fetched from the GitRepo directly 🤔 |
@bkcsoft this is only way to efficiently implement release page paging and to have release page match github behavior. Releases are actually just extenended tags so can say they are quite the same |
@bkcsoft @lunny it's not about just migration from github it's about displaying tags that are not linked to releases in release page like github is doing: And it does not matter if repository is migrated or tags are created from git client. Not everyone wants or need to create releases for each tag but it is useful when creating tag to see kind of release list and only if needed create release with additional info and attachments. This is especially important for mirrored repositories and they can also be mirrored from github/gitlab etc |
And also this was the functionality gitea had before release page was rewritten to show only data from database (I'm not against it) |
@lafriks OK. I see. |
LGTM |
@lunny I thought that any non-repo migration/sync would be left to third-party tools? |
@bkcsoft but this PR is not related to it in any way but otherwise I agree 3rd-party sync/migration should be external tool |
models/release.go
Outdated
@@ -246,6 +248,9 @@ func (opts *FindReleasesOptions) toConds(repoID int64) builder.Cond { | |||
if !opts.IncludeDrafts { | |||
cond = cond.And(builder.Eq{"is_draft": false}) | |||
} | |||
if !opts.IncludeTags { | |||
cond = cond.And(builder.Eq{"is_release": false}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be "is_tag"
?
routers/api/v1/repo/release.go
Outdated
if err != nil { | ||
ctx.Error(500, "GetTag", err) | ||
if models.IsErrReleaseNotExist(err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused here. If we are creating a release, why do we expect there to already be a release with the name form.TagName
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because release table does now contains also tags that are not full releases with attachments etc and when creating release it is needed to update release table flag (is_tag to false) and adding additional release information to that row
@lafriks Mainly just thinking out loud 🙂 |
f2d2992
to
6e160c3
Compare
@ethantkoenig fixed and also refactored code to minimize chance of possible race conditions |
@lafriks and this one. |
Minimize posibility of race conditions
cd6235b
to
b2a9ea0
Compare
Codecov Report
@@ Coverage Diff @@
## master #2459 +/- ##
==========================================
- Coverage 27.21% 26.99% -0.23%
==========================================
Files 85 85
Lines 16955 17097 +142
==========================================
Hits 4615 4615
- Misses 11665 11807 +142
Partials 675 675
Continue to review full report at Codecov.
|
@lunny I think I found bug but have to still reproduce that, do not merge yet. Would be great if someone could test it on his dev environment |
models/release.go
Outdated
existingRelTags := make(map[string]struct{}) | ||
opts := FindReleasesOptions{IncludeDrafts: true, IncludeTags: true} | ||
page := 0 | ||
for { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: for page := 1; ; page++ {
@ethantkoenig fixed your suggestion |
@lafriks Found two issues.
But maybe there are more. |
@lafriks Ok, I have finished my examination. Last commit definitely fixes bugs regarding release creation. As |
Steps to reproduce:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind
LGTM |
Make L-G-T-M work |
I made a mistake. @lafriks |
* 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
* 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
Fixes #2154
Not fully tested but ready for review