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

Fix broken releases when re-pushing tags (#32435) #32449

Merged
merged 3 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
19 changes: 12 additions & 7 deletions services/repository/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,10 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
}

releases, err := db.Find[repo_model.Release](ctx, repo_model.FindReleasesOptions{
RepoID: repo.ID,
TagNames: tags,
IncludeTags: true,
RepoID: repo.ID,
TagNames: tags,
IncludeDrafts: true,
IncludeTags: true,
})
if err != nil {
return fmt.Errorf("db.Find[repo_model.Release]: %w", err)
Expand Down Expand Up @@ -409,13 +410,17 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo

newReleases = append(newReleases, rel)
} else {
rel.Title = parts[0]
rel.Note = note
rel.Sha1 = commit.ID.String()
rel.CreatedUnix = timeutil.TimeStamp(createdAt.Unix())
rel.NumCommits = commitsCount
if rel.IsTag && author != nil {
rel.PublisherID = author.ID
if rel.IsTag {
rel.Title = parts[0]
rel.Note = note
if author != nil {
rel.PublisherID = author.ID
}
} else {
rel.IsDraft = false
}
if err = repo_model.UpdateRelease(ctx, rel); err != nil {
return fmt.Errorf("Update: %w", err)
Expand Down
47 changes: 47 additions & 0 deletions tests/integration/repo_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
package integration

import (
"fmt"
"net/http"
"net/url"
"testing"

"code.gitea.io/gitea/models"
auth_model "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/services/release"
"code.gitea.io/gitea/tests"

Expand Down Expand Up @@ -117,3 +120,47 @@
assert.NoError(t, err)
}
}

func TestRepushTag(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
session := loginUser(t, owner.LowerName)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)

httpContext := NewAPITestContext(t, owner.Name, repo.Name)

dstPath := t.TempDir()

u.Path = httpContext.GitPath()
u.User = url.UserPassword(owner.Name, userPassword)

doGitClone(dstPath, u)(t)

// create and push a tag
_, _, err := git.NewCommand(git.DefaultContext, "tag", "v2.0").RunStdString(&git.RunOpts{Dir: dstPath})
assert.NoError(t, err)
_, _, err = git.NewCommand(git.DefaultContext, "push", "origin", "--tags", "v2.0").RunStdString(&git.RunOpts{Dir: dstPath})
assert.NoError(t, err)
// create a release for the tag
createdRelease := createNewReleaseUsingAPI(t, token, owner, repo, "v2.0", "", "Release of v2.0", "desc")

Check failure on line 146 in tests/integration/repo_tag_test.go

View workflow job for this annotation

GitHub Actions / test-pgsql

not enough arguments in call to createNewReleaseUsingAPI

Check failure on line 146 in tests/integration/repo_tag_test.go

View workflow job for this annotation

GitHub Actions / test-sqlite

not enough arguments in call to createNewReleaseUsingAPI

Check failure on line 146 in tests/integration/repo_tag_test.go

View workflow job for this annotation

GitHub Actions / test-mssql

not enough arguments in call to createNewReleaseUsingAPI

Check failure on line 146 in tests/integration/repo_tag_test.go

View workflow job for this annotation

GitHub Actions / test-mysql

not enough arguments in call to createNewReleaseUsingAPI

Check failure on line 146 in tests/integration/repo_tag_test.go

View workflow job for this annotation

GitHub Actions / lint-backend

not enough arguments in call to createNewReleaseUsingAPI

Check failure on line 146 in tests/integration/repo_tag_test.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

not enough arguments in call to createNewReleaseUsingAPI

Check failure on line 146 in tests/integration/repo_tag_test.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

not enough arguments in call to createNewReleaseUsingAPI
lunny marked this conversation as resolved.
Show resolved Hide resolved
assert.False(t, createdRelease.IsDraft)
// delete the tag
_, _, err = git.NewCommand(git.DefaultContext, "push", "origin", "--delete", "v2.0").RunStdString(&git.RunOpts{Dir: dstPath})
assert.NoError(t, err)
// query the release by API and it should be a draft
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/releases/tags/%s", owner.Name, repo.Name, "v2.0"))
resp := MakeRequest(t, req, http.StatusOK)
var respRelease *api.Release
DecodeJSON(t, resp, &respRelease)
assert.True(t, respRelease.IsDraft)
// re-push the tag
_, _, err = git.NewCommand(git.DefaultContext, "push", "origin", "--tags", "v2.0").RunStdString(&git.RunOpts{Dir: dstPath})
assert.NoError(t, err)
// query the release by API and it should not be a draft
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/releases/tags/%s", owner.Name, repo.Name, "v2.0"))
resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &respRelease)
assert.False(t, respRelease.IsDraft)
})
}
Loading