summaryrefslogtreecommitdiffstats
path: root/routers/repo
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-08-15 05:53:47 -0700
committerUnknwon <u@gogs.io>2016-08-15 05:53:47 -0700
commit94392a7af3d07f79adab195acfb7c1b545f68be9 (patch)
tree7782b7b0ca87f3ca077c98b945892ec833e3b25e /routers/repo
parentcc647ba9d5854319df259377f0c89027bb9f9813 (diff)
downloadgitea-94392a7af3d07f79adab195acfb7c1b545f68be9.tar.gz
gitea-94392a7af3d07f79adab195acfb7c1b545f68be9.zip
Fix empty repository panic on send test webhook
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/repo.go2
-rw-r--r--routers/repo/webhook.go30
2 files changed, 22 insertions, 10 deletions
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index 3c1775dce4..74ee3c4ff8 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -130,7 +130,7 @@ func CreatePost(ctx *context.Context, form auth.CreateRepoForm) {
AutoInit: form.AutoInit,
})
if err == nil {
- log.Trace("Repository created[%d]: %s/%s", repo.ID, ctxUser.Name, repo.Name)
+ log.Trace("Repository created [%d]: %s/%s", repo.ID, ctxUser.Name, repo.Name)
ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + repo.Name)
return
}
diff --git a/routers/repo/webhook.go b/routers/repo/webhook.go
index 8f6ee3f06c..85878e7d1e 100644
--- a/routers/repo/webhook.go
+++ b/routers/repo/webhook.go
@@ -347,23 +347,35 @@ func SlackHooksEditPost(ctx *context.Context, form auth.NewSlackHookForm) {
}
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: ctx.Repo.CommitID,
- After: ctx.Repo.CommitID,
+ Before: commit.ID.String(),
+ After: commit.ID.String(),
Commits: []*api.PayloadCommit{
{
- ID: ctx.Repo.CommitID,
- Message: ctx.Repo.Commit.Message(),
- URL: ctx.Repo.Repository.FullLink() + "/commit/" + ctx.Repo.CommitID,
+ ID: commit.ID.String(),
+ Message: commit.Message(),
+ URL: ctx.Repo.Repository.FullLink() + "/commit/" + commit.ID.String(),
Author: &api.PayloadUser{
- Name: ctx.Repo.Commit.Author.Name,
- Email: ctx.Repo.Commit.Author.Email,
+ Name: commit.Author.Name,
+ Email: commit.Author.Email,
},
Committer: &api.PayloadUser{
- Name: ctx.Repo.Commit.Committer.Name,
- Email: ctx.Repo.Commit.Committer.Email,
+ Name: commit.Committer.Name,
+ Email: commit.Committer.Email,
},
},
},