|
|
@ -4,17 +4,20 @@ |
|
|
|
package integration |
|
|
|
package integration |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"fmt" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"net/url" |
|
|
|
"net/url" |
|
|
|
"testing" |
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
|
|
|
|
auth_model "code.gitea.io/gitea/models/auth" |
|
|
|
"code.gitea.io/gitea/models/db" |
|
|
|
"code.gitea.io/gitea/models/db" |
|
|
|
git_model "code.gitea.io/gitea/models/git" |
|
|
|
git_model "code.gitea.io/gitea/models/git" |
|
|
|
repo_model "code.gitea.io/gitea/models/repo" |
|
|
|
repo_model "code.gitea.io/gitea/models/repo" |
|
|
|
"code.gitea.io/gitea/models/unittest" |
|
|
|
"code.gitea.io/gitea/models/unittest" |
|
|
|
user_model "code.gitea.io/gitea/models/user" |
|
|
|
user_model "code.gitea.io/gitea/models/user" |
|
|
|
"code.gitea.io/gitea/modules/git" |
|
|
|
"code.gitea.io/gitea/modules/git" |
|
|
|
|
|
|
|
api "code.gitea.io/gitea/modules/structs" |
|
|
|
"code.gitea.io/gitea/services/release" |
|
|
|
"code.gitea.io/gitea/services/release" |
|
|
|
"code.gitea.io/gitea/tests" |
|
|
|
"code.gitea.io/gitea/tests" |
|
|
|
|
|
|
|
|
|
|
@ -117,3 +120,47 @@ func TestCreateNewTagProtected(t *testing.T) { |
|
|
|
assert.NoError(t, err) |
|
|
|
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") |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|