mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-07 18:49:29 +02:00
Merge branch 'main' of https://github.com/go-gitea/gitea into workflow-webhook-api
This commit is contained in:
commit
8acd36b649
116 files changed
+1177
-726
No files matched your search
@@ -7,10 +7,12 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
auth_model "code.gitea.io/gitea/models/auth"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
@@ -149,6 +151,27 @@ jobs:
|
||||
)
|
||||
}
|
||||
|
||||
runID, _ := strconv.ParseInt(task.Context.GetFields()["run_id"].GetStringValue(), 10, 64)
|
||||
|
||||
jobs, err := actions_model.GetRunJobsByRunID(t.Context(), runID)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, jobs, 1)
|
||||
jobID := jobs[0].ID
|
||||
|
||||
// download task logs from API and check content
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/actions/jobs/%d/logs", user2.Name, repo.Name, jobID)).
|
||||
AddTokenAuth(token)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
logTextLines = strings.Split(strings.TrimSpace(resp.Body.String()), "\n")
|
||||
assert.Len(t, logTextLines, len(tc.outcome.logRows))
|
||||
for idx, lr := range tc.outcome.logRows {
|
||||
assert.Equal(
|
||||
t,
|
||||
fmt.Sprintf("%s %s", lr.Time.AsTime().Format("2006-01-02T15:04:05.0000000Z07:00"), lr.Content),
|
||||
logTextLines[idx],
|
||||
)
|
||||
}
|
||||
|
||||
resetFunc()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"testing"
|
||||
@@ -35,12 +34,12 @@ func withKeyFile(t *testing.T, keyname string, callback func(string)) {
|
||||
err = ssh.GenKeyPair(keyFile)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = os.WriteFile(path.Join(tmpDir, "ssh"), []byte("#!/bin/bash\n"+
|
||||
err = os.WriteFile(filepath.Join(tmpDir, "ssh"), []byte("#!/bin/bash\n"+
|
||||
"ssh -o \"UserKnownHostsFile=/dev/null\" -o \"StrictHostKeyChecking=no\" -o \"IdentitiesOnly=yes\" -i \""+keyFile+"\" \"$@\""), 0o700)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Setup ssh wrapper
|
||||
t.Setenv("GIT_SSH", path.Join(tmpDir, "ssh"))
|
||||
t.Setenv("GIT_SSH", filepath.Join(tmpDir, "ssh"))
|
||||
t.Setenv("GIT_SSH_COMMAND",
|
||||
"ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i \""+keyFile+"\"")
|
||||
t.Setenv("GIT_SSH_VARIANT", "ssh")
|
||||
|
||||
@@ -38,7 +38,7 @@ var currentEngine *xorm.Engine
|
||||
func initMigrationTest(t *testing.T) func() {
|
||||
testlogger.Init()
|
||||
giteaRoot := test.SetupGiteaRoot()
|
||||
setting.AppPath = path.Join(giteaRoot, "gitea")
|
||||
setting.AppPath = filepath.Join(giteaRoot, "gitea")
|
||||
if _, err := os.Stat(setting.AppPath); err != nil {
|
||||
testlogger.Fatalf(fmt.Sprintf("Could not find gitea binary at %s\n", setting.AppPath))
|
||||
}
|
||||
@@ -47,7 +47,7 @@ func initMigrationTest(t *testing.T) func() {
|
||||
if giteaConf == "" {
|
||||
testlogger.Fatalf("Environment variable $GITEA_CONF not set\n")
|
||||
} else if !path.IsAbs(giteaConf) {
|
||||
setting.CustomConf = path.Join(giteaRoot, giteaConf)
|
||||
setting.CustomConf = filepath.Join(giteaRoot, giteaConf)
|
||||
} else {
|
||||
setting.CustomConf = giteaConf
|
||||
}
|
||||
@@ -55,7 +55,7 @@ func initMigrationTest(t *testing.T) func() {
|
||||
unittest.InitSettings()
|
||||
|
||||
assert.NotEmpty(t, setting.RepoRootPath)
|
||||
assert.NoError(t, unittest.SyncDirs(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath))
|
||||
assert.NoError(t, unittest.SyncDirs(filepath.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath))
|
||||
assert.NoError(t, git.InitFull(t.Context()))
|
||||
setting.LoadDBSetting()
|
||||
setting.InitLoggersForTest()
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
@@ -19,11 +21,13 @@ import (
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestMirrorPull(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
ctx := t.Context()
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
repoPath := repo_model.RepoPath(user.Name, repo.Name)
|
||||
@@ -35,10 +39,10 @@ func TestMirrorPull(t *testing.T) {
|
||||
Mirror: true,
|
||||
CloneAddr: repoPath,
|
||||
Wiki: true,
|
||||
Releases: false,
|
||||
Releases: true,
|
||||
}
|
||||
|
||||
mirrorRepo, err := repo_service.CreateRepositoryDirectly(db.DefaultContext, user, user, repo_service.CreateRepoOptions{
|
||||
mirrorRepo, err := repo_service.CreateRepositoryDirectly(ctx, user, user, repo_service.CreateRepoOptions{
|
||||
Name: opts.RepoName,
|
||||
Description: opts.Description,
|
||||
IsPrivate: opts.Private,
|
||||
@@ -48,11 +52,15 @@ func TestMirrorPull(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, mirrorRepo.IsMirror, "expected pull-mirror repo to be marked as a mirror immediately after its creation")
|
||||
|
||||
ctx := t.Context()
|
||||
|
||||
mirror, err := repo_service.MigrateRepositoryGitData(ctx, user, mirrorRepo, opts, nil)
|
||||
mirrorRepo, err = repo_service.MigrateRepositoryGitData(ctx, user, mirrorRepo, opts, nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// these units should have been enabled
|
||||
mirrorRepo.Units = nil
|
||||
require.NoError(t, mirrorRepo.LoadUnits(ctx))
|
||||
assert.True(t, slices.ContainsFunc(mirrorRepo.Units, func(u *repo_model.RepoUnit) bool { return u.Type == unit.TypeReleases }))
|
||||
assert.True(t, slices.ContainsFunc(mirrorRepo.Units, func(u *repo_model.RepoUnit) bool { return u.Type == unit.TypeWiki }))
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo)
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
@@ -60,10 +68,11 @@ func TestMirrorPull(t *testing.T) {
|
||||
findOptions := repo_model.FindReleasesOptions{
|
||||
IncludeDrafts: true,
|
||||
IncludeTags: true,
|
||||
RepoID: mirror.ID,
|
||||
RepoID: mirrorRepo.ID,
|
||||
}
|
||||
initCount, err := db.Count[repo_model.Release](db.DefaultContext, findOptions)
|
||||
assert.NoError(t, err)
|
||||
assert.Zero(t, initCount) // no sync yet, so even though there is a tag in source repo, the mirror's release table is still empty
|
||||
|
||||
assert.NoError(t, release_service.CreateRelease(gitRepo, &repo_model.Release{
|
||||
RepoID: repo.ID,
|
||||
@@ -79,12 +88,15 @@ func TestMirrorPull(t *testing.T) {
|
||||
IsTag: true,
|
||||
}, nil, ""))
|
||||
|
||||
_, err = repo_model.GetMirrorByRepoID(ctx, mirror.ID)
|
||||
_, err = repo_model.GetMirrorByRepoID(ctx, mirrorRepo.ID)
|
||||
assert.NoError(t, err)
|
||||
|
||||
ok := mirror_service.SyncPullMirror(ctx, mirror.ID)
|
||||
ok := mirror_service.SyncPullMirror(ctx, mirrorRepo.ID)
|
||||
assert.True(t, ok)
|
||||
|
||||
// actually there is a tag in the source repo, so after "sync", that tag will also come into the mirror
|
||||
initCount++
|
||||
|
||||
count, err := db.Count[repo_model.Release](db.DefaultContext, findOptions)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, initCount+1, count)
|
||||
@@ -93,7 +105,7 @@ func TestMirrorPull(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, release_service.DeleteReleaseByID(ctx, repo, release, user, true))
|
||||
|
||||
ok = mirror_service.SyncPullMirror(ctx, mirror.ID)
|
||||
ok = mirror_service.SyncPullMirror(ctx, mirrorRepo.ID)
|
||||
assert.True(t, ok)
|
||||
|
||||
count, err = db.Count[repo_model.Release](db.DefaultContext, findOptions)
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
oauth2_provider "code.gitea.io/gitea/services/oauth2_provider"
|
||||
"code.gitea.io/gitea/services/oauth2_provider"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
@@ -24,23 +24,38 @@ import (
|
||||
func TestPullCompare(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
session := loginUser(t, "user2")
|
||||
req := NewRequest(t, "GET", "/user2/repo1/pulls")
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
link, exists := htmlDoc.doc.Find(".new-pr-button").Attr("href")
|
||||
assert.True(t, exists, "The template has changed")
|
||||
t.Run("PullsNewRedirect", func(t *testing.T) {
|
||||
req := NewRequest(t, "GET", "/user2/repo1/pulls/new/foo")
|
||||
resp := MakeRequest(t, req, http.StatusSeeOther)
|
||||
redirect := test.RedirectURL(resp)
|
||||
assert.Equal(t, "/user2/repo1/compare/master...foo?expand=1", redirect)
|
||||
|
||||
req = NewRequest(t, "GET", link)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
assert.EqualValues(t, http.StatusOK, resp.Code)
|
||||
req = NewRequest(t, "GET", "/user13/repo11/pulls/new/foo")
|
||||
resp = MakeRequest(t, req, http.StatusSeeOther)
|
||||
redirect = test.RedirectURL(resp)
|
||||
assert.Equal(t, "/user12/repo10/compare/master...user13:foo?expand=1", redirect)
|
||||
})
|
||||
|
||||
// test the edit button in the PR diff view
|
||||
req = NewRequest(t, "GET", "/user2/repo1/pulls/3/files")
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
doc := NewHTMLParser(t, resp.Body)
|
||||
editButtonCount := doc.doc.Find(".diff-file-header-actions a[href*='/_edit/']").Length()
|
||||
assert.Positive(t, editButtonCount, "Expected to find a button to edit a file in the PR diff view but there were none")
|
||||
t.Run("ButtonsExist", func(t *testing.T) {
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
// test the "New PR" button
|
||||
req := NewRequest(t, "GET", "/user2/repo1/pulls")
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
link, exists := htmlDoc.doc.Find(".new-pr-button").Attr("href")
|
||||
assert.True(t, exists, "The template has changed")
|
||||
req = NewRequest(t, "GET", link)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
assert.EqualValues(t, http.StatusOK, resp.Code)
|
||||
|
||||
// test the edit button in the PR diff view
|
||||
req = NewRequest(t, "GET", "/user2/repo1/pulls/3/files")
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
doc := NewHTMLParser(t, resp.Body)
|
||||
editButtonCount := doc.doc.Find(".diff-file-header-actions a[href*='/_edit/']").Length()
|
||||
assert.Positive(t, editButtonCount, "Expected to find a button to edit a file in the PR diff view but there were none")
|
||||
})
|
||||
|
||||
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
@@ -54,8 +69,8 @@ func TestPullCompare(t *testing.T) {
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "repo1"})
|
||||
issueIndex := unittest.AssertExistsAndLoadBean(t, &issues_model.IssueIndex{GroupID: repo1.ID}, unittest.OrderBy("group_id ASC"))
|
||||
prFilesURL := fmt.Sprintf("/user2/repo1/pulls/%d/files", issueIndex.MaxIndex)
|
||||
req = NewRequest(t, "GET", prFilesURL)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
req := NewRequest(t, "GET", prFilesURL)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
doc := NewHTMLParser(t, resp.Body)
|
||||
editButtonCount := doc.doc.Find(".diff-file-header-actions a[href*='/_edit/']").Length()
|
||||
assert.Positive(t, editButtonCount, "Expected to find a button to edit a file in the PR diff view but there were none")
|
||||
|
||||
@@ -31,16 +31,16 @@ func testRepoGenerate(t *testing.T, session *TestSession, templateID, templateOw
|
||||
|
||||
// Step2: click the "Use this template" button
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
link, exists := htmlDoc.doc.Find("a.ui.button[href^=\"/repo/create\"]").Attr("href")
|
||||
link, exists := htmlDoc.doc.Find(`a.ui.button[href^="/repo/create"]`).Attr("href")
|
||||
assert.True(t, exists, "The template has changed")
|
||||
req = NewRequest(t, "GET", link)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
// Step3: fill the form of the create
|
||||
// Step3: fill the form on the "create" page
|
||||
htmlDoc = NewHTMLParser(t, resp.Body)
|
||||
link, exists = htmlDoc.doc.Find("form.ui.form[action^=\"/repo/create\"]").Attr("action")
|
||||
link, exists = htmlDoc.doc.Find(`form.ui.form[action^="/repo/create"]`).Attr("action")
|
||||
assert.True(t, exists, "The template has changed")
|
||||
_, exists = htmlDoc.doc.Find(fmt.Sprintf(".owner.dropdown .item[data-value=\"%d\"]", generateOwner.ID)).Attr("data-value")
|
||||
_, exists = htmlDoc.doc.Find(fmt.Sprintf(`#repo_owner_dropdown .item[data-value="%d"]`, generateOwner.ID)).Attr("data-value")
|
||||
assert.True(t, exists, "Generate owner '%s' is not present in select box", generateOwnerName)
|
||||
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
||||
"_csrf": htmlDoc.GetCSRF(),
|
||||
|
||||
Reference in new issue
Block a user