func TestWebhook(ctx *context.Context) { // Grab latest commit or fake one if it's empty repository. commit := ctx.Repo.Commit if commit == nil { ghost := models.NewGhostUser() commit = &git.Commit{ ID: git.MustIDFromString(git.EMPTY_SHA), Author: ghost.NewGitSig(), Committer: ghost.NewGitSig(), CommitMessage: "This is a fake commit", } } apiUser := ctx.User.APIFormat() p := &api.PushPayload{ Ref: git.BRANCH_PREFIX + ctx.Repo.Repository.DefaultBranch, Before: commit.ID.String(), After: commit.ID.String(), Commits: []*api.PayloadCommit{ { ID: commit.ID.String(), Message: commit.Message(), URL: ctx.Repo.Repository.HTMLURL() + "/commit/" + commit.ID.String(), Author: &api.PayloadUser{ Name: commit.Author.Name, Email: commit.Author.Email, }, Committer: &api.PayloadUser{ Name: commit.Committer.Name, Email: commit.Committer.Email, }, }, }, Repo: ctx.Repo.Repository.APIFormat(nil), Pusher: apiUser, Sender: apiUser, } if err := models.PrepareWebhooks(ctx.Repo.Repository, models.HOOK_EVENT_PUSH, p); err != nil { ctx.Flash.Error("PrepareWebhooks: " + err.Error()) ctx.Status(500) } else { go models.HookQueue.Add(ctx.Repo.Repository.ID) ctx.Flash.Info(ctx.Tr("repo.settings.webhook.test_delivery_success")) ctx.Status(200) } }
func TestWebhook(ctx *context.Context) { p := &api.PushPayload{ Ref: git.BRANCH_PREFIX + ctx.Repo.Repository.DefaultBranch, Before: ctx.Repo.CommitID, After: ctx.Repo.CommitID, Commits: []*api.PayloadCommit{ { ID: ctx.Repo.CommitID, Message: ctx.Repo.Commit.Message(), URL: ctx.Repo.Repository.FullLink() + "/commit/" + ctx.Repo.CommitID, Author: &api.PayloadAuthor{ Name: ctx.Repo.Commit.Author.Name, Email: ctx.Repo.Commit.Author.Email, }, Committer: &api.PayloadCommitter{ Name: ctx.Repo.Commit.Committer.Name, Email: ctx.Repo.Commit.Committer.Email, }, }, }, Repo: ctx.Repo.Repository.ComposePayload(), Pusher: &api.PayloadAuthor{ Name: ctx.User.Name, Email: ctx.User.Email, UserName: ctx.User.Name, }, Sender: &api.PayloadUser{ UserName: ctx.User.Name, ID: ctx.User.ID, AvatarUrl: ctx.User.AvatarLink(), }, } if err := models.PrepareWebhooks(ctx.Repo.Repository, models.HOOK_EVENT_PUSH, p); err != nil { ctx.Flash.Error("PrepareWebhooks: " + err.Error()) ctx.Status(500) } else { go models.HookQueue.Add(ctx.Repo.Repository.ID) ctx.Flash.Info(ctx.Tr("repo.settings.webhook.test_delivery_success")) ctx.Status(200) } }