Fix empty repository panic on send test webhook

release/v1.15
Unknwon 2016-08-15 05:53:47 -07:00
parent cc647ba9d5
commit 94392a7af3
8 changed files with 28 additions and 35 deletions

View File

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

View File

@ -18,7 +18,7 @@ github.com/go-xorm/core = commit:5bf745d
github.com/go-xorm/xorm = commit:c6c7056 github.com/go-xorm/xorm = commit:c6c7056
github.com/gogits/chardet = commit:2404f77 github.com/gogits/chardet = commit:2404f77
github.com/gogits/cron = commit:7f3990a 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/gogits/go-gogs-client = commit:e363d3f
github.com/issue9/identicon = commit:d36b545 github.com/issue9/identicon = commit:d36b545
github.com/jaytaylor/html2text = commit:52d9b78 github.com/jaytaylor/html2text = commit:52d9b78

2
glide.lock generated
View File

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

View File

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

View File

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

View File

@ -25,9 +25,8 @@ import (
) )
var ( var (
ErrWrongIssueCounter = errors.New("Invalid number of issues for this milestone") 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")
ErrMissingIssueNumber = errors.New("No issue number specified")
) )
// Issue represents an issue or pull request of repository. // Issue represents an issue or pull request of repository.
@ -834,19 +833,6 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
return issues, sess.Find(&issues) 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
}
// .___ ____ ___ // .___ ____ ___
// | | ______ ________ __ ____ | | \______ ___________ // | | ______ ________ __ ____ | | \______ ___________
// | |/ ___// ___/ | \_/ __ \| | / ___// __ \_ __ \ // | |/ ___// ___/ | \_/ __ \| | / ___// __ \_ __ \

View File

@ -130,7 +130,7 @@ func CreatePost(ctx *context.Context, form auth.CreateRepoForm) {
AutoInit: form.AutoInit, AutoInit: form.AutoInit,
}) })
if err == nil { 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) ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + repo.Name)
return return
} }

View File

@ -347,23 +347,35 @@ func SlackHooksEditPost(ctx *context.Context, form auth.NewSlackHookForm) {
} }
func TestWebhook(ctx *context.Context) { 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() apiUser := ctx.User.APIFormat()
p := &api.PushPayload{ p := &api.PushPayload{
Ref: git.BRANCH_PREFIX + ctx.Repo.Repository.DefaultBranch, Ref: git.BRANCH_PREFIX + ctx.Repo.Repository.DefaultBranch,
Before: ctx.Repo.CommitID, Before: commit.ID.String(),
After: ctx.Repo.CommitID, After: commit.ID.String(),
Commits: []*api.PayloadCommit{ Commits: []*api.PayloadCommit{
{ {
ID: ctx.Repo.CommitID, ID: commit.ID.String(),
Message: ctx.Repo.Commit.Message(), Message: commit.Message(),
URL: ctx.Repo.Repository.FullLink() + "/commit/" + ctx.Repo.CommitID, URL: ctx.Repo.Repository.FullLink() + "/commit/" + commit.ID.String(),
Author: &api.PayloadUser{ Author: &api.PayloadUser{
Name: ctx.Repo.Commit.Author.Name, Name: commit.Author.Name,
Email: ctx.Repo.Commit.Author.Email, Email: commit.Author.Email,
}, },
Committer: &api.PayloadUser{ Committer: &api.PayloadUser{
Name: ctx.Repo.Commit.Committer.Name, Name: commit.Committer.Name,
Email: ctx.Repo.Commit.Committer.Email, Email: commit.Committer.Email,
}, },
}, },
}, },