Fix empty repository panic on send test webhook

tokarchuk/v1.17
Unknwon 8 years ago
parent cc647ba9d5
commit 94392a7af3
  1. 2
      .bra.toml
  2. 2
      .gopmfile
  3. 2
      glide.lock
  4. 2
      gogs.go
  5. 5
      models/action.go
  6. 18
      models/issue.go
  7. 2
      routers/repo/repo.go
  8. 30
      routers/repo/webhook.go

@ -14,6 +14,6 @@ watch_exts = [".go"]
ignore_files = [".+_test.go"]
build_delay = 1500
cmds = [
["make", "build-dev", "TAGS=sqlite"], # cert pam tidb
["make", "build-dev"], # TAGS=sqlite cert pam tidb
["./gogs", "web"]
]

@ -18,7 +18,7 @@ github.com/go-xorm/core = commit:5bf745d
github.com/go-xorm/xorm = commit:c6c7056
github.com/gogits/chardet = commit:2404f77
github.com/gogits/cron = commit:7f3990a
github.com/gogits/git-module = commit:313ce90
github.com/gogits/git-module = commit:31d8d73
github.com/gogits/go-gogs-client = commit:e363d3f
github.com/issue9/identicon = commit:d36b545
github.com/jaytaylor/html2text = commit:52d9b78

2
glide.lock generated

@ -41,7 +41,7 @@ imports:
- name: github.com/gogits/cron
version: 7f3990acf1833faa5ebd0e86f0a4c72a4b5eba3c
- name: github.com/gogits/git-module
version: 313ce907cc5a5801126c7dfa3a74d21cc3104329
version: 31d8d73910d6f9ccb94ba6c17bbd18b1d01492ee
- name: github.com/gogits/go-gogs-client
version: e363d3ff8f70d0fe813324eedf228684af41c29c
- name: github.com/issue9/identicon

@ -27,7 +27,7 @@ func init() {
func main() {
app := cli.NewApp()
app.Name = "Gogs"
app.Usage = "Go Git Service"
app.Usage = "Go Git Service: a painless self-hosted Git service"
app.Version = APP_VER
app.Commands = []cli.Command{
cmd.CmdWeb,

@ -6,7 +6,6 @@ package models
import (
"encoding/json"
"errors"
"fmt"
"path"
"regexp"
@ -45,10 +44,6 @@ const (
ACTION_REOPEN_PULL_REQUEST // 15
)
var (
ErrNotImplemented = errors.New("Not implemented yet")
)
var (
// Same as Github. See https://help.github.com/articles/closing-issues-via-commit-messages
IssueCloseKeywords = []string{"close", "closes", "closed", "fix", "fixes", "fixed", "resolve", "resolves", "resolved"}

@ -25,9 +25,8 @@ import (
)
var (
ErrWrongIssueCounter = errors.New("Invalid number of issues for this milestone")
ErrAttachmentNotLinked = errors.New("Attachment does not belong to this issue")
ErrMissingIssueNumber = errors.New("No issue number specified")
ErrWrongIssueCounter = errors.New("Invalid number of issues for this milestone")
ErrMissingIssueNumber = errors.New("No issue number specified")
)
// Issue represents an issue or pull request of repository.
@ -834,19 +833,6 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
return issues, sess.Find(&issues)
}
type IssueStatus int
const (
IS_OPEN = iota + 1
IS_CLOSE
)
// GetIssueCountByPoster returns number of issues of repository by poster.
func GetIssueCountByPoster(uid, rid int64, isClosed bool) int64 {
count, _ := x.Where("repo_id=?", rid).And("poster_id=?", uid).And("is_closed=?", isClosed).Count(new(Issue))
return count
}
// .___ ____ ___
// | | ______ ________ __ ____ | | \______ ___________
// | |/ ___// ___/ | \_/ __ \| | / ___// __ \_ __ \

@ -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
}

@ -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,
},
},
},

Loading…
Cancel
Save