From 7ea4bfc56172faf588142ee5637f35c0344f7534 Mon Sep 17 00:00:00 2001 From: Ethan Koenig Date: Sat, 28 Apr 2018 23:21:33 -0700 Subject: API endpoint for testing webhook (#3550) * API endpoint for testing webhook * Empty commit to rerun CI --- modules/test/context_tests.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'modules/test/context_tests.go') diff --git a/modules/test/context_tests.go b/modules/test/context_tests.go index bd5ea3fd38..b2b96fff9d 100644 --- a/modules/test/context_tests.go +++ b/modules/test/context_tests.go @@ -13,10 +13,11 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" + "net/http/httptest" + "github.com/go-macaron/session" "github.com/stretchr/testify/assert" "gopkg.in/macaron.v1" - "net/http/httptest" ) // MockContext mock context for unit tests @@ -48,6 +49,16 @@ func LoadRepo(t *testing.T, ctx *context.Context, repoID int64) { ctx.Repo.RepoLink = ctx.Repo.Repository.Link() } +// LoadRepoCommit loads a repo's commit into a test context. +func LoadRepoCommit(t *testing.T, ctx *context.Context) { + gitRepo, err := git.OpenRepository(ctx.Repo.Repository.RepoPath()) + assert.NoError(t, err) + branch, err := gitRepo.GetHEADBranch() + assert.NoError(t, err) + ctx.Repo.Commit, err = gitRepo.GetBranchCommit(branch.Name) + assert.NoError(t, err) +} + // LoadUser load a user into a test context. func LoadUser(t *testing.T, ctx *context.Context, userID int64) { ctx.User = models.AssertExistsAndLoadBean(t, &models.User{ID: userID}).(*models.User) -- cgit v1.2.3