#2246 fully support of webhooks for pull request

This commit is contained in:
Unknwon committed 2016-08-14 03:32:24 -07:00
1 parent 0f33b04c87
commit 3f7f4852ef
30 files changed
+795 -270

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
##### Current tip version: 0.9.75 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions) ##### Current tip version: 0.9.76 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
| Web | UI | Preview | | Web | UI | Preview |
|:-------------:|:-------:|:-------:| |:-------------:|:-------:|:-------:|
+1 -1
View File
@@ -113,7 +113,7 @@ func handleUpdateTask(uuid string, user, repoUser *models.User, reponame string,
// Ask for running deliver hook and test pull request tasks. // Ask for running deliver hook and test pull request tasks.
reqURL := setting.LocalURL + repoUser.Name + "/" + reponame + "/tasks/trigger?branch=" + reqURL := setting.LocalURL + repoUser.Name + "/" + reponame + "/tasks/trigger?branch=" +
strings.TrimPrefix(task.RefName, "refs/heads/") + "&secret=" + base.EncodeMD5(repoUser.Salt) strings.TrimPrefix(task.RefName, "refs/heads/") + "&secret=" + base.EncodeMD5(repoUser.Salt) + "&pusher=" + com.ToStr(user.ID)
log.GitLogger.Trace("Trigger task: %s", reqURL) log.GitLogger.Trace("Trigger task: %s", reqURL)
resp, err := httplib.Head(reqURL).SetTLSClientConfig(&tls.Config{ resp, err := httplib.Head(reqURL).SetTLSClientConfig(&tls.Config{
+2
View File
@@ -666,6 +666,8 @@ settings.event_send_everything = I need <strong>everything</strong>.
settings.event_choose = Let me choose what I need. settings.event_choose = Let me choose what I need.
settings.event_create = Create settings.event_create = Create
settings.event_create_desc = Branch, or tag created settings.event_create_desc = Branch, or tag created
settings.event_pull_request = Pull Request
settings.event_pull_request_desc = Pull request opened, closed, reopened, edited, assigned, unassigned, label updated, label cleared, or synchronized.
settings.event_push = Push settings.event_push = Push
settings.event_push_desc = Git push to a repository settings.event_push_desc = Git push to a repository
settings.active = Active settings.active = Active
+1 -1
View File
@@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.9.75.0813" const APP_VER = "0.9.76.0814"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())
+9 -10
View File
@@ -169,7 +169,7 @@ func (a *Action) GetIssueTitle() string {
log.Error(4, "GetIssueByIndex: %v", err) log.Error(4, "GetIssueByIndex: %v", err)
return "500 when get issue" return "500 when get issue"
} }
return issue.Name return issue.Title
} }
func (a *Action) GetIssueContent() string { func (a *Action) GetIssueContent() string {
@@ -513,11 +513,11 @@ func CommitRepoAction(
payloadRepo := repo.ComposePayload() payloadRepo := repo.ComposePayload()
pusher_email, pusher_name := "", "" var pusherEmail, pusherName string
pusher, err := GetUserByName(userName) pusher, err := GetUserByName(userName)
if err == nil { if err == nil {
pusher_email = pusher.Email pusherEmail = pusher.Email
pusher_name = pusher.DisplayName() pusherName = pusher.DisplayName()
} }
payloadSender := &api.PayloadUser{ payloadSender := &api.PayloadUser{
UserName: pusher.Name, UserName: pusher.Name,
@@ -527,7 +527,7 @@ func CommitRepoAction(
switch opType { switch opType {
case ACTION_COMMIT_REPO: // Push case ACTION_COMMIT_REPO: // Push
p := &api.PushPayload{ if err = PrepareWebhooks(repo, HOOK_EVENT_PUSH, &api.PushPayload{
Ref: refFullName, Ref: refFullName,
Before: oldCommitID, Before: oldCommitID,
After: newCommitID, After: newCommitID,
@@ -535,13 +535,12 @@ func CommitRepoAction(
Commits: commit.ToApiPayloadCommits(repo.FullLink()), Commits: commit.ToApiPayloadCommits(repo.FullLink()),
Repo: payloadRepo, Repo: payloadRepo,
Pusher: &api.PayloadAuthor{ Pusher: &api.PayloadAuthor{
Name: pusher_name, Name: pusherName,
Email: pusher_email, Email: pusherEmail,
UserName: userName, UserName: userName,
}, },
Sender: payloadSender, Sender: payloadSender,
} }); err != nil {
if err = PrepareWebhooks(repo, HOOK_EVENT_PUSH, p); err != nil {
return fmt.Errorf("PrepareWebhooks: %v", err) return fmt.Errorf("PrepareWebhooks: %v", err)
} }
@@ -603,7 +602,7 @@ func mergePullRequestAction(e Engine, actUser *User, repo *Repository, pull *Iss
ActUserName: actUser.Name, ActUserName: actUser.Name,
ActEmail: actUser.Email, ActEmail: actUser.Email,
OpType: ACTION_MERGE_PULL_REQUEST, OpType: ACTION_MERGE_PULL_REQUEST,
Content: fmt.Sprintf("%d|%s", pull.Index, pull.Name), Content: fmt.Sprintf("%d|%s", pull.Index, pull.Title),
RepoID: repo.ID, RepoID: repo.ID,
RepoUserName: repo.Owner.Name, RepoUserName: repo.Owner.Name,
RepoName: repo.Name, RepoName: repo.Name,
+300 -62
View File
@@ -16,6 +16,7 @@ import (
"github.com/Unknwon/com" "github.com/Unknwon/com"
"github.com/go-xorm/xorm" "github.com/go-xorm/xorm"
api "github.com/gogits/go-gogs-client"
gouuid "github.com/satori/go.uuid" gouuid "github.com/satori/go.uuid"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
@@ -31,10 +32,10 @@ var (
// Issue represents an issue or pull request of repository. // Issue represents an issue or pull request of repository.
type Issue struct { type Issue struct {
ID int64 `xorm:"pk autoincr"` ID int64 `xorm:"pk autoincr"`
RepoID int64 `xorm:"INDEX UNIQUE(repo_index)"` RepoID int64 `xorm:"INDEX UNIQUE(repo_index)"`
Index int64 `xorm:"UNIQUE(repo_index)"` // Index in one repository. Index int64 `xorm:"UNIQUE(repo_index)"` // Index in one repository.
Name string Title string `xorm:"name"`
Repo *Repository `xorm:"-"` Repo *Repository `xorm:"-"`
PosterID int64 PosterID int64
Poster *User `xorm:"-"` Poster *User `xorm:"-"`
@@ -73,19 +74,6 @@ func (i *Issue) BeforeUpdate() {
i.DeadlineUnix = i.Deadline.Unix() i.DeadlineUnix = i.Deadline.Unix()
} }
func (issue *Issue) loadAttributes(e Engine) (err error) {
issue.Repo, err = getRepositoryByID(e, issue.RepoID)
if err != nil {
return fmt.Errorf("getRepositoryByID: %v", err)
}
return nil
}
func (issue *Issue) LoadAttributes() error {
return issue.loadAttributes(x)
}
func (i *Issue) AfterSet(colName string, _ xorm.Cell) { func (i *Issue) AfterSet(colName string, _ xorm.Cell) {
var err error var err error
switch colName { switch colName {
@@ -110,7 +98,7 @@ func (i *Issue) AfterSet(colName string, _ xorm.Cell) {
if err != nil { if err != nil {
if IsErrUserNotExist(err) { if IsErrUserNotExist(err) {
i.PosterID = -1 i.PosterID = -1
i.Poster = NewFakeUser() i.Poster = NewGhostUser()
} else { } else {
log.Error(3, "GetUserByID[%d]: %v", i.ID, err) log.Error(3, "GetUserByID[%d]: %v", i.ID, err)
} }
@@ -146,17 +134,80 @@ func (i *Issue) AfterSet(colName string, _ xorm.Cell) {
} }
} }
// HashTag returns unique hash tag for issue. func (issue *Issue) loadAttributes(e Engine) (err error) {
func (i *Issue) HashTag() string { if issue.Repo == nil {
return "issue-" + com.ToStr(i.ID) issue.Repo, err = getRepositoryByID(e, issue.RepoID)
if err != nil {
return fmt.Errorf("getRepositoryByID [%d]: %v", issue.RepoID, err)
}
}
if issue.IsPull && issue.PullRequest == nil {
// It is possible pull request is not yet created.
issue.PullRequest, err = getPullRequestByIssueID(e, issue.ID)
if err != nil && !IsErrPullRequestNotExist(err) {
return fmt.Errorf("getPullRequestByIssueID [%d]: %v", issue.ID, err)
}
}
return nil
}
func (issue *Issue) LoadAttributes() error {
return issue.loadAttributes(x)
} }
// State returns string representation of issue status. // State returns string representation of issue status.
func (i *Issue) State() string { func (i *Issue) State() api.StateType {
if i.IsClosed { if i.IsClosed {
return "closed" return api.STATE_CLOSED
} }
return "open" return api.STATE_OPEN
}
// This method assumes some fields assigned with values:
// Required - Poster, Labels,
// Optional - Milestone, Assignee, PullRequest
func (issue *Issue) APIFormat() *api.Issue {
apiLabels := make([]*api.Label, len(issue.Labels))
for i := range issue.Labels {
apiLabels[i] = issue.Labels[i].APIFormat()
}
apiIssue := &api.Issue{
ID: issue.ID,
Index: issue.Index,
State: issue.State(),
Title: issue.Title,
Body: issue.Content,
User: issue.Poster.APIFormat(),
Labels: apiLabels,
Comments: issue.NumComments,
Created: issue.Created,
Updated: issue.Updated,
}
if issue.Milestone != nil {
apiIssue.Milestone = issue.Milestone.APIFormat()
}
if issue.Assignee != nil {
apiIssue.Assignee = issue.Assignee.APIFormat()
}
if issue.IsPull {
apiIssue.PullRequest = &api.PullRequestMeta{
HasMerged: issue.PullRequest.HasMerged,
}
if issue.PullRequest.HasMerged {
apiIssue.PullRequest.Merged = &issue.PullRequest.Merged
}
}
return apiIssue
}
// HashTag returns unique hash tag for issue.
func (i *Issue) HashTag() string {
return "issue-" + com.ToStr(i.ID)
} }
func (issue *Issue) FullLink() string { func (issue *Issue) FullLink() string {
@@ -183,23 +234,37 @@ func (i *Issue) HasLabel(labelID int64) bool {
return i.hasLabel(x, labelID) return i.hasLabel(x, labelID)
} }
func (issue *Issue) sendLabelUpdatedWebhook(doer *User) {
var err error
if issue.IsPull {
issue.PullRequest.Issue = issue
err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{
Action: api.HOOK_ISSUE_LABEL_UPDATED,
Index: issue.Index,
PullRequest: issue.PullRequest.APIFormat(),
Repository: issue.Repo.APIFormat(nil),
Sender: doer.APIFormat(),
})
}
if err != nil {
log.Error(4, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
} else {
go HookQueue.Add(issue.RepoID)
}
}
func (i *Issue) addLabel(e *xorm.Session, label *Label) error { func (i *Issue) addLabel(e *xorm.Session, label *Label) error {
return newIssueLabel(e, i, label) return newIssueLabel(e, i, label)
} }
// AddLabel adds a new label to the issue. // AddLabel adds a new label to the issue.
func (i *Issue) AddLabel(label *Label) (err error) { func (issue *Issue) AddLabel(doer *User, label *Label) error {
sess := x.NewSession() if err := NewIssueLabel(issue, label); err != nil {
defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
return err return err
} }
if err = i.addLabel(sess, label); err != nil { issue.sendLabelUpdatedWebhook(doer)
return err return nil
}
return sess.Commit()
} }
func (issue *Issue) addLabels(e *xorm.Session, labels []*Label) error { func (issue *Issue) addLabels(e *xorm.Session, labels []*Label) error {
@@ -207,8 +272,13 @@ func (issue *Issue) addLabels(e *xorm.Session, labels []*Label) error {
} }
// AddLabels adds a list of new labels to the issue. // AddLabels adds a list of new labels to the issue.
func (issue *Issue) AddLabels(labels []*Label) error { func (issue *Issue) AddLabels(doer *User, labels []*Label) error {
return NewIssueLabels(issue, labels) if err := NewIssueLabels(issue, labels); err != nil {
return err
}
issue.sendLabelUpdatedWebhook(doer)
return nil
} }
func (issue *Issue) getLabels(e Engine) (err error) { func (issue *Issue) getLabels(e Engine) (err error) {
@@ -228,8 +298,13 @@ func (issue *Issue) removeLabel(e *xorm.Session, label *Label) error {
} }
// RemoveLabel removes a label from issue by given ID. // RemoveLabel removes a label from issue by given ID.
func (issue *Issue) RemoveLabel(label *Label) (err error) { func (issue *Issue) RemoveLabel(doer *User, label *Label) error {
return DeleteIssueLabel(issue, label) if err := DeleteIssueLabel(issue, label); err != nil {
return err
}
issue.sendLabelUpdatedWebhook(doer)
return nil
} }
func (issue *Issue) clearLabels(e *xorm.Session) (err error) { func (issue *Issue) clearLabels(e *xorm.Session) (err error) {
@@ -246,7 +321,7 @@ func (issue *Issue) clearLabels(e *xorm.Session) (err error) {
return nil return nil
} }
func (issue *Issue) ClearLabels() (err error) { func (issue *Issue) ClearLabels(doer *User) (err error) {
sess := x.NewSession() sess := x.NewSession()
defer sessionRelease(sess) defer sessionRelease(sess)
if err = sess.Begin(); err != nil { if err = sess.Begin(); err != nil {
@@ -257,7 +332,27 @@ func (issue *Issue) ClearLabels() (err error) {
return err return err
} }
return sess.Commit() if err = sess.Commit(); err != nil {
return fmt.Errorf("Commit: %v", err)
}
if issue.IsPull {
issue.PullRequest.Issue = issue
err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{
Action: api.HOOK_ISSUE_LABEL_CLEARED,
Index: issue.Index,
PullRequest: issue.PullRequest.APIFormat(),
Repository: issue.Repo.APIFormat(nil),
Sender: doer.APIFormat(),
})
}
if err != nil {
log.Error(4, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
} else {
go HookQueue.Add(issue.RepoID)
}
return nil
} }
// ReplaceLabels removes all current labels and add new labels to the issue. // ReplaceLabels removes all current labels and add new labels to the issue.
@@ -294,6 +389,16 @@ func (i *Issue) ReadBy(uid int64) error {
return UpdateIssueUserByRead(uid, i.ID) return UpdateIssueUserByRead(uid, i.ID)
} }
func updateIssueCols(e Engine, issue *Issue, cols ...string) error {
_, err := e.Id(issue.ID).Cols(cols...).Update(issue)
return err
}
// UpdateIssueCols only updates values of specific columns for given issue.
func UpdateIssueCols(issue *Issue, cols ...string) error {
return updateIssueCols(x, issue, cols...)
}
func (i *Issue) changeStatus(e *xorm.Session, doer *User, repo *Repository, isClosed bool) (err error) { func (i *Issue) changeStatus(e *xorm.Session, doer *User, repo *Repository, isClosed bool) (err error) {
// Nothing should be performed if current status is same as target status // Nothing should be performed if current status is same as target status
if i.IsClosed == isClosed { if i.IsClosed == isClosed {
@@ -336,32 +441,149 @@ func (i *Issue) changeStatus(e *xorm.Session, doer *User, repo *Repository, isCl
} }
// ChangeStatus changes issue status to open or closed. // ChangeStatus changes issue status to open or closed.
func (i *Issue) ChangeStatus(doer *User, repo *Repository, isClosed bool) (err error) { func (issue *Issue) ChangeStatus(doer *User, repo *Repository, isClosed bool) (err error) {
sess := x.NewSession() sess := x.NewSession()
defer sessionRelease(sess) defer sessionRelease(sess)
if err = sess.Begin(); err != nil { if err = sess.Begin(); err != nil {
return err return err
} }
if err = i.changeStatus(sess, doer, repo, isClosed); err != nil { if err = issue.changeStatus(sess, doer, repo, isClosed); err != nil {
return err return err
} }
return sess.Commit() if err = sess.Commit(); err != nil {
return fmt.Errorf("Commit: %v", err)
}
if issue.IsPull {
// Merge pull request calls issue.changeStatus so we need to handle separately.
issue.PullRequest.Issue = issue
apiPullRequest := &api.PullRequestPayload{
Index: issue.Index,
PullRequest: issue.PullRequest.APIFormat(),
Repository: repo.APIFormat(nil),
Sender: doer.APIFormat(),
}
if isClosed {
apiPullRequest.Action = api.HOOK_ISSUE_CLOSED
} else {
apiPullRequest.Action = api.HOOK_ISSUE_REOPENED
}
err = PrepareWebhooks(repo, HOOK_EVENT_PULL_REQUEST, apiPullRequest)
}
if err != nil {
log.Error(4, "PrepareWebhooks [is_pull: %v, is_closed: %v]: %v", issue.IsPull, isClosed, err)
} else {
go HookQueue.Add(repo.ID)
}
return nil
} }
func (i *Issue) GetPullRequest() (err error) { func (issue *Issue) ChangeTitle(doer *User, title string) (err error) {
if i.PullRequest != nil { oldTitle := issue.Title
issue.Title = title
if err = UpdateIssueCols(issue, "name"); err != nil {
return fmt.Errorf("UpdateIssueCols: %v", err)
}
if issue.IsPull {
issue.PullRequest.Issue = issue
err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{
Action: api.HOOK_ISSUE_EDITED,
Index: issue.Index,
Changes: &api.ChangesPayload{
Title: &api.ChangesFromPayload{
From: oldTitle,
},
},
PullRequest: issue.PullRequest.APIFormat(),
Repository: issue.Repo.APIFormat(nil),
Sender: doer.APIFormat(),
})
}
if err != nil {
log.Error(4, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
} else {
go HookQueue.Add(issue.RepoID)
}
return nil
}
func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
oldContent := issue.Content
issue.Content = content
if err = UpdateIssueCols(issue, "content"); err != nil {
return fmt.Errorf("UpdateIssueCols: %v", err)
}
if issue.IsPull {
issue.PullRequest.Issue = issue
err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{
Action: api.HOOK_ISSUE_EDITED,
Index: issue.Index,
Changes: &api.ChangesPayload{
Body: &api.ChangesFromPayload{
From: oldContent,
},
},
PullRequest: issue.PullRequest.APIFormat(),
Repository: issue.Repo.APIFormat(nil),
Sender: doer.APIFormat(),
})
}
if err != nil {
log.Error(4, "PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
} else {
go HookQueue.Add(issue.RepoID)
}
return nil
}
func (issue *Issue) ChangeAssignee(doer *User, assigneeID int64) (err error) {
issue.AssigneeID = assigneeID
if err = UpdateIssueUserByAssignee(issue); err != nil {
return fmt.Errorf("UpdateIssueUserByAssignee: %v", err)
}
issue.Assignee, err = GetUserByID(issue.AssigneeID)
if err != nil && !IsErrUserNotExist(err) {
log.Error(4, "GetUserByID [assignee_id: %v]: %v", issue.AssigneeID, err)
return nil return nil
} }
i.PullRequest, err = GetPullRequestByIssueID(i.ID) // Error not nil here means user does not exist, which is remove assignee.
return err isRemoveAssignee := err != nil
if issue.IsPull {
issue.PullRequest.Issue = issue
apiPullRequest := &api.PullRequestPayload{
Index: issue.Index,
PullRequest: issue.PullRequest.APIFormat(),
Repository: issue.Repo.APIFormat(nil),
Sender: doer.APIFormat(),
}
if isRemoveAssignee {
apiPullRequest.Action = api.HOOK_ISSUE_UNASSIGNED
} else {
apiPullRequest.Action = api.HOOK_ISSUE_ASSIGNED
}
err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, apiPullRequest)
}
if err != nil {
log.Error(4, "PrepareWebhooks [is_pull: %v, remove_assignee: %v]: %v", issue.IsPull, isRemoveAssignee, err)
} else {
go HookQueue.Add(issue.RepoID)
}
return nil
} }
// It's caller's responsibility to create action. // It's caller's responsibility to create action.
func newIssue(e *xorm.Session, repo *Repository, issue *Issue, labelIDs []int64, uuids []string, isPull bool) (err error) { func newIssue(e *xorm.Session, repo *Repository, issue *Issue, labelIDs []int64, uuids []string, isPull bool) (err error) {
issue.Name = strings.TrimSpace(issue.Name) issue.Title = strings.TrimSpace(issue.Title)
issue.Index = repo.NextIssueIndex() issue.Index = repo.NextIssueIndex()
if issue.AssigneeID > 0 { if issue.AssigneeID > 0 {
@@ -462,7 +684,7 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string)
ActUserName: issue.Poster.Name, ActUserName: issue.Poster.Name,
ActEmail: issue.Poster.Email, ActEmail: issue.Poster.Email,
OpType: ACTION_CREATE_ISSUE, OpType: ACTION_CREATE_ISSUE,
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Name), Content: fmt.Sprintf("%d|%s", issue.Index, issue.Title),
RepoID: repo.ID, RepoID: repo.ID,
RepoUserName: repo.Owner.Name, RepoUserName: repo.Owner.Name,
RepoName: repo.Name, RepoName: repo.Name,
@@ -518,10 +740,9 @@ func GetIssueByIndex(repoID, index int64) (*Issue, error) {
return issue, issue.LoadAttributes() return issue, issue.LoadAttributes()
} }
// GetIssueByID returns an issue by given ID. func getIssueByID(e Engine, id int64) (*Issue, error) {
func GetIssueByID(id int64) (*Issue, error) {
issue := new(Issue) issue := new(Issue)
has, err := x.Id(id).Get(issue) has, err := e.Id(id).Get(issue)
if err != nil { if err != nil {
return nil, err return nil, err
} else if !has { } else if !has {
@@ -530,6 +751,11 @@ func GetIssueByID(id int64) (*Issue, error) {
return issue, issue.LoadAttributes() return issue, issue.LoadAttributes()
} }
// GetIssueByID returns an issue by given ID.
func GetIssueByID(id int64) (*Issue, error) {
return getIssueByID(x, id)
}
type IssuesOptions struct { type IssuesOptions struct {
UserID int64 UserID int64
AssigneeID int64 AssigneeID int64
@@ -970,12 +1196,6 @@ func UpdateIssue(issue *Issue) error {
return updateIssue(x, issue) return updateIssue(x, issue)
} }
// updateIssueCols only updates values of specific columns for given issue.
func updateIssueCols(e Engine, issue *Issue, cols ...string) error {
_, err := e.Id(issue.ID).Cols(cols...).Update(issue)
return err
}
func updateIssueUsersByStatus(e Engine, issueID int64, isClosed bool) error { func updateIssueUsersByStatus(e Engine, issueID int64, isClosed bool) error {
_, err := e.Exec("UPDATE `issue_user` SET is_closed=? WHERE issue_id=?", isClosed, issueID) _, err := e.Exec("UPDATE `issue_user` SET is_closed=? WHERE issue_id=?", isClosed, issueID)
return err return err
@@ -987,13 +1207,13 @@ func UpdateIssueUsersByStatus(issueID int64, isClosed bool) error {
} }
func updateIssueUserByAssignee(e *xorm.Session, issue *Issue) (err error) { func updateIssueUserByAssignee(e *xorm.Session, issue *Issue) (err error) {
if _, err = e.Exec("UPDATE `issue_user` SET is_assigned=? WHERE issue_id=?", false, issue.ID); err != nil { if _, err = e.Exec("UPDATE `issue_user` SET is_assigned = ? WHERE issue_id = ?", false, issue.ID); err != nil {
return err return err
} }
// Assignee ID equals to 0 means clear assignee. // Assignee ID equals to 0 means clear assignee.
if issue.AssigneeID > 0 { if issue.AssigneeID > 0 {
if _, err = e.Exec("UPDATE `issue_user` SET is_assigned=? WHERE uid=? AND issue_id=?", true, issue.AssigneeID, issue.ID); err != nil { if _, err = e.Exec("UPDATE `issue_user` SET is_assigned = ? WHERE uid = ? AND issue_id = ?", true, issue.AssigneeID, issue.ID); err != nil {
return err return err
} }
} }
@@ -1112,11 +1332,29 @@ func (m *Milestone) AfterSet(colName string, _ xorm.Cell) {
} }
// State returns string representation of milestone status. // State returns string representation of milestone status.
func (m *Milestone) State() string { func (m *Milestone) State() api.StateType {
if m.IsClosed { if m.IsClosed {
return "closed" return api.STATE_CLOSED
} }
return "open" return api.STATE_OPEN
}
func (m *Milestone) APIFormat() *api.Milestone {
apiMilestone := &api.Milestone{
ID: m.ID,
State: m.State(),
Title: m.Name,
Description: m.Content,
OpenIssues: m.NumOpenIssues,
ClosedIssues: m.NumClosedIssues,
}
if m.IsClosed {
apiMilestone.Closed = &m.ClosedDate
}
if m.Deadline.Year() < 9999 {
apiMilestone.Deadline = &m.Deadline
}
return apiMilestone
} }
// NewMilestone creates new milestone of repository. // NewMilestone creates new milestone of repository.
+1 -1
View File
@@ -86,7 +86,7 @@ func (c *Comment) AfterSet(colName string, _ xorm.Cell) {
if err != nil { if err != nil {
if IsErrUserNotExist(err) { if IsErrUserNotExist(err) {
c.PosterID = -1 c.PosterID = -1
c.Poster = NewFakeUser() c.Poster = NewGhostUser()
} else { } else {
log.Error(3, "GetUserByID[%d]: %v", c.ID, err) log.Error(3, "GetUserByID[%d]: %v", c.ID, err)
} }
+12 -2
View File
@@ -12,6 +12,8 @@ import (
"github.com/go-xorm/xorm" "github.com/go-xorm/xorm"
api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
) )
@@ -27,9 +29,17 @@ type Label struct {
IsChecked bool `xorm:"-"` IsChecked bool `xorm:"-"`
} }
func (label *Label) APIFormat() *api.Label {
return &api.Label{
ID: label.ID,
Name: label.Name,
Color: label.Color,
}
}
// CalOpenIssues calculates the open issues of label. // CalOpenIssues calculates the open issues of label.
func (m *Label) CalOpenIssues() { func (label *Label) CalOpenIssues() {
m.NumOpenIssues = m.NumIssues - m.NumClosedIssues label.NumOpenIssues = label.NumIssues - label.NumClosedIssues
} }
// ForegroundColor calculates the text color for labels based // ForegroundColor calculates the text color for labels based
+1 -1
View File
@@ -15,7 +15,7 @@ import (
) )
func (issue *Issue) MailSubject() string { func (issue *Issue) MailSubject() string {
return fmt.Sprintf("[%s] %s (#%d)", issue.Repo.Name, issue.Name, issue.Index) return fmt.Sprintf("[%s] %s (#%d)", issue.Repo.Name, issue.Title, issue.Index)
} }
// mailIssueCommentToParticipants can be used for both new issue creation and comment. // mailIssueCommentToParticipants can be used for both new issue creation and comment.
+217 -65
View File
@@ -68,7 +68,7 @@ func (pr *PullRequest) BeforeUpdate() {
pr.MergedUnix = pr.Merged.Unix() pr.MergedUnix = pr.Merged.Unix()
} }
// Note: don't try to get Pull because will end up recursive querying. // Note: don't try to get Issue because will end up recursive querying.
func (pr *PullRequest) AfterSet(colName string, _ xorm.Cell) { func (pr *PullRequest) AfterSet(colName string, _ xorm.Cell) {
switch colName { switch colName {
case "merged_unix": case "merged_unix":
@@ -80,6 +80,62 @@ func (pr *PullRequest) AfterSet(colName string, _ xorm.Cell) {
} }
} }
// Note: don't try to get Issue because will end up recursive querying.
func (pr *PullRequest) loadAttributes(e Engine) (err error) {
if pr.HasMerged && pr.Merger == nil {
pr.Merger, err = getUserByID(e, pr.MergerID)
if IsErrUserNotExist(err) {
pr.MergerID = -1
pr.Merger = NewGhostUser()
} else if err != nil {
return fmt.Errorf("getUserByID [%d]: %v", pr.MergerID, err)
}
}
return nil
}
func (pr *PullRequest) LoadAttributes() error {
return pr.loadAttributes(x)
}
func (pr *PullRequest) LoadIssue() (err error) {
pr.Issue, err = GetIssueByID(pr.IssueID)
return err
}
// This method assumes following fields have been assigned with valid values:
// Required - Issue
// Optional - Merger
func (pr *PullRequest) APIFormat() *api.PullRequest {
apiIssue := pr.Issue.APIFormat()
apiPullRequest := &api.PullRequest{
ID: pr.ID,
Index: pr.Index,
State: apiIssue.State,
Title: apiIssue.Title,
Body: apiIssue.Body,
User: apiIssue.User,
Labels: apiIssue.Labels,
Milestone: apiIssue.Milestone,
Assignee: apiIssue.Assignee,
Comments: apiIssue.Comments,
HasMerged: pr.HasMerged,
}
if pr.Status != PULL_REQUEST_STATUS_CHECKING {
mergeable := pr.Status != PULL_REQUEST_STATUS_CONFLICT
apiPullRequest.Mergeable = &mergeable
}
if pr.HasMerged {
apiPullRequest.Merged = &pr.Merged
apiPullRequest.MergedCommitID = &pr.MergedCommitID
apiPullRequest.MergedBy = pr.Merger.APIFormat()
}
return apiPullRequest
}
func (pr *PullRequest) getHeadRepo(e Engine) (err error) { func (pr *PullRequest) getHeadRepo(e Engine) (err error) {
pr.HeadRepo, err = getRepositoryByID(e, pr.HeadRepoID) pr.HeadRepo, err = getRepositoryByID(e, pr.HeadRepoID)
if err != nil && !IsErrRepoNotExist(err) { if err != nil && !IsErrRepoNotExist(err) {
@@ -88,7 +144,7 @@ func (pr *PullRequest) getHeadRepo(e Engine) (err error) {
return nil return nil
} }
func (pr *PullRequest) GetHeadRepo() (err error) { func (pr *PullRequest) GetHeadRepo() error {
return pr.getHeadRepo(x) return pr.getHeadRepo(x)
} }
@@ -104,21 +160,6 @@ func (pr *PullRequest) GetBaseRepo() (err error) {
return nil return nil
} }
func (pr *PullRequest) GetMerger() (err error) {
if !pr.HasMerged || pr.Merger != nil {
return nil
}
pr.Merger, err = GetUserByID(pr.MergerID)
if IsErrUserNotExist(err) {
pr.MergerID = -1
pr.Merger = NewFakeUser()
} else if err != nil {
return fmt.Errorf("GetUserByID: %v", err)
}
return nil
}
// IsChecking returns true if this pull request is still checking conflict. // IsChecking returns true if this pull request is still checking conflict.
func (pr *PullRequest) IsChecking() bool { func (pr *PullRequest) IsChecking() bool {
return pr.Status == PULL_REQUEST_STATUS_CHECKING return pr.Status == PULL_REQUEST_STATUS_CHECKING
@@ -130,6 +171,7 @@ func (pr *PullRequest) CanAutoMerge() bool {
} }
// Merge merges pull request to base repository. // Merge merges pull request to base repository.
// FIXME: add repoWorkingPull make sure two merges does not happen at same time.
func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error) { func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error) {
if err = pr.GetHeadRepo(); err != nil { if err = pr.GetHeadRepo(); err != nil {
return fmt.Errorf("GetHeadRepo: %v", err) return fmt.Errorf("GetHeadRepo: %v", err)
@@ -137,6 +179,11 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error
return fmt.Errorf("GetBaseRepo: %v", err) return fmt.Errorf("GetBaseRepo: %v", err)
} }
defer func() {
go HookQueue.Add(pr.BaseRepo.ID)
go AddTestPullRequestTask(doer, pr.BaseRepo.ID, pr.BaseBranch, false)
}()
sess := x.NewSession() sess := x.NewSession()
defer sessionRelease(sess) defer sessionRelease(sess)
if err = sess.Begin(); err != nil { if err = sess.Begin(); err != nil {
@@ -152,21 +199,6 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error
if err != nil { if err != nil {
return fmt.Errorf("OpenRepository: %v", err) return fmt.Errorf("OpenRepository: %v", err)
} }
pr.MergedCommitID, err = headGitRepo.GetBranchCommitID(pr.HeadBranch)
if err != nil {
return fmt.Errorf("GetBranchCommitID: %v", err)
}
if err = mergePullRequestAction(sess, doer, pr.Issue.Repo, pr.Issue); err != nil {
return fmt.Errorf("mergePullRequestAction: %v", err)
}
pr.HasMerged = true
pr.Merged = time.Now()
pr.MergerID = doer.ID
if _, err = sess.Id(pr.ID).AllCols().Update(pr); err != nil {
return fmt.Errorf("update pull request: %v", err)
}
// Clone base repo. // Clone base repo.
tmpBasePath := path.Join(setting.AppDataPath, "tmp/repos", com.ToStr(time.Now().Nanosecond())+".git") tmpBasePath := path.Join(setting.AppDataPath, "tmp/repos", com.ToStr(time.Now().Nanosecond())+".git")
@@ -222,15 +254,59 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error
return fmt.Errorf("git push: %s", stderr) return fmt.Errorf("git push: %s", stderr)
} }
pr.MergedCommitID, err = headGitRepo.GetBranchCommitID(pr.HeadBranch)
if err != nil {
return fmt.Errorf("GetBranchCommit: %v", err)
}
pr.HasMerged = true
pr.Merged = time.Now()
pr.MergerID = doer.ID
if _, err = sess.Id(pr.ID).AllCols().Update(pr); err != nil {
return fmt.Errorf("update pull request: %v", err)
}
if err = sess.Commit(); err != nil { if err = sess.Commit(); err != nil {
return fmt.Errorf("Commit: %v", err) return fmt.Errorf("Commit: %v", err)
} }
// Compose commit repository action if err = MergePullRequestAction(doer, pr.Issue.Repo, pr.Issue); err != nil {
log.Error(4, "MergePullRequestAction [%d]: %v", pr.ID, err)
}
// Reload pull request information.
if err = pr.LoadAttributes(); err != nil {
log.Error(4, "LoadAttributes: %v", err)
return nil
}
if err = PrepareWebhooks(pr.Issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{
Action: api.HOOK_ISSUE_CLOSED,
Index: pr.Index,
PullRequest: pr.APIFormat(),
Repository: pr.Issue.Repo.APIFormat(nil),
Sender: doer.APIFormat(),
}); err != nil {
log.Error(4, "PrepareWebhooks: %v", err)
return nil
}
l, err := headGitRepo.CommitsBetweenIDs(pr.MergedCommitID, pr.MergeBase) l, err := headGitRepo.CommitsBetweenIDs(pr.MergedCommitID, pr.MergeBase)
if err != nil { if err != nil {
return fmt.Errorf("CommitsBetween: %v", err) log.Error(4, "CommitsBetweenIDs: %v", err)
return nil
} }
// TODO: when squash commits, no need to append merge commit.
// It is possible that head branch is not fully sync with base branch for merge commits,
// so we need to get latest head commit and append merge commit manully
// to avoid strange diff commits produced.
mergeCommit, err := baseGitRepo.GetBranchCommit(pr.BaseBranch)
if err != nil {
log.Error(4, "GetBranchCommit: %v", err)
return nil
}
l.PushFront(mergeCommit)
p := &api.PushPayload{ p := &api.PushPayload{
Ref: "refs/heads/" + pr.BaseBranch, Ref: "refs/heads/" + pr.BaseBranch,
Before: pr.MergeBase, Before: pr.MergeBase,
@@ -252,8 +328,6 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error
if err = PrepareWebhooks(pr.BaseRepo, HOOK_EVENT_PUSH, p); err != nil { if err = PrepareWebhooks(pr.BaseRepo, HOOK_EVENT_PUSH, p); err != nil {
return fmt.Errorf("PrepareWebhooks: %v", err) return fmt.Errorf("PrepareWebhooks: %v", err)
} }
go HookQueue.Add(pr.BaseRepo.ID)
go AddTestPullRequestTask(pr.BaseRepo.ID, pr.BaseBranch)
return nil return nil
} }
@@ -331,19 +405,6 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str
return fmt.Errorf("newIssue: %v", err) return fmt.Errorf("newIssue: %v", err)
} }
// Notify watchers.
act := &Action{
ActUserID: pull.Poster.ID,
ActUserName: pull.Poster.Name,
ActEmail: pull.Poster.Email,
OpType: ACTION_CREATE_PULL_REQUEST,
Content: fmt.Sprintf("%d|%s", pull.Index, pull.Name),
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,
RepoName: repo.Name,
IsPrivate: repo.IsPrivate,
}
pr.Index = pull.Index pr.Index = pull.Index
if err = repo.SavePatch(pr.Index, patch); err != nil { if err = repo.SavePatch(pr.Index, patch); err != nil {
return fmt.Errorf("SavePatch: %v", err) return fmt.Errorf("SavePatch: %v", err)
@@ -353,6 +414,7 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str
if err = pr.testPatch(); err != nil { if err = pr.testPatch(); err != nil {
return fmt.Errorf("testPatch: %v", err) return fmt.Errorf("testPatch: %v", err)
} }
// No conflict appears after test means mergeable.
if pr.Status == PULL_REQUEST_STATUS_CHECKING { if pr.Status == PULL_REQUEST_STATUS_CHECKING {
pr.Status = PULL_REQUEST_STATUS_MERGEABLE pr.Status = PULL_REQUEST_STATUS_MERGEABLE
} }
@@ -366,12 +428,35 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str
return fmt.Errorf("Commit: %v", err) return fmt.Errorf("Commit: %v", err)
} }
if err = NotifyWatchers(act); err != nil { if err = NotifyWatchers(&Action{
ActUserID: pull.Poster.ID,
ActUserName: pull.Poster.Name,
ActEmail: pull.Poster.Email,
OpType: ACTION_CREATE_PULL_REQUEST,
Content: fmt.Sprintf("%d|%s", pull.Index, pull.Title),
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,
RepoName: repo.Name,
IsPrivate: repo.IsPrivate,
}); err != nil {
log.Error(4, "NotifyWatchers: %v", err) log.Error(4, "NotifyWatchers: %v", err)
} else if err = pull.MailParticipants(); err != nil { } else if err = pull.MailParticipants(); err != nil {
log.Error(4, "MailParticipants: %v", err) log.Error(4, "MailParticipants: %v", err)
} }
pr.Issue = pull
pull.PullRequest = pr
if err = PrepareWebhooks(repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{
Action: api.HOOK_ISSUE_OPENED,
Index: pull.Index,
PullRequest: pr.APIFormat(),
Repository: repo.APIFormat(nil),
Sender: pull.Poster.APIFormat(),
}); err != nil {
log.Error(4, "PrepareWebhooks: %v", err)
}
go HookQueue.Add(repo.ID)
return nil return nil
} }
@@ -395,9 +480,9 @@ func GetUnmergedPullRequest(headRepoID, baseRepoID int64, headBranch, baseBranch
// by given head information (repo and branch). // by given head information (repo and branch).
func GetUnmergedPullRequestsByHeadInfo(repoID int64, branch string) ([]*PullRequest, error) { func GetUnmergedPullRequestsByHeadInfo(repoID int64, branch string) ([]*PullRequest, error) {
prs := make([]*PullRequest, 0, 2) prs := make([]*PullRequest, 0, 2)
return prs, x.Where("head_repo_id=? AND head_branch=? AND has_merged=? AND issue.is_closed=?", return prs, x.Where("head_repo_id = ? AND head_branch = ? AND has_merged = ? AND issue.is_closed = ?",
repoID, branch, false, false). repoID, branch, false, false).
Join("INNER", "issue", "issue.id=pull_request.issue_id").Find(&prs) Join("INNER", "issue", "issue.id = pull_request.issue_id").Find(&prs)
} }
// GetUnmergedPullRequestsByBaseInfo returnss all pull requests that are open and has not been merged // GetUnmergedPullRequestsByBaseInfo returnss all pull requests that are open and has not been merged
@@ -409,30 +494,38 @@ func GetUnmergedPullRequestsByBaseInfo(repoID int64, branch string) ([]*PullRequ
Join("INNER", "issue", "issue.id=pull_request.issue_id").Find(&prs) Join("INNER", "issue", "issue.id=pull_request.issue_id").Find(&prs)
} }
// GetPullRequestByID returns a pull request by given ID. func getPullRequestByID(e Engine, id int64) (*PullRequest, error) {
func GetPullRequestByID(id int64) (*PullRequest, error) {
pr := new(PullRequest) pr := new(PullRequest)
has, err := x.Id(id).Get(pr) has, err := e.Id(id).Get(pr)
if err != nil { if err != nil {
return nil, err return nil, err
} else if !has { } else if !has {
return nil, ErrPullRequestNotExist{id, 0, 0, 0, "", ""} return nil, ErrPullRequestNotExist{id, 0, 0, 0, "", ""}
} }
return pr, nil return pr, pr.loadAttributes(e)
} }
// GetPullRequestByIssueID returns pull request by given issue ID. // GetPullRequestByID returns a pull request by given ID.
func GetPullRequestByIssueID(issueID int64) (*PullRequest, error) { func GetPullRequestByID(id int64) (*PullRequest, error) {
return getPullRequestByID(x, id)
}
func getPullRequestByIssueID(e Engine, issueID int64) (*PullRequest, error) {
pr := &PullRequest{ pr := &PullRequest{
IssueID: issueID, IssueID: issueID,
} }
has, err := x.Get(pr) has, err := e.Get(pr)
if err != nil { if err != nil {
return nil, err return nil, err
} else if !has { } else if !has {
return nil, ErrPullRequestNotExist{0, issueID, 0, 0, "", ""} return nil, ErrPullRequestNotExist{0, issueID, 0, 0, "", ""}
} }
return pr, nil return pr, pr.loadAttributes(e)
}
// GetPullRequestByIssueID returns pull request by given issue ID.
func GetPullRequestByIssueID(issueID int64) (*PullRequest, error) {
return getPullRequestByIssueID(x, issueID)
} }
// Update updates all fields of pull request. // Update updates all fields of pull request.
@@ -536,6 +629,37 @@ func (pr *PullRequest) AddToTaskQueue() {
}) })
} }
type PullRequestList []*PullRequest
func (prs PullRequestList) loadAttributes(e Engine) error {
if len(prs) == 0 {
return nil
}
// Load issues.
issueIDs := make([]int64, 0, len(prs))
for i := range prs {
issueIDs = append(issueIDs, prs[i].IssueID)
}
issues := make([]*Issue, 0, len(issueIDs))
if err := e.Where("id > 0").In("id", issueIDs).Find(&issues); err != nil {
return fmt.Errorf("find issues: %v", err)
}
set := make(map[int64]*Issue)
for i := range issues {
set[issues[i].ID] = issues[i]
}
for i := range prs {
prs[i].Issue = set[prs[i].IssueID]
}
return nil
}
func (prs PullRequestList) LoadAttributes() error {
return prs.loadAttributes(x)
}
func addHeadRepoTasks(prs []*PullRequest) { func addHeadRepoTasks(prs []*PullRequest) {
for _, pr := range prs { for _, pr := range prs {
log.Trace("addHeadRepoTasks[%d]: composing new test task", pr.ID) log.Trace("addHeadRepoTasks[%d]: composing new test task", pr.ID)
@@ -553,19 +677,47 @@ func addHeadRepoTasks(prs []*PullRequest) {
// AddTestPullRequestTask adds new test tasks by given head/base repository and head/base branch, // AddTestPullRequestTask adds new test tasks by given head/base repository and head/base branch,
// and generate new patch for testing as needed. // and generate new patch for testing as needed.
func AddTestPullRequestTask(repoID int64, branch string) { func AddTestPullRequestTask(doer *User, repoID int64, branch string, isSync bool) {
log.Trace("AddTestPullRequestTask[head_repo_id: %d, head_branch: %s]: finding pull requests", repoID, branch) log.Trace("AddTestPullRequestTask [head_repo_id: %d, head_branch: %s]: finding pull requests", repoID, branch)
prs, err := GetUnmergedPullRequestsByHeadInfo(repoID, branch) prs, err := GetUnmergedPullRequestsByHeadInfo(repoID, branch)
if err != nil { if err != nil {
log.Error(4, "Find pull requests[head_repo_id: %d, head_branch: %s]: %v", repoID, branch, err) log.Error(4, "Find pull requests [head_repo_id: %d, head_branch: %s]: %v", repoID, branch, err)
return return
} }
if isSync {
if err = PullRequestList(prs).LoadAttributes(); err != nil {
log.Error(4, "PullRequestList.LoadAttributes: %v", err)
}
if err == nil {
for _, pr := range prs {
pr.Issue.PullRequest = pr
if err = pr.Issue.LoadAttributes(); err != nil {
log.Error(4, "LoadAttributes: %v", err)
continue
}
if err = PrepareWebhooks(pr.Issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{
Action: api.HOOK_ISSUE_SYNCHRONIZED,
Index: pr.Issue.Index,
PullRequest: pr.Issue.PullRequest.APIFormat(),
Repository: pr.Issue.Repo.APIFormat(nil),
Sender: doer.APIFormat(),
}); err != nil {
log.Error(4, "PrepareWebhooks [pull_id: %v]: %v", pr.ID, err)
continue
}
go HookQueue.Add(pr.Issue.Repo.ID)
}
}
}
addHeadRepoTasks(prs) addHeadRepoTasks(prs)
log.Trace("AddTestPullRequestTask[base_repo_id: %d, base_branch: %s]: finding pull requests", repoID, branch) log.Trace("AddTestPullRequestTask [base_repo_id: %d, base_branch: %s]: finding pull requests", repoID, branch)
prs, err = GetUnmergedPullRequestsByBaseInfo(repoID, branch) prs, err = GetUnmergedPullRequestsByBaseInfo(repoID, branch)
if err != nil { if err != nil {
log.Error(4, "Find pull requests[base_repo_id: %d, base_branch: %s]: %v", repoID, branch, err) log.Error(4, "Find pull requests [base_repo_id: %d, base_branch: %s]: %v", repoID, branch, err)
return return
} }
for _, pr := range prs { for _, pr := range prs {
+42 -12
View File
@@ -216,6 +216,48 @@ func (repo *Repository) AfterSet(colName string, _ xorm.Cell) {
} }
} }
// MustOwner always returns a valid *User object to avoid
// conceptually impossible error handling.
// It creates a fake object that contains error deftail
// when error occurs.
func (repo *Repository) MustOwner() *User {
return repo.mustOwner(x)
}
func (repo *Repository) FullName() string {
return repo.MustOwner().Name + "/" + repo.Name
}
func (repo *Repository) FullLink() string {
return setting.AppUrl + repo.FullName()
}
// Arguments that are allowed to be nil: permission
func (repo *Repository) APIFormat(permission *api.Permission) *api.Repository {
cloneLink := repo.CloneLink()
return &api.Repository{
ID: repo.ID,
Owner: repo.Owner.APIFormat(),
Name: repo.Name,
FullName: repo.FullName(),
Description: repo.Description,
Private: repo.IsPrivate,
Fork: repo.IsFork,
HTMLURL: repo.FullLink(),
SSHURL: cloneLink.SSH,
CloneURL: cloneLink.HTTPS,
Website: repo.Website,
Stars: repo.NumStars,
Forks: repo.NumForks,
Watchers: repo.NumWatches,
OpenIssues: repo.NumOpenIssues,
DefaultBranch: repo.DefaultBranch,
Created: repo.Created,
Updated: repo.Updated,
Permissions: permission,
}
}
func (repo *Repository) getOwner(e Engine) (err error) { func (repo *Repository) getOwner(e Engine) (err error) {
if repo.Owner != nil { if repo.Owner != nil {
return nil return nil
@@ -240,14 +282,6 @@ func (repo *Repository) mustOwner(e Engine) *User {
return repo.Owner return repo.Owner
} }
// MustOwner always returns a valid *User object to avoid
// conceptually impossible error handling.
// It creates a fake object that contains error deftail
// when error occurs.
func (repo *Repository) MustOwner() *User {
return repo.mustOwner(x)
}
// ComposeMetas composes a map of metas for rendering external issue tracker URL. // ComposeMetas composes a map of metas for rendering external issue tracker URL.
func (repo *Repository) ComposeMetas() map[string]string { func (repo *Repository) ComposeMetas() map[string]string {
if !repo.EnableExternalTracker { if !repo.EnableExternalTracker {
@@ -357,10 +391,6 @@ func (repo *Repository) ComposeCompareURL(oldCommitID, newCommitID string) strin
return fmt.Sprintf("%s/%s/compare/%s...%s", repo.MustOwner().Name, repo.Name, oldCommitID, newCommitID) return fmt.Sprintf("%s/%s/compare/%s...%s", repo.MustOwner().Name, repo.Name, oldCommitID, newCommitID)
} }
func (repo *Repository) FullLink() string {
return setting.AppUrl + repo.MustOwner().Name + "/" + repo.Name
}
func (repo *Repository) HasAccess(u *User) bool { func (repo *Repository) HasAccess(u *User) bool {
has, _ := HasAccess(u, repo, ACCESS_MODE_READ) has, _ := HasAccess(u, repo, ACCESS_MODE_READ)
return has return has
+15 -4
View File
@@ -25,6 +25,7 @@ import (
"github.com/nfnt/resize" "github.com/nfnt/resize"
"github.com/gogits/git-module" "github.com/gogits/git-module"
api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/modules/avatar" "github.com/gogits/gogs/modules/avatar"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
@@ -130,6 +131,16 @@ func (u *User) AfterSet(colName string, _ xorm.Cell) {
} }
} }
func (u *User) APIFormat() *api.User {
return &api.User{
ID: u.ID,
UserName: u.Name,
FullName: u.FullName,
Email: u.Email,
AvatarUrl: u.AvatarLink(),
}
}
// returns true if user login type is LOGIN_PLAIN. // returns true if user login type is LOGIN_PLAIN.
func (u *User) IsLocal() bool { func (u *User) IsLocal() bool {
return u.LoginType <= LOGIN_PLAIN return u.LoginType <= LOGIN_PLAIN
@@ -468,12 +479,12 @@ func GetUserSalt() string {
return base.GetRandomString(10) return base.GetRandomString(10)
} }
// NewFakeUser creates and returns a fake user for someone has deleted his/her account. // NewGhostUser creates and returns a fake user for someone has deleted his/her account.
func NewFakeUser() *User { func NewGhostUser() *User {
return &User{ return &User{
ID: -1, ID: -1,
Name: "Someone", Name: "Ghost",
LowerName: "someone", LowerName: "ghost",
} }
} }
+18 -10
View File
@@ -58,8 +58,9 @@ func IsValidHookContentType(name string) bool {
} }
type HookEvents struct { type HookEvents struct {
Create bool `json:"create"` Create bool `json:"create"`
Push bool `json:"push"` Push bool `json:"push"`
PullRequest bool `json:"pull_request"`
} }
// HookEvent represents events that will delivery hook. // HookEvent represents events that will delivery hook.
@@ -157,6 +158,12 @@ func (w *Webhook) HasPushEvent() bool {
(w.ChooseEvents && w.HookEvents.Push) (w.ChooseEvents && w.HookEvents.Push)
} }
// HasPullRequestEvent returns true if hook enabled pull request event.
func (w *Webhook) HasPullRequestEvent() bool {
return w.SendEverything ||
(w.ChooseEvents && w.HookEvents.PullRequest)
}
func (w *Webhook) EventsArray() []string { func (w *Webhook) EventsArray() []string {
events := make([]string, 0, 2) events := make([]string, 0, 2)
if w.HasCreateEvent() { if w.HasCreateEvent() {
@@ -309,8 +316,9 @@ func IsValidHookTaskType(name string) bool {
type HookEventType string type HookEventType string
const ( const (
HOOK_EVENT_CREATE HookEventType = "create" HOOK_EVENT_CREATE HookEventType = "create"
HOOK_EVENT_PUSH HookEventType = "push" HOOK_EVENT_PUSH HookEventType = "push"
HOOK_EVENT_PULL_REQUEST HookEventType = "pull_request"
) )
// HookRequest represents hook task request information. // HookRequest represents hook task request information.
@@ -422,17 +430,13 @@ func UpdateHookTask(t *HookTask) error {
// PrepareWebhooks adds new webhooks to task queue for given payload. // PrepareWebhooks adds new webhooks to task queue for given payload.
func PrepareWebhooks(repo *Repository, event HookEventType, p api.Payloader) error { func PrepareWebhooks(repo *Repository, event HookEventType, p api.Payloader) error {
if err := repo.GetOwner(); err != nil {
return fmt.Errorf("GetOwner: %v", err)
}
ws, err := GetActiveWebhooksByRepoID(repo.ID) ws, err := GetActiveWebhooksByRepoID(repo.ID)
if err != nil { if err != nil {
return fmt.Errorf("GetActiveWebhooksByRepoID: %v", err) return fmt.Errorf("GetActiveWebhooksByRepoID: %v", err)
} }
// check if repo belongs to org and append additional webhooks // check if repo belongs to org and append additional webhooks
if repo.Owner.IsOrganization() { if repo.MustOwner().IsOrganization() {
// get hooks for org // get hooks for org
orgws, err := GetActiveWebhooksByOrgID(repo.OwnerID) orgws, err := GetActiveWebhooksByOrgID(repo.OwnerID)
if err != nil { if err != nil {
@@ -456,6 +460,10 @@ func PrepareWebhooks(repo *Repository, event HookEventType, p api.Payloader) err
if !w.HasPushEvent() { if !w.HasPushEvent() {
continue continue
} }
case HOOK_EVENT_PULL_REQUEST:
if !w.HasPullRequestEvent() {
continue
}
} }
// Use separate objects so modifcations won't be made on payload on non-Gogs type hooks. // Use separate objects so modifcations won't be made on payload on non-Gogs type hooks.
@@ -477,7 +485,7 @@ func PrepareWebhooks(repo *Repository, event HookEventType, p api.Payloader) err
URL: w.URL, URL: w.URL,
Payloader: payloader, Payloader: payloader,
ContentType: w.ContentType, ContentType: w.ContentType,
EventType: HOOK_EVENT_PUSH, EventType: event,
IsSSL: w.IsSSL, IsSSL: w.IsSSL,
}); err != nil { }); err != nil {
return fmt.Errorf("CreateHookTask: %v", err) return fmt.Errorf("CreateHookTask: %v", err)
+74 -16
View File
@@ -12,6 +12,8 @@ import (
"github.com/gogits/git-module" "github.com/gogits/git-module"
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/modules/setting"
) )
type SlackMeta struct { type SlackMeta struct {
@@ -34,6 +36,7 @@ type SlackPayload struct {
type SlackAttachment struct { type SlackAttachment struct {
Fallback string `json:"fallback"` Fallback string `json:"fallback"`
Color string `json:"color"` Color string `json:"color"`
Title string `json:"title"`
Text string `json:"text"` Text string `json:"text"`
} }
@@ -49,13 +52,20 @@ func (p *SlackPayload) JSONPayload() ([]byte, error) {
// see: https://api.slack.com/docs/formatting // see: https://api.slack.com/docs/formatting
func SlackTextFormatter(s string) string { func SlackTextFormatter(s string) string {
// take only first line of commit
first := strings.Split(s, "\n")[0]
// replace & < > // replace & < >
first = strings.Replace(first, "&", "&amp;", -1) s = strings.Replace(s, "&", "&amp;", -1)
first = strings.Replace(first, "<", "&lt;", -1) s = strings.Replace(s, "<", "&lt;", -1)
first = strings.Replace(first, ">", "&gt;", -1) s = strings.Replace(s, ">", "&gt;", -1)
return first return s
}
func SlackShortTextFormatter(s string) string {
s = strings.Split(s, "\n")[0]
// replace & < >
s = strings.Replace(s, "&", "&amp;", -1)
s = strings.Replace(s, "<", "&lt;", -1)
s = strings.Replace(s, ">", "&gt;", -1)
return s
} }
func SlackLinkFormatter(url string, text string) string { func SlackLinkFormatter(url string, text string) string {
@@ -104,24 +114,70 @@ func getSlackPushPayload(p *api.PushPayload, slack *SlackMeta) (*SlackPayload, e
var attachmentText string var attachmentText string
// for each commit, generate attachment text // for each commit, generate attachment text
for i, commit := range p.Commits { for i, commit := range p.Commits {
attachmentText += fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.URL, commit.ID[:7]), SlackTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name)) attachmentText += fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.URL, commit.ID[:7]), SlackShortTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name))
// add linebreak to each commit but the last // add linebreak to each commit but the last
if i < len(p.Commits)-1 { if i < len(p.Commits)-1 {
attachmentText += "\n" attachmentText += "\n"
} }
} }
slackAttachments := []SlackAttachment{{ return &SlackPayload{
Color: slack.Color, Channel: slack.Channel,
Text: attachmentText, Text: text,
}} Username: slack.Username,
IconURL: slack.IconURL,
Attachments: []SlackAttachment{{
Color: slack.Color,
Text: attachmentText,
}},
}, nil
}
func getSlackPullRequestPayload(p *api.PullRequestPayload, slack *SlackMeta) (*SlackPayload, error) {
senderLink := SlackLinkFormatter(setting.AppUrl+p.Sender.UserName, p.Sender.UserName)
titleLink := SlackLinkFormatter(fmt.Sprintf("%s/%d", setting.AppUrl+p.Repository.FullName+"/pulls", p.Index),
fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title))
var text, title, attachmentText string
switch p.Action {
case api.HOOK_ISSUE_OPENED:
text = fmt.Sprintf("[%s] Pull request submitted by %s", p.Repository.FullName, senderLink)
title = titleLink
attachmentText = SlackTextFormatter(p.PullRequest.Body)
case api.HOOK_ISSUE_CLOSED:
if p.PullRequest.HasMerged {
text = fmt.Sprintf("[%s] Pull request merged: %s by %s", p.Repository.FullName, titleLink, senderLink)
} else {
text = fmt.Sprintf("[%s] Pull request closed: %s by %s", p.Repository.FullName, titleLink, senderLink)
}
case api.HOOK_ISSUE_REOPENED:
text = fmt.Sprintf("[%s] Pull request re-opened: %s by %s", p.Repository.FullName, titleLink, senderLink)
case api.HOOK_ISSUE_EDITED:
text = fmt.Sprintf("[%s] Pull request edited: %s by %s", p.Repository.FullName, titleLink, senderLink)
attachmentText = SlackTextFormatter(p.PullRequest.Body)
case api.HOOK_ISSUE_ASSIGNED:
text = fmt.Sprintf("[%s] Pull request assigned to %s: %s by %s", p.Repository.FullName,
SlackLinkFormatter(setting.AppUrl+p.PullRequest.Assignee.UserName, p.PullRequest.Assignee.UserName),
titleLink, senderLink)
case api.HOOK_ISSUE_UNASSIGNED:
text = fmt.Sprintf("[%s] Pull request unassigned: %s by %s", p.Repository.FullName, titleLink, senderLink)
case api.HOOK_ISSUE_LABEL_UPDATED:
text = fmt.Sprintf("[%s] Pull request labels updated: %s by %s", p.Repository.FullName, titleLink, senderLink)
case api.HOOK_ISSUE_LABEL_CLEARED:
text = fmt.Sprintf("[%s] Pull request labels cleared: %s by %s", p.Repository.FullName, titleLink, senderLink)
case api.HOOK_ISSUE_SYNCHRONIZED:
text = fmt.Sprintf("[%s] Pull request synchronized: %s by %s", p.Repository.FullName, titleLink, senderLink)
}
return &SlackPayload{ return &SlackPayload{
Channel: slack.Channel, Channel: slack.Channel,
Text: text, Text: text,
Username: slack.Username, Username: slack.Username,
IconURL: slack.IconURL, IconURL: slack.IconURL,
Attachments: slackAttachments, Attachments: []SlackAttachment{{
Color: slack.Color,
Title: title,
Text: attachmentText,
}},
}, nil }, nil
} }
@@ -138,6 +194,8 @@ func GetSlackPayload(p api.Payloader, event HookEventType, meta string) (*SlackP
return getSlackCreatePayload(p.(*api.CreatePayload), slack) return getSlackCreatePayload(p.(*api.CreatePayload), slack)
case HOOK_EVENT_PUSH: case HOOK_EVENT_PUSH:
return getSlackPushPayload(p.(*api.PushPayload), slack) return getSlackPushPayload(p.(*api.PushPayload), slack)
case HOOK_EVENT_PULL_REQUEST:
return getSlackPullRequestPayload(p.(*api.PullRequestPayload), slack)
} }
return s, nil return s, nil
+5 -4
View File
@@ -113,10 +113,11 @@ func (f *RepoSettingForm) Validate(ctx *macaron.Context, errs binding.Errors) bi
// \/ \/ \/ \/ \/ \/ // \/ \/ \/ \/ \/ \/
type WebhookForm struct { type WebhookForm struct {
Events string Events string
Create bool Create bool
Push bool Push bool
Active bool PullRequest bool
Active bool
} }
func (f WebhookForm) PushOnly() bool { func (f WebhookForm) PushOnly() bool {
+3 -3
View File
@@ -301,7 +301,7 @@ func confAppIni() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "conf/app.ini", size: 12337, mode: os.FileMode(420), modTime: time.Unix(1470952001, 0)} info := bindataFileInfo{name: "conf/app.ini", size: 12337, mode: os.FileMode(420), modTime: time.Unix(1470994320, 0)}
a := &asset{bytes: bytes, info: info} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }
@@ -4346,7 +4346,7 @@ func confLocaleLocale_deDeIni() (*asset, error) {
return a, nil return a, nil
} }
var _confLocaleLocale_enUsIni = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xac\xbd\xfb\x92\xdb\x46\x92\x2f\xfc\x3f\x9e\x02\xd6\x84\x42\x52\x84\x44\x87\xc7\xfb\x5d\xc2\xe1\xcb\xd7\x6a\x59\x97\x5d\xb5\xd4\xab\x6e\x7b\xbe\x39\x0e\x05\x0d\x92\x68\x12\x2b\x12\xe0\x00\xa0\x5a\x3d\x13\xf3\x06\xe7\x01\xce\xf3\x9d\x27\x39\x99\xbf\xcc\xac\xca\x02\xc0\x6e\xc9\xb3\xfa\x43\x0d\x56\x65\xdd\xb3\xb2\xf2\x56\x59\xc5\x7e\x3f\x5f\x95\xdd\x32\xff\x21\x3f\xc9\xf7\x45\x55\x6f\xcb\xae\xcb\xbb\x72\x7b\xf5\x64\xd3\x74\x7d\xb9\xca\x5f\x54\x3d\xfd\x6e\x3f\x56\xcb\x32\xcb\x36\xcd\xae\x24\xd0\x97\xf4\x27\x5b\x15\xdd\x66\xd1\x14\xed\x8a\x12\x9e\xd9\x77\x56\x7e\xda\x6f\x9b\x96\x81\x7e\x96\xaf\x6c\x53\x6e\xf7\x5c\x86\xfe\x64\x5d\xb5\xae\xe7\x55\x4d\x3f\x2f\xe8\x2b\x7f\x55\x4b\x4a\x73\xe8\x2d\xe9\xed\xa1\x97\xb4\xc3\xde\x92\x7e\xd9\x67\x6d\xb9\xae\xa8\x37\x2d\x25\xbd\xd3\xcf\xec\xba\x5c\x74\x55\xcf\x2d\xfd\x45\xbe\xb2\x8f\x65\xdb\x55\x0d\xd7\xfe\xab\x7c\x65\xfb\x62\xcd\x00\xe7\xf4\x27\xeb\xcb\xdd\x7e\x5b\xa0\xc0\xa5\x7e\x66\xdb\xa2\x5e\x1f\x04\xe6\xb5\x7e\x66\xcb\xb6\xa4\xac\x79\x5d\x5e\x53\xea\x29\x7e\xcc\x66\xb3\xec\x40\x93\x30\xdf\xb7\xcd\x55\xb5\x2d\xe7\x45\xbd\x9a\xef\x64\x98\xbf\x50\x7a\xae\xe9\x39\xa5\xe7\x9c\x8e\x21\x94\x2b\x1a\xea\xbc\xe8\x74\x1c\x34\x97\x34\xf2\xa2\xcb\x50\x55\x5d\xec\xac\x34\x7f\x66\xe5\xae\xa8\xb6\x3c\x6b\xfc\x97\xfa\xdd\x75\xd7\x0d\xa6\xf6\x5c\x3f\x69\x0e\xe6\xfd\xcd\xbe\xc4\x14\x3c\xb9\xa4\xaf\x6c\x59\xec\xfb\xe5\xa6\xe0\x6e\xca\x57\x46\x40\xfb\x86\xe6\xa2\x69\x6f\x00\x67\x3f\xb2\xa6\x5d\x17\x75\xf5\xf7\xa2\x97\xf9\x79\xeb\x7e\x66\xbb\xaa\x6d\x1b\x9e\xda\x33\x7c\x64\x34\xf2\x39\xd7\x43\x29\x6f\x68\x12\x5c\x2d\x9c\xb3\xab\xd6\xad\xcc\x22\x67\x9e\xe1\x17\xd7\x22\x79\x5a\x93\x64\x85\xda\xae\x9a\xf6\x83\xa6\x3e\xe7\xcf\x41\x95\xd4\x39\xcd\x4d\xfb\x55\xd4\xb4\x1e\x9a\x7b\x86\x1f\x09\x40\x97\x15\xab\x1d\xcd\xf0\xbe\xa8\x4b\x9e\xba\x13\xfe\x45\xf3\x45\xbf\xb2\x62\xb9\x6c\x0e\x75\x3f\xef\xca\xbe\xaf\xea\x35\xaf\xc1\x89\x24\xe5\x17\x9a\x94\xb9\xbc\x90\x76\xd3\x1c\xc2\x2a\x53\xfa\x5f\xe9\x67\x7e\x2e\x3f\x25\xcf\x15\x42\x66\x28\x49\x4d\xf6\xd5\xc7\xaa\xaf\x4a\x69\xcc\x7e\x64\xfb\xc3\x76\x4b\xf3\xf9\xb7\x43\xd9\xf5\x9c\x75\x4e\xbf\x69\x06\xe4\x77\x56\x75\xdd\x01\x25\x5e\xe1\x23\xa3\x45\xad\x97\x18\xce\x29\x3e\xb2\xec\xb7\xaa\xee\xfa\x62\xbb\x7d\x9f\xe9\x07\x03\xcb\x97\xcc\x53\x5f\xf5\xe8\xac\x26\xe6\x17\x7d\xb9\xef\x78\xa2\xf3\xe7\x55\xdb\xf5\x4f\xfa\x8a\x50\xed\xdd\xa1\xce\x56\xcd\xf2\x03\x21\x31\x6f\x48\x6c\xa5\x57\x57\x39\x8d\xe9\x01\xa1\x71\x7b\xa8\x6b\x1a\x45\xfe\xa2\xa1\x91\x51\x33\xd5\xaa\xcc\x9f\x01\xfa\x71\xbe\xdf\x96\x45\x47\x20\x65\xb1\xca\xbf\x2f\xf2\xbe\x68\xd7\x65\xff\xc3\xbd\xf9\x82\x36\xcf\x87\x7b\xf9\xa6\x2d\xaf\x7e\xb8\x77\xbf\xbb\xf7\xe3\x8b\x03\x15\xdb\x56\x75\xd9\x7d\xff\x75\xf1\x63\xbe\x2c\x28\x87\xc6\x7a\x93\x2f\xca\x2b\xde\x2b\xd4\x56\x4e\x48\x5a\xaf\x79\x9f\xdc\xf4\x1b\x6e\x90\x16\x8c\x3e\xba\x9c\x37\xea\x57\x19\xcf\x12\x6d\xe4\xf9\x6a\x61\x44\x09\x1d\x42\x72\x4b\xb3\x74\x76\x73\xf1\x9f\xaf\x1f\xe7\xe7\x44\x99\xd6\x6d\x89\x6f\xfa\x8f\x4a\x7c\x9b\xd3\x68\x2f\xab\x67\x4f\x67\x19\x95\xb5\x09\x79\x56\xf4\xc5\x82\xfb\x1e\x16\x89\x33\x65\x0f\x85\x3c\xec\x24\xa6\x75\xa0\x6b\x5d\x8f\xdd\xa9\x3b\x73\x72\x1f\x52\x1d\xba\x79\x43\x1d\x6f\x78\x07\x53\x7a\x98\xd9\x73\x99\x33\xaa\x2a\x7f\xf5\xe6\xcd\xdb\x67\x4f\xf3\xb2\x5e\xd3\xcc\xe4\xd7\x55\xbf\xc9\x0f\xfd\xd5\xff\x3b\x5f\x97\x75\xd9\x16\xdb\xf9\xb2\xe2\x49\x69\x09\xaf\x72\x9a\x25\x19\xe2\x2c\xeb\xba\x2d\x11\x98\x15\xb7\x72\x71\xf1\x3a\x3f\xa3\x4f\xea\x0c\x95\xe5\x8e\xf4\x9b\xac\xfb\xdb\x96\x27\x2a\x34\x78\xb9\x29\x73\xe0\x2c\x80\x9a\xab\xe1\xbc\xe4\x2b\xed\xeb\x2c\xff\x7e\xd1\xfe\xe8\xfa\x57\x2c\xba\x66\x7b\xe8\xb5\xe4\xf5\xa6\xac\xb1\x50\x84\x4a\x6d\x4f\xd4\xca\x68\xff\x2c\x2b\xdb\x76\x4e\x74\xb3\xbf\xe1\xe5\xd1\xbe\x1c\x6b\x45\x2a\x23\x54\xae\x9b\x9e\x96\x3f\x47\x39\xa9\xa2\xaa\x3f\x16\xdb\x6a\x45\x8b\x14\x27\x32\x2d\x8b\xc4\x55\x43\xeb\xcd\xa5\x09\xa3\x9b\x6b\x4c\x11\x6d\x30\x22\xeb\xf9\xbd\xd9\x3d\xd0\xd9\x7b\x4f\xee\xcd\xb2\xba\x99\x0b\x11\x60\x8a\xbc\xaa\xba\x62\x41\xd4\x59\x4e\x8b\xd6\x88\xdd\x5f\x19\xef\xa4\x2b\x0a\x91\x27\x10\xbc\x26\x7c\x02\x81\xf0\x33\x52\x16\x44\xa6\x41\x4b\x94\x8a\xf8\xb1\x1b\xc9\x09\x78\x21\x54\x27\x24\x8c\xc6\x9c\xd9\x42\x1b\x56\x9e\xec\xf7\xdb\x6a\x29\x4d\xbf\x90\xbc\x88\xa0\x7c\x1e\xeb\xa4\x78\x38\x20\x98\xe5\x39\x34\xa3\x5e\x33\x55\xca\x13\xf2\x8e\xf2\x9b\x92\x76\xdc\xe6\xb0\x96\x33\x69\xdb\x1c\x56\x5f\xe1\x70\xb0\x95\x8b\x24\x38\x7f\xd7\x50\x87\x81\x55\x01\x20\x36\x71\x42\x04\x85\x59\x80\xb6\xdc\x35\x3d\x4f\x9c\x16\x63\x32\x77\x5d\x51\x26\x8d\xb4\x2b\x3e\xd2\xe1\xd6\x37\xb2\x95\x57\xb4\x55\x97\x5c\xf1\x2c\x23\xb2\x32\xd7\xed\x44\xf4\x47\xb6\x94\xa5\xa5\xb8\x0b\xa8\xdd\x81\x76\xe1\x86\x2a\xe3\x89\x67\x3e\x84\xaa\x9c\xea\x27\x86\x44\xf5\x80\x3a\xd0\x8e\x6f\xe8\xcc\xe4\x85\x7e\x86\x0f\xfd\xed\xeb\xa7\x5e\x15\x57\x57\xd4\xab\x8e\x76\xd3\xcb\x7c\xb9\x6d\x68\x2b\xfe\xf2\xee\x75\xc7\x1b\x6d\x33\xdf\x37\x2d\xf8\x0f\xca\x3a\xa7\xcf\x90\xe6\x26\x9a\x21\xea\xc3\x6e\x41\xbf\xae\x37\xd5\x72\x23\xd3\xce\x25\x78\x7f\x50\x2a\x35\x7Line truncated var _confLocaleLocale_enUsIni = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xac\xbd\xfb\x72\xdc\x46\x92\x2f\xfc\x3f\x9e\x02\xd6\x84\x42\x52\x04\xd5\x0e\x8f\xf7\xbb\x84\xc3\x97\x8f\xa2\xac\xcb\xae\x28\x71\x45\xda\xf3\xcd\x71\x28\xda\x60\x37\xd8\x8d\x55\x37\xd0\x03\xa0\x49\x71\x26\xe6\x0d\xce\x03\x9c\xe7\x3b\x4f\x72\x32\x7f\x99\x59\x95\x05\xa0\x49\xc9\xb3\xfa\x43\x44\x57\x65\xdd\xb3\xb2\xf2\x56\x59\xc5\x6e\x37\x5f\x96\xdd\x22\xff\x21\x3f\xce\x77\x45\x55\x6f\xca\xae\xcb\xbb\x72\x73\xf5\x74\xdd\x74\x7d\xb9\xcc\x5f\x56\x3d\xfd\x6e\xaf\xab\x45\x99\x65\xeb\x66\x5b\x12\xe8\x2b\xfa\x93\x2d\x8b\x6e\x7d\xd9\x14\xed\x92\x12\x9e\xdb\x77\x56\x7e\xda\x6d\x9a\x96\x81\x7e\x96\xaf\x6c\x5d\x6e\x76\x5c\x86\xfe\x64\x5d\xb5\xaa\xe7\x55\x4d\x3f\xcf\xe9\x2b\x7f\x5d\x4b\x4a\xb3\xef\x2d\xe9\xdd\xbe\x97\xb4\xfd\xce\x92\x7e\xd9\x65\x6d\xb9\xaa\xa8\x37\x2d\x25\xbd\xd7\xcf\xec\xa6\xbc\xec\xaa\x9e\x5b\xfa\x8b\x7c\x65\xd7\x65\xdb\x55\x0d\xd7\xfe\xab\x7c\x65\xbb\x62\xc5\x00\x67\xf4\x27\xeb\xcb\xed\x6e\x53\xa0\xc0\x85\x7e\x66\x9b\xa2\x5e\xed\x05\xe6\x8d\x7e\x66\x8b\xb6\xa4\xac\x79\x5d\xde\x50\xea\x09\x7e\xcc\x66\xb3\x6c\x4f\x93\x30\xdf\xb5\xcd\x55\xb5\x29\xe7\x45\xbd\x9c\x6f\x65\x98\xbf\x50\x7a\xae\xe9\x39\xa5\xe7\x9c\x8e\x21\x94\x4b\x1a\xea\xbc\xe8\x74\x1c\x34\x97\x34\xf2\xa2\xcb\x50\x55\x5d\x6c\xad\x34\x7f\x66\xe5\xb6\xa8\x36\x3c\x6b\xfc\x97\xfa\xdd\x75\x37\x0d\xa6\xf6\x4c\x3f\x69\x0e\xe6\xfd\xed\xae\xc4\x14\x3c\xbd\xa0\xaf\x6c\x51\xec\xfa\xc5\xba\xe0\x6e\xca\x57\x46\x40\xbb\x86\xe6\xa2\x69\x6f\x01\x67\x3f\xb2\xa6\x5d\x15\x75\xf5\xf7\xa2\x97\xf9\x79\xe7\x7e\x66\xdb\xaa\x6d\x1b\x9e\xda\x53\x7c\x64\x34\xf2\x39\xd7\x43\x29\x6f\x69\x12\x5c\x2d\x9c\xb3\xad\x56\xad\xcc\x22\x67\x9e\xe2\x17\xd7\x22\x79\x5a\x93\x64\x85\xda\xae\x9a\xf6\xa3\xa6\xbe\xe0\xcf\x41\x95\xd4\x39\xcd\x4d\xfb\x55\xd4\xb4\x1e\x9a\x7b\x8a\x1f\x09\x40\x97\x15\xcb\x2d\xcd\xf0\xae\xa8\x4b\x9e\xba\x63\xfe\x45\xf3\x45\xbf\xb2\x62\xb1\x68\xf6\x75\x3f\xef\xca\xbe\xaf\xea\x15\xaf\xc1\xb1\x24\xe5\xe7\x9a\x94\xb9\xbc\x90\x76\xdb\xec\xc3\x2a\x53\xfa\x5f\xe9\x67\x7e\x26\x3f\x25\xcf\x15\x42\x66\x28\x49\x4d\xf6\xd5\x75\xd5\x57\xa5\x34\x66\x3f\xb2\xdd\x7e\xb3\xa1\xf9\xfc\xdb\xbe\xec\x7a\xce\x3a\xa3\xdf\x34\x03\xf2\x3b\xab\xba\x6e\x8f\x12\xaf\xf1\x91\xd1\xa2\xd6\x0b\x0c\xe7\x04\x1f\x59\xf6\x5b\x55\x77\x7d\xb1\xd9\x7c\xc8\xf4\x83\x81\xe5\x4b\xe6\xa9\xaf\x7a\x74\x56\x13\xf3\xf3\xbe\xdc\x75\x3c\xd1\xf9\x8b\xaa\xed\xfa\xa7\x7d\x45\xa8\xf6\x7e\x5f\x67\xcb\x66\xf1\x91\x90\x98\x37\x24\xb6\xd2\xeb\xab\x9c\xc6\xf4\x88\xd0\xb8\xdd\xd7\x35\x8d\x22\x7f\xd9\xd0\xc8\xa8\x99\x6a\x59\xe6\xcf\x01\x7d\x94\xef\x36\x65\xd1\x11\x48\x59\x2c\xf3\xef\x8b\xbc\x2f\xda\x55\xd9\xff\xf0\x60\x7e\x49\x9b\xe7\xe3\x83\x7c\xdd\x96\x57\x3f\x3c\x78\xd8\x3d\xf8\xf1\xe5\x9e\x8a\x6d\xaa\xba\xec\xbe\xff\xba\xf8\x31\x5f\x14\x94\x43\x63\xbd\xcd\x2f\xcb\x2b\xde\x2b\xd4\x56\x4e\x48\x5a\xaf\x78\x9f\xdc\xf6\x6b\x6e\x90\x16\x8c\x3e\xba\x9c\x37\xea\x57\x19\xcf\x12\x6d\xe4\xf9\xf2\xd2\x88\x12\x3a\x84\xe4\x96\x66\xe9\xf4\xf6\xfc\x3f\xdf\x1c\xe5\x67\x44\x99\x56\x6d\x89\x6f\xfa\x8f\x4a\x7c\x9b\xd3\x68\x2f\xaa\xe7\xcf\x66\x19\x95\xb5\x09\x79\x5e\xf4\xc5\x25\xf7\x3d\x2c\x12\x67\xca\x1e\x0a\x79\xd8\x49\x4c\xeb\x40\xd7\xba\x1e\xbb\x53\x77\xe6\xe4\x3e\xa4\x3a\x74\xf3\x86\x3a\xde\xf2\x0e\xa6\xf4\x30\xb3\x67\x32\x67\x54\x55\xfe\xfa\xed\xdb\x77\xcf\x9f\xe5\x65\xbd\xa2\x99\xc9\x6f\xaa\x7e\x9d\xef\xfb\xab\xff\x77\xbe\x2a\xeb\xb2\x2d\x36\xf3\x45\xc5\x93\xd2\x12\x5e\xe5\x34\x4b\x32\xc4\x59\xd6\x75\x1b\x22\x30\x4b\x6e\xe5\xfc\xfc\x4d\x7e\x4a\x9f\xd4\x19\x2a\xcb\x1d\xe9\xd7\x59\xf7\xb7\x0d\x4f\x54\x68\xf0\x62\x5d\xe6\xc0\x59\x00\x35\x57\xc3\x79\xc9\x97\xda\xd7\x59\xfe\xfd\x65\xfb\xa3\xeb\x5f\x71\xd9\x35\x9b\x7d\xaf\x25\x6f\xd6\x65\x8d\x85\x22\x54\x6a\x7b\xa2\x56\x46\xfb\x67\x59\xd9\xb6\x73\xa2\x9b\xfd\x2d\x2f\x8f\xf6\xe5\x50\x2b\x52\x19\xa1\x72\xdd\xf4\xb4\xfc\x39\xca\x49\x15\x55\x7d\x5d\x6c\xaa\x25\x2d\x52\x9c\xc8\xb4\x2c\x12\x97\x0d\xad\x37\x97\x26\x8c\x6e\x6e\x30\x45\xb4\xc1\x88\xac\xe7\x0f\x66\x0f\x40\x67\x1f\x3c\x7d\x30\xcb\xea\x66\x2e\x44\x80\x29\xf2\xb2\xea\x8a\x4b\xa2\xce\x72\x5a\xb4\x46\xec\xfe\xca\x78\x27\x5d\x51\x88\x3c\x81\xe0\x35\xe1\x13\x08\x84\x9f\x91\xb2\x20\x32\x0d\x5a\xa2\x54\xc4\x8f\xdd\x48\x4e\xc0\x0b\xa1\x3a\x21\x61\x34\xe6\xcc\x16\xda\xb0\xf2\x78\xb7\xdb\x54\x0b\x69\xfa\xa5\xe4\x45\x04\xe5\xf3\x58\x27\xc5\xc3\x01\xc1\x2c\xcf\xa1\x19\xf5\x9a\xa9\x52\x9e\x90\x77\x94\x5f\x97\xb4\xe3\xd6\xfb\x95\x9c\x49\x9b\x66\xbf\xfc\x0a\x87\x83\xad\x5c\x24\xc1\xf9\xfb\x86\x3a\x0c\xac\x0a\x00\xb1\x89\x63\x22\x28\xcc\x02\xb4\xe5\xb6\xe9\x79\xe2\xb4\x18\x93\xb9\x9b\x8a\x32\x69\xa4\x5d\x71\x4d\x87\x5b\xdf\xc8\x56\x5e\xd2\x56\x5d\x70\xc5\xb3\x8c\xc8\xca\x5c\xb7\x13\xd1\x1f\xd9\x52\x96\x96\xe2\x2e\xa0\xb6\x7b\xda\x85\x6b\xaa\x8c\x27\x9e\xf9\x10\xaa\x72\xaa\x9f\x18\x12\xd5\x03\xea\x40\x3b\xbe\xa1\x33\x93\x17\xfa\x39\x3e\xf4\xb7\xaf\x9f\x7a\x55\x5c\x5d\x51\xaf\x3a\xda\x4d\xaf\xf2\xc5\xa6\xa1\xad\xf8\xcb\xfb\x37\x1d\x6f\xb4\xf5\x7c\xd7\xb4\xe0\x3f\x28\xeb\x8c\x3e\x43\x9a\x9b\x68\x86\xa8\xf7\xdb\x4b\xfa\x75\xb3\xae\x16\x6b\x99\x76\x2e\xc1\xfb\x83\x52\xa9\x8Line truncated
func confLocaleLocale_enUsIniBytes() ([]byte, error) { func confLocaleLocale_enUsIniBytes() ([]byte, error) {
return bindataRead( return bindataRead(
@@ -4361,7 +4361,7 @@ func confLocaleLocale_enUsIni() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "conf/locale/locale_en-US.ini", size: 52579, mode: os.FileMode(420), modTime: time.Unix(1470959628, 0)} info := bindataFileInfo{name: "conf/locale/locale_en-US.ini", size: 52773, mode: os.FileMode(420), modTime: time.Unix(1471166949, 0)}
a := &asset{bytes: bytes, info: info} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }
+8
View File
@@ -2064,6 +2064,14 @@ footer .ui.language .menu {
margin-left: 5px; margin-left: 5px;
margin-top: -3px; margin-top: -3px;
} }
.repository.settings.webhook .events .column {
padding-bottom: 0;
}
.repository.settings.webhook .events .help {
font-size: 13px;
margin-left: 26px;
padding-top: 0;
}
.user-cards .list { .user-cards .list {
padding: 0; padding: 0;
} }
+13
View File
@@ -1090,6 +1090,19 @@
} }
} }
} }
&.webhook {
.events {
.column {
padding-bottom: 0;
}
.help {
font-size: 13px;
margin-left: 26px;
padding-top: 0;
}
}
}
} }
} }
// End of .repository // End of .repository
+10 -15
View File
@@ -13,7 +13,6 @@ import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@@ -48,16 +47,16 @@ func ToRepository(owner *models.User, repo *models.Repository, permission api.Pe
Description: repo.Description, Description: repo.Description,
Private: repo.IsPrivate, Private: repo.IsPrivate,
Fork: repo.IsFork, Fork: repo.IsFork,
HtmlUrl: setting.AppUrl + owner.Name + "/" + repo.Name, HTMLURL: setting.AppUrl + owner.Name + "/" + repo.Name,
CloneUrl: cl.HTTPS, CloneURL: cl.HTTPS,
SshUrl: cl.SSH, SSHURL: cl.SSH,
OpenIssues: repo.NumOpenIssues, OpenIssues: repo.NumOpenIssues,
Stars: repo.NumStars, Stars: repo.NumStars,
Forks: repo.NumForks, Forks: repo.NumForks,
Watchers: repo.NumWatches, Watchers: repo.NumWatches,
Created: repo.Created, Created: repo.Created,
Updated: repo.Updated, Updated: repo.Updated,
Permissions: permission, Permissions: &permission,
} }
} }
@@ -183,7 +182,7 @@ func ToIssue(issue *models.Issue) *api.Issue {
ID: issue.ID, ID: issue.ID,
Index: issue.Index, Index: issue.Index,
State: issue.State(), State: issue.State(),
Title: issue.Name, Title: issue.Title,
Body: issue.Content, Body: issue.Content,
User: ToUser(issue.Poster), User: ToUser(issue.Poster),
Labels: apiLabels, Labels: apiLabels,
@@ -194,15 +193,11 @@ func ToIssue(issue *models.Issue) *api.Issue {
Updated: issue.Updated, Updated: issue.Updated,
} }
if issue.IsPull { if issue.IsPull {
if err := issue.GetPullRequest(); err != nil { apiIssue.PullRequest = &api.PullRequestMeta{
log.Error(4, "GetPullRequest", err) HasMerged: issue.PullRequest.HasMerged,
} else { }
apiIssue.PullRequest = &api.PullRequestMeta{ if issue.PullRequest.HasMerged {
HasMerged: issue.PullRequest.HasMerged, apiIssue.PullRequest.Merged = &issue.PullRequest.Merged
}
if issue.PullRequest.HasMerged {
apiIssue.PullRequest.Merged = &issue.PullRequest.Merged
}
} }
} }
+2 -2
View File
@@ -52,7 +52,7 @@ func GetIssue(ctx *context.APIContext) {
func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) { func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
issue := &models.Issue{ issue := &models.Issue{
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,
Name: form.Title, Title: form.Title,
PosterID: ctx.User.ID, PosterID: ctx.User.ID,
Poster: ctx.User, Poster: ctx.User,
Content: form.Body, Content: form.Body,
@@ -115,7 +115,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
} }
if len(form.Title) > 0 { if len(form.Title) > 0 {
issue.Name = form.Title issue.Title = form.Title
} }
if form.Body != nil { if form.Body != nil {
issue.Content = *form.Body issue.Content = *form.Body
+2 -2
View File
@@ -52,7 +52,7 @@ func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
return return
} }
if err = issue.AddLabels(labels); err != nil { if err = issue.AddLabels(ctx.User, labels); err != nil {
ctx.Error(500, "AddLabels", err) ctx.Error(500, "AddLabels", err)
return return
} }
@@ -160,7 +160,7 @@ func ClearIssueLabels(ctx *context.APIContext) {
return return
} }
if err := issue.ClearLabels(); err != nil { if err := issue.ClearLabels(ctx.User); err != nil {
ctx.Error(500, "ClearLabels", err) ctx.Error(500, "ClearLabels", err)
return return
} }
+1 -1
View File
@@ -206,7 +206,7 @@ func HTTP(ctx *context.Context) {
RepoName: reponame, RepoName: reponame,
}); err == nil { }); err == nil {
go models.HookQueue.Add(repo.ID) go models.HookQueue.Add(repo.ID)
go models.AddTestPullRequestTask(repo.ID, strings.TrimPrefix(refName, "refs/heads/")) go models.AddTestPullRequestTask(authUser, repo.ID, strings.TrimPrefix(refName, "refs/heads/"), true)
} }
} }
+17 -31
View File
@@ -424,7 +424,7 @@ func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
issue := &models.Issue{ issue := &models.Issue{
RepoID: repo.ID, RepoID: repo.ID,
Name: form.Title, Title: form.Title,
PosterID: ctx.User.ID, PosterID: ctx.User.ID,
Poster: ctx.User, Poster: ctx.User,
MilestoneID: milestoneID, MilestoneID: milestoneID,
@@ -500,7 +500,7 @@ func ViewIssue(ctx *context.Context) {
} }
return return
} }
ctx.Data["Title"] = issue.Name ctx.Data["Title"] = issue.Title
// Make sure type and URL matches. // Make sure type and URL matches.
if ctx.Params(":type") == "issues" && issue.IsPull { if ctx.Params(":type") == "issues" && issue.IsPull {
@@ -517,12 +517,6 @@ func ViewIssue(ctx *context.Context) {
return return
} }
ctx.Data["PageIsPullList"] = true ctx.Data["PageIsPullList"] = true
if err = issue.GetPullRequest(); err != nil {
ctx.Handle(500, "GetPullRequest", err)
return
}
ctx.Data["PageIsPullConversation"] = true ctx.Data["PageIsPullConversation"] = true
} else { } else {
MustEnableIssues(ctx) MustEnableIssues(ctx)
@@ -668,19 +662,19 @@ func UpdateIssueTitle(ctx *context.Context) {
return return
} }
issue.Name = ctx.QueryTrim("title") title := ctx.QueryTrim("title")
if len(issue.Name) == 0 { if len(title) == 0 {
ctx.Error(204) ctx.Error(204)
return return
} }
if err := models.UpdateIssue(issue); err != nil { if err := issue.ChangeTitle(ctx.User, title); err != nil {
ctx.Handle(500, "UpdateIssue", err) ctx.Handle(500, "ChangeTitle", err)
return return
} }
ctx.JSON(200, map[string]interface{}{ ctx.JSON(200, map[string]interface{}{
"title": issue.Name, "title": issue.Title,
}) })
} }
@@ -695,9 +689,9 @@ func UpdateIssueContent(ctx *context.Context) {
return return
} }
issue.Content = ctx.Query("content") content := ctx.Query("content")
if err := models.UpdateIssue(issue); err != nil { if err := issue.ChangeContent(ctx.User, content); err != nil {
ctx.Handle(500, "UpdateIssue", err) ctx.Handle(500, "ChangeContent", err)
return return
} }
@@ -713,7 +707,7 @@ func UpdateIssueLabel(ctx *context.Context) {
} }
if ctx.Query("action") == "clear" { if ctx.Query("action") == "clear" {
if err := issue.ClearLabels(); err != nil { if err := issue.ClearLabels(ctx.User); err != nil {
ctx.Handle(500, "ClearLabels", err) ctx.Handle(500, "ClearLabels", err)
return return
} }
@@ -730,12 +724,12 @@ func UpdateIssueLabel(ctx *context.Context) {
} }
if isAttach && !issue.HasLabel(label.ID) { if isAttach && !issue.HasLabel(label.ID) {
if err = issue.AddLabel(label); err != nil { if err = issue.AddLabel(ctx.User, label); err != nil {
ctx.Handle(500, "AddLabel", err) ctx.Handle(500, "AddLabel", err)
return return
} }
} else if !isAttach && issue.HasLabel(label.ID) { } else if !isAttach && issue.HasLabel(label.ID) {
if err = issue.RemoveLabel(label); err != nil { if err = issue.RemoveLabel(ctx.User, label); err != nil {
ctx.Handle(500, "RemoveLabel", err) ctx.Handle(500, "RemoveLabel", err)
return return
} }
@@ -780,18 +774,16 @@ func UpdateIssueAssignee(ctx *context.Context) {
return return
} }
aid := ctx.QueryInt64("id") assigneeID := ctx.QueryInt64("id")
if issue.AssigneeID == aid { if issue.AssigneeID == assigneeID {
ctx.JSON(200, map[string]interface{}{ ctx.JSON(200, map[string]interface{}{
"ok": true, "ok": true,
}) })
return return
} }
// Not check for invalid assignee id and give responsibility to owners. if err := issue.ChangeAssignee(ctx.User, assigneeID); err != nil {
issue.AssigneeID = aid ctx.Handle(500, "ChangeAssignee", err)
if err := models.UpdateIssueUserByAssignee(issue); err != nil {
ctx.Handle(500, "UpdateIssueUserByAssignee", err)
return return
} }
@@ -806,12 +798,6 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
ctx.HandleError("GetIssueByIndex", models.IsErrIssueNotExist, err, 404) ctx.HandleError("GetIssueByIndex", models.IsErrIssueNotExist, err, 404)
return return
} }
if issue.IsPull {
if err = issue.GetPullRequest(); err != nil {
ctx.Handle(500, "GetPullRequest", err)
return
}
}
var attachments []string var attachments []string
if setting.AttachmentEnabled { if setting.AttachmentEnabled {
+21 -18
View File
@@ -148,7 +148,7 @@ func checkPullInfo(ctx *context.Context) *models.Issue {
} }
return nil return nil
} }
ctx.Data["Title"] = issue.Name ctx.Data["Title"] = issue.Title
ctx.Data["Issue"] = issue ctx.Data["Issue"] = issue
if !issue.IsPull { if !issue.IsPull {
@@ -156,10 +156,7 @@ func checkPullInfo(ctx *context.Context) *models.Issue {
return nil return nil
} }
if err = issue.GetPullRequest(); err != nil { if err = issue.GetHeadRepo(); err != nil {
ctx.Handle(500, "GetPullRequest", err)
return nil
} else if err = issue.GetHeadRepo(); err != nil {
ctx.Handle(500, "GetHeadRepo", err) ctx.Handle(500, "GetHeadRepo", err)
return nil return nil
} }
@@ -177,17 +174,10 @@ func checkPullInfo(ctx *context.Context) *models.Issue {
func PrepareMergedViewPullInfo(ctx *context.Context, pull *models.Issue) { func PrepareMergedViewPullInfo(ctx *context.Context, pull *models.Issue) {
ctx.Data["HasMerged"] = true ctx.Data["HasMerged"] = true
var err error
if err = pull.GetMerger(); err != nil {
ctx.Handle(500, "GetMerger", err)
return
}
ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadBranch ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadBranch
ctx.Data["BaseTarget"] = ctx.Repo.Owner.Name + "/" + pull.BaseBranch ctx.Data["BaseTarget"] = ctx.Repo.Owner.Name + "/" + pull.BaseBranch
var err error
ctx.Data["NumCommits"], err = ctx.Repo.GitRepo.CommitsCountBetween(pull.MergeBase, pull.MergedCommitID) ctx.Data["NumCommits"], err = ctx.Repo.GitRepo.CommitsCountBetween(pull.MergeBase, pull.MergedCommitID)
if err != nil { if err != nil {
ctx.Handle(500, "Repo.GitRepo.CommitsCountBetween", err) ctx.Handle(500, "Repo.GitRepo.CommitsCountBetween", err)
@@ -252,6 +242,7 @@ func PrepareViewPullInfo(ctx *context.Context, pull *models.Issue) *git.PullRequ
} }
func ViewPullCommits(ctx *context.Context) { func ViewPullCommits(ctx *context.Context) {
ctx.Data["PageIsPullList"] = true
ctx.Data["PageIsPullCommits"] = true ctx.Data["PageIsPullCommits"] = true
pull := checkPullInfo(ctx) pull := checkPullInfo(ctx)
@@ -302,6 +293,7 @@ func ViewPullCommits(ctx *context.Context) {
} }
func ViewPullFiles(ctx *context.Context) { func ViewPullFiles(ctx *context.Context) {
ctx.Data["PageIsPullList"] = true
ctx.Data["PageIsPullFiles"] = true ctx.Data["PageIsPullFiles"] = true
pull := checkPullInfo(ctx) pull := checkPullInfo(ctx)
@@ -679,7 +671,7 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
pullIssue := &models.Issue{ pullIssue := &models.Issue{
RepoID: repo.ID, RepoID: repo.ID,
Index: repo.NextIssueIndex(), Index: repo.NextIssueIndex(),
Name: form.Title, Title: form.Title,
PosterID: ctx.User.ID, PosterID: ctx.User.ID,
Poster: ctx.User, Poster: ctx.User,
MilestoneID: milestoneID, MilestoneID: milestoneID,
@@ -711,11 +703,12 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
} }
func TriggerTask(ctx *context.Context) { func TriggerTask(ctx *context.Context) {
pusherID := ctx.QueryInt64("pusher")
branch := ctx.Query("branch") branch := ctx.Query("branch")
secret := ctx.Query("secret") secret := ctx.Query("secret")
if len(branch) == 0 || len(secret) == 0 { if len(branch) == 0 || len(secret) == 0 || pusherID <= 0 {
ctx.Error(404) ctx.Error(404)
log.Trace("TriggerTask: branch or secret is empty") log.Trace("TriggerTask: branch or secret is empty, or pusher ID is not valid")
return return
} }
owner, repo := parseOwnerAndRepo(ctx) owner, repo := parseOwnerAndRepo(ctx)
@@ -728,9 +721,19 @@ func TriggerTask(ctx *context.Context) {
return return
} }
log.Trace("TriggerTask [%d].(new request): %s", repo.ID, branch) pusher, err := models.GetUserByID(pusherID)
if err != nil {
if models.IsErrUserNotExist(err) {
ctx.Error(404)
} else {
ctx.Handle(500, "GetUserByID", err)
}
return
}
log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name)
go models.HookQueue.Add(repo.ID) go models.HookQueue.Add(repo.ID)
go models.AddTestPullRequestTask(repo.ID, branch) go models.AddTestPullRequestTask(pusher, repo.ID, branch, true)
ctx.Status(202) ctx.Status(202)
} }
+2 -2
View File
@@ -77,7 +77,7 @@ func Releases(ctx *context.Context) {
r.Publisher, err = models.GetUserByID(r.PublisherID) r.Publisher, err = models.GetUserByID(r.PublisherID)
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
r.Publisher = models.NewFakeUser() r.Publisher = models.NewGhostUser()
} else { } else {
ctx.Handle(500, "GetUserByID", err) ctx.Handle(500, "GetUserByID", err)
return return
@@ -126,7 +126,7 @@ func Releases(ctx *context.Context) {
r.Publisher, err = models.GetUserByID(r.PublisherID) r.Publisher, err = models.GetUserByID(r.PublisherID)
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
r.Publisher = models.NewFakeUser() r.Publisher = models.NewGhostUser()
} else { } else {
ctx.Handle(500, "GetUserByID", err) ctx.Handle(500, "GetUserByID", err)
return return
+3 -2
View File
@@ -108,8 +108,9 @@ func ParseHookEvent(form auth.WebhookForm) *models.HookEvent {
SendEverything: form.SendEverything(), SendEverything: form.SendEverything(),
ChooseEvents: form.ChooseEvents(), ChooseEvents: form.ChooseEvents(),
HookEvents: models.HookEvents{ HookEvents: models.HookEvents{
Create: form.Create, Create: form.Create,
Push: form.Push, Push: form.Push,
PullRequest: form.PullRequest,
}, },
} }
} }
+1 -1
View File
@@ -1 +1 @@
0.9.75.0813 0.9.76.0814
+1 -1
View File
@@ -102,7 +102,7 @@
{{ $timeStr:= TimeSince .Created $.Lang }} {{ $timeStr:= TimeSince .Created $.Lang }}
<li class="item"> <li class="item">
<div class="ui {{if .IsRead}}black{{else}}green{{end}} label">#{{.Index}}</div> <div class="ui {{if .IsRead}}black{{else}}green{{end}} label">#{{.Index}}</div>
<a class="title has-emoji" href="{{$.Link}}/{{.Index}}">{{.Name}}</a> <a class="title has-emoji" href="{{$.Link}}/{{.Index}}">{{.Title}}</a>
{{range .Labels}} {{range .Labels}}
<a class="ui label" href="{{$.Link}}?type={{$.ViewType}}&state={{$.State}}&labels={{.ID}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}}">{{.Name}}</a> <a class="ui label" href="{{$.Link}}?type={{$.ViewType}}&state={{$.State}}&labels={{.ID}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}}">{{.Name}}</a>
+2 -2
View File
@@ -1,9 +1,9 @@
<div class="sixteen wide column title"> <div class="sixteen wide column title">
<div class="ui grid"> <div class="ui grid">
<h1 class="twelve wide column"> <h1 class="twelve wide column">
<span class="index">#{{.Issue.Index}}</span> <span id="issue-title" class="has-emoji">{{.Issue.Name}}</span> <span class="index">#{{.Issue.Index}}</span> <span id="issue-title" class="has-emoji">{{.Issue.Title}}</span>
<div id="edit-title-input" class="ui input" style="display: none"> <div id="edit-title-input" class="ui input" style="display: none">
<input value="{{.Issue.Name}}"> <input value="{{.Issue.Title}}">
</div> </div>
</h1> </h1>
{{if .IsIssueOwner}} {{if .IsIssueOwner}}
@@ -42,6 +42,16 @@
</div> </div>
</div> </div>
</div> </div>
<!-- Pull Request -->
<div class="seven wide column">
<div class="field">
<div class="ui checkbox">
<input class="hidden" name="pull_request" type="checkbox" tabindex="0" {{if .Webhook.PullRequest}}checked{{end}}>
<label>{{.i18n.Tr "repo.settings.event_pull_request"}}</label>
<span class="help">{{.i18n.Tr "repo.settings.event_pull_request_desc"}}</span>
</div>
</div>
</div>
</div> </div>
</div> </div>