type ActionType int
const (
- ACTION_CREATE_REPO ActionType = iota + 1 // 1
- ACTION_RENAME_REPO // 2
- ACTION_STAR_REPO // 3
- ACTION_WATCH_REPO // 4
- ACTION_COMMIT_REPO // 5
- ACTION_CREATE_ISSUE // 6
- ACTION_CREATE_PULL_REQUEST // 7
- ACTION_TRANSFER_REPO // 8
- ACTION_PUSH_TAG // 9
- ACTION_COMMENT_ISSUE // 10
- ACTION_MERGE_PULL_REQUEST // 11
- ACTION_CLOSE_ISSUE // 12
- ACTION_REOPEN_ISSUE // 13
- ACTION_CLOSE_PULL_REQUEST // 14
- ACTION_REOPEN_PULL_REQUEST // 15
+ ActionCreateRepo ActionType = iota + 1 // 1
+ ActionRenameRepo // 2
+ ActionStarRepo // 3
+ ActionWatchRepo // 4
+ ActionCommitRepo // 5
+ ActionCreateIssue // 6
+ ActionCreatePullRequest // 7
+ ActionTransferRepo // 8
+ ActionPushTag // 9
+ ActionCommentIssue // 10
+ ActionMergePullRequest // 11
+ ActionCloseIssue // 12
+ ActionReopenIssue // 13
+ ActionClosePullRequest // 14
+ ActionReopenPullRequest // 15
)
var (
if err = notifyWatchers(e, &Action{
ActUserID: u.ID,
ActUserName: u.Name,
- OpType: ACTION_CREATE_REPO,
+ OpType: ActionCreateRepo,
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,
RepoName: repo.Name,
if err = notifyWatchers(e, &Action{
ActUserID: actUser.ID,
ActUserName: actUser.Name,
- OpType: ACTION_RENAME_REPO,
+ OpType: ActionRenameRepo,
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,
RepoName: repo.Name,
}
isNewBranch := false
- opType := ACTION_COMMIT_REPO
+ opType := ActionCommitRepo
// Check it's tag push or branch.
if strings.HasPrefix(opts.RefFullName, git.TAG_PREFIX) {
- opType = ACTION_PUSH_TAG
+ opType = ActionPushTag
opts.Commits = &PushCommits{}
} else {
// if not the first commit, set the compare URL.
apiPusher := pusher.APIFormat()
apiRepo := repo.APIFormat(nil)
switch opType {
- case ACTION_COMMIT_REPO: // Push
- if err = PrepareWebhooks(repo, HOOK_EVENT_PUSH, &api.PushPayload{
+ case ActionCommitRepo: // Push
+ if err = PrepareWebhooks(repo, HookEventPush, &api.PushPayload{
Ref: opts.RefFullName,
Before: opts.OldCommitID,
After: opts.NewCommitID,
}
if isNewBranch {
- return PrepareWebhooks(repo, HOOK_EVENT_CREATE, &api.CreatePayload{
+ return PrepareWebhooks(repo, HookEventCreate, &api.CreatePayload{
Ref: refName,
RefType: "branch",
Repo: apiRepo,
})
}
- case ACTION_PUSH_TAG: // Create
- return PrepareWebhooks(repo, HOOK_EVENT_CREATE, &api.CreatePayload{
+ case ActionPushTag: // Create
+ return PrepareWebhooks(repo, HookEventCreate, &api.CreatePayload{
Ref: refName,
RefType: "tag",
Repo: apiRepo,
if err = notifyWatchers(e, &Action{
ActUserID: doer.ID,
ActUserName: doer.Name,
- OpType: ACTION_TRANSFER_REPO,
+ OpType: ActionTransferRepo,
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,
RepoName: repo.Name,
return notifyWatchers(e, &Action{
ActUserID: doer.ID,
ActUserName: doer.Name,
- OpType: ACTION_MERGE_PULL_REQUEST,
+ OpType: ActionMergePullRequest,
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Title),
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,
log.Error(4, "LoadIssue: %v", err)
return
}
- err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{
- Action: api.HOOK_ISSUE_LABEL_UPDATED,
+ err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
+ Action: api.HookIssueLabelUpdated,
Index: issue.Index,
PullRequest: issue.PullRequest.APIFormat(),
Repository: issue.Repo.APIFormat(nil),
log.Error(4, "LoadIssue: %v", err)
return
}
- err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{
- Action: api.HOOK_ISSUE_LABEL_CLEARED,
+ err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
+ Action: api.HookIssueLabelCleared,
Index: issue.Index,
PullRequest: issue.PullRequest.APIFormat(),
Repository: issue.Repo.APIFormat(nil),
Sender: doer.APIFormat(),
}
if isClosed {
- apiPullRequest.Action = api.HOOK_ISSUE_CLOSED
+ apiPullRequest.Action = api.HookIssueClosed
} else {
- apiPullRequest.Action = api.HOOK_ISSUE_REOPENED
+ apiPullRequest.Action = api.HookIssueReopened
}
- err = PrepareWebhooks(repo, HOOK_EVENT_PULL_REQUEST, apiPullRequest)
+ err = PrepareWebhooks(repo, HookEventPullRequest, apiPullRequest)
}
if err != nil {
log.Error(4, "PrepareWebhooks [is_pull: %v, is_closed: %v]: %v", issue.IsPull, isClosed, err)
if issue.IsPull {
issue.PullRequest.Issue = issue
- err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{
- Action: api.HOOK_ISSUE_EDITED,
+ err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
+ Action: api.HookIssueEdited,
Index: issue.Index,
Changes: &api.ChangesPayload{
Title: &api.ChangesFromPayload{
if issue.IsPull {
issue.PullRequest.Issue = issue
- err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{
- Action: api.HOOK_ISSUE_EDITED,
+ err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
+ Action: api.HookIssueEdited,
Index: issue.Index,
Changes: &api.ChangesPayload{
Body: &api.ChangesFromPayload{
Sender: doer.APIFormat(),
}
if isRemoveAssignee {
- apiPullRequest.Action = api.HOOK_ISSUE_UNASSIGNED
+ apiPullRequest.Action = api.HookIssueUnassigned
} else {
- apiPullRequest.Action = api.HOOK_ISSUE_ASSIGNED
+ apiPullRequest.Action = api.HookIssueAssigned
}
- err = PrepareWebhooks(issue.Repo, HOOK_EVENT_PULL_REQUEST, apiPullRequest)
+ err = PrepareWebhooks(issue.Repo, HookEventPullRequest, apiPullRequest)
}
if err != nil {
log.Error(4, "PrepareWebhooks [is_pull: %v, remove_assignee: %v]: %v", issue.IsPull, isRemoveAssignee, err)
if err = NotifyWatchers(&Action{
ActUserID: issue.Poster.ID,
ActUserName: issue.Poster.Name,
- OpType: ACTION_CREATE_ISSUE,
+ OpType: ActionCreateIssue,
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Title),
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,
}
switch opType {
- case ACTION_COMMENT_ISSUE:
+ case ActionCommentIssue:
issue.Content = cmt.Content
- case ACTION_CLOSE_ISSUE:
+ case ActionCloseIssue:
issue.Content = fmt.Sprintf("Closed #%d", issue.Index)
- case ACTION_REOPEN_ISSUE:
+ case ActionReopenIssue:
issue.Content = fmt.Sprintf("Reopened #%d", issue.Index)
}
if err = mailIssueCommentToParticipants(issue, cmt.Poster, mentions); err != nil {
// Check comment type.
switch opts.Type {
case COMMENT_TYPE_COMMENT:
- act.OpType = ACTION_COMMENT_ISSUE
+ act.OpType = ActionCommentIssue
if _, err = e.Exec("UPDATE `issue` SET num_comments=num_comments+1 WHERE id=?", opts.Issue.ID); err != nil {
return nil, err
}
case COMMENT_TYPE_REOPEN:
- act.OpType = ACTION_REOPEN_ISSUE
+ act.OpType = ActionReopenIssue
if opts.Issue.IsPull {
- act.OpType = ACTION_REOPEN_PULL_REQUEST
+ act.OpType = ActionReopenPullRequest
}
if opts.Issue.IsPull {
}
case COMMENT_TYPE_CLOSE:
- act.OpType = ACTION_CLOSE_ISSUE
+ act.OpType = ActionCloseIssue
if opts.Issue.IsPull {
- act.OpType = ACTION_CLOSE_PULL_REQUEST
+ act.OpType = ActionClosePullRequest
}
if opts.Issue.IsPull {
type PullRequestType int
const (
- PULL_REQUEST_GITEA PullRequestType = iota
- PULL_REQUEST_GIT
+ PullRequestGitea PullRequestType = iota
+ PullRequestGit
)
type PullRequestStatus int
const (
- PULL_REQUEST_STATUS_CONFLICT PullRequestStatus = iota
- PULL_REQUEST_STATUS_CHECKING
- PULL_REQUEST_STATUS_MERGEABLE
+ PullRequestStatusConflict PullRequestStatus = iota
+ PullRequestStatusChecking
+ PullRequestStatusMergeable
)
// PullRequest represents relation between pull request and repositories.
HasMerged: pr.HasMerged,
}
- if pr.Status != PULL_REQUEST_STATUS_CHECKING {
- mergeable := pr.Status != PULL_REQUEST_STATUS_CONFLICT
+ if pr.Status != PullRequestStatusChecking {
+ mergeable := pr.Status != PullRequestStatusConflict
apiPullRequest.Mergeable = &mergeable
}
if pr.HasMerged {
// IsChecking returns true if this pull request is still checking conflict.
func (pr *PullRequest) IsChecking() bool {
- return pr.Status == PULL_REQUEST_STATUS_CHECKING
+ return pr.Status == PullRequestStatusChecking
}
// CanAutoMerge returns true if this pull request can be merged automatically.
func (pr *PullRequest) CanAutoMerge() bool {
- return pr.Status == PULL_REQUEST_STATUS_MERGEABLE
+ return pr.Status == PullRequestStatusMergeable
}
// Merge merges pull request to base repository.
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,
+ if err = PrepareWebhooks(pr.Issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
+ Action: api.HookIssueClosed,
Index: pr.Index,
PullRequest: pr.APIFormat(),
Repository: pr.Issue.Repo.APIFormat(nil),
Pusher: pr.HeadRepo.MustOwner().APIFormat(),
Sender: doer.APIFormat(),
}
- if err = PrepareWebhooks(pr.BaseRepo, HOOK_EVENT_PUSH, p); err != nil {
+ if err = PrepareWebhooks(pr.BaseRepo, HookEventPush, p); err != nil {
return fmt.Errorf("PrepareWebhooks: %v", err)
}
return nil
return fmt.Errorf("UpdateLocalCopy: %v", err)
}
- pr.Status = PULL_REQUEST_STATUS_CHECKING
+ pr.Status = PullRequestStatusChecking
_, stderr, err := process.ExecDir(-1, pr.BaseRepo.LocalCopyPath(),
fmt.Sprintf("testPatch (git apply --check): %d", pr.BaseRepo.ID),
"git", "apply", "--check", patchPath)
if strings.Contains(stderr, patchConflicts[i]) {
log.Trace("PullRequest[%d].testPatch (apply): has conflit", pr.ID)
fmt.Println(stderr)
- pr.Status = PULL_REQUEST_STATUS_CONFLICT
+ pr.Status = PullRequestStatusConflict
return nil
}
}
return fmt.Errorf("testPatch: %v", err)
}
// No conflict appears after test means mergeable.
- if pr.Status == PULL_REQUEST_STATUS_CHECKING {
- pr.Status = PULL_REQUEST_STATUS_MERGEABLE
+ if pr.Status == PullRequestStatusChecking {
+ pr.Status = PullRequestStatusMergeable
}
pr.IssueID = pull.ID
if err = NotifyWatchers(&Action{
ActUserID: pull.Poster.ID,
ActUserName: pull.Poster.Name,
- OpType: ACTION_CREATE_PULL_REQUEST,
+ OpType: ActionCreatePullRequest,
Content: fmt.Sprintf("%d|%s", pull.Index, pull.Title),
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,
pr.Issue = pull
pull.PullRequest = pr
- if err = PrepareWebhooks(repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{
- Action: api.HOOK_ISSUE_OPENED,
+ if err = PrepareWebhooks(repo, HookEventPullRequest, &api.PullRequestPayload{
+ Action: api.HookIssueOpened,
Index: pull.Index,
PullRequest: pr.APIFormat(),
Repository: repo.APIFormat(nil),
// AddToTaskQueue adds itself to pull request test task queue.
func (pr *PullRequest) AddToTaskQueue() {
go PullRequestQueue.AddFunc(pr.ID, func() {
- pr.Status = PULL_REQUEST_STATUS_CHECKING
+ pr.Status = PullRequestStatusChecking
if err := pr.UpdateCols("status"); err != nil {
log.Error(5, "AddToTaskQueue.UpdateCols[%d].(add to queue): %v", pr.ID, err)
}
log.Error(4, "LoadAttributes: %v", err)
continue
}
- if err = PrepareWebhooks(pr.Issue.Repo, HOOK_EVENT_PULL_REQUEST, &api.PullRequestPayload{
- Action: api.HOOK_ISSUE_SYNCHRONIZED,
+ if err = PrepareWebhooks(pr.Issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
+ Action: api.HookIssueSynchronized,
Index: pr.Issue.Index,
PullRequest: pr.Issue.PullRequest.APIFormat(),
Repository: pr.Issue.Repo.APIFormat(nil),
// and set to be either conflict or mergeable.
func (pr *PullRequest) checkAndUpdateStatus() {
// Status is not changed to conflict means mergeable.
- if pr.Status == PULL_REQUEST_STATUS_CHECKING {
- pr.Status = PULL_REQUEST_STATUS_MERGEABLE
+ if pr.Status == PullRequestStatusChecking {
+ pr.Status = PullRequestStatusMergeable
}
// Make sure there is no waiting test to process before levaing the checking status.
func TestPullRequests() {
prs := make([]*PullRequest, 0, 10)
x.Iterate(PullRequest{
- Status: PULL_REQUEST_STATUS_CHECKING,
+ Status: PullRequestStatusChecking,
},
func(idx int, bean interface{}) error {
pr := bean.(*PullRequest)
const (
HOOK_STATUS_NONE = iota
- HOOK_STATUS_SUCCEED
- HOOK_STATUS_FAILED
+ HookStatusSucceed
+ HookStatusFail
)
// Webhook represents a web hook object.
type HookEventType string
const (
- HOOK_EVENT_CREATE HookEventType = "create"
- HOOK_EVENT_PUSH HookEventType = "push"
- HOOK_EVENT_PULL_REQUEST HookEventType = "pull_request"
+ HookEventCreate HookEventType = "create"
+ HookEventPush HookEventType = "push"
+ HookEventPullRequest HookEventType = "pull_request"
)
// HookRequest represents hook task request information.
var payloader api.Payloader
for _, w := range ws {
switch event {
- case HOOK_EVENT_CREATE:
+ case HookEventCreate:
if !w.HasCreateEvent() {
continue
}
- case HOOK_EVENT_PUSH:
+ case HookEventPush:
if !w.HasPushEvent() {
continue
}
- case HOOK_EVENT_PULL_REQUEST:
+ case HookEventPullRequest:
if !w.HasPullRequestEvent() {
continue
}
return
}
if t.IsSucceed {
- w.LastStatus = HOOK_STATUS_SUCCEED
+ w.LastStatus = HookStatusSucceed
} else {
- w.LastStatus = HOOK_STATUS_FAILED
+ w.LastStatus = HookStatusFail
}
if err = UpdateWebhook(w); err != nil {
log.Error(5, "UpdateWebhook: %v", err)
fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title))
var text, title, attachmentText string
switch p.Action {
- case api.HOOK_ISSUE_OPENED:
+ case api.HookIssueOpened:
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:
+ case api.HookIssueClosed:
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:
+ case api.HookIssueReopened:
text = fmt.Sprintf("[%s] Pull request re-opened: %s by %s", p.Repository.FullName, titleLink, senderLink)
- case api.HOOK_ISSUE_EDITED:
+ case api.HookIssueEdited:
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:
+ case api.HookIssueAssigned:
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:
+ case api.HookIssueUnassigned:
text = fmt.Sprintf("[%s] Pull request unassigned: %s by %s", p.Repository.FullName, titleLink, senderLink)
- case api.HOOK_ISSUE_LABEL_UPDATED:
+ case api.HookIssueLabelUpdated:
text = fmt.Sprintf("[%s] Pull request labels updated: %s by %s", p.Repository.FullName, titleLink, senderLink)
- case api.HOOK_ISSUE_LABEL_CLEARED:
+ case api.HookIssueLabelCleared:
text = fmt.Sprintf("[%s] Pull request labels cleared: %s by %s", p.Repository.FullName, titleLink, senderLink)
- case api.HOOK_ISSUE_SYNCHRONIZED:
+ case api.HookIssueSynchronized:
text = fmt.Sprintf("[%s] Pull request synchronized: %s by %s", p.Repository.FullName, titleLink, senderLink)
}
}
switch event {
- case HOOK_EVENT_CREATE:
+ case HookEventCreate:
return getSlackCreatePayload(p.(*api.CreatePayload), slack)
- case HOOK_EVENT_PUSH:
+ case HookEventPush:
return getSlackPushPayload(p.(*api.PushPayload), slack)
- case HOOK_EVENT_PULL_REQUEST:
+ case HookEventPullRequest:
return getSlackPullRequestPayload(p.(*api.PullRequestPayload), slack)
}
HookEvent: &models.HookEvent{
ChooseEvents: true,
HookEvents: models.HookEvents{
- Create: com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_CREATE)),
- Push: com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_PUSH)),
- PullRequest: com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_PULL_REQUEST)),
+ Create: com.IsSliceContainsStr(form.Events, string(models.HookEventCreate)),
+ Push: com.IsSliceContainsStr(form.Events, string(models.HookEventPush)),
+ PullRequest: com.IsSliceContainsStr(form.Events, string(models.HookEventPullRequest)),
},
},
IsActive: form.Active,
w.PushOnly = false
w.SendEverything = false
w.ChooseEvents = true
- w.Create = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_CREATE))
- w.Push = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_PUSH))
- w.PullRequest = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_PULL_REQUEST))
+ w.Create = com.IsSliceContainsStr(form.Events, string(models.HookEventCreate))
+ w.Push = com.IsSliceContainsStr(form.Events, string(models.HookEventPush))
+ w.PullRequest = com.IsSliceContainsStr(form.Events, string(models.HookEventPullRequest))
if err = w.UpdateEvent(); err != nil {
ctx.Error(500, "UpdateEvent", err)
return
HeadRepo: headRepo,
BaseRepo: repo,
MergeBase: prInfo.MergeBase,
- Type: models.PULL_REQUEST_GITEA,
+ Type: models.PullRequestGitea,
}
// FIXME: check error in the case two people send pull request at almost same time, give nice error prompt
// instead of 500.
Pusher: apiUser,
Sender: apiUser,
}
- if err := models.PrepareWebhooks(ctx.Repo.Repository, models.HOOK_EVENT_PUSH, p); err != nil {
+ if err := models.PrepareWebhooks(ctx.Repo.Repository, models.HookEventPush, p); err != nil {
ctx.Flash.Error("PrepareWebhooks: " + err.Error())
ctx.Status(500)
} else {
type HookIssueAction string
const (
- HOOK_ISSUE_OPENED HookIssueAction = "opened"
- HOOK_ISSUE_CLOSED HookIssueAction = "closed"
- HOOK_ISSUE_REOPENED HookIssueAction = "reopened"
- HOOK_ISSUE_EDITED HookIssueAction = "edited"
- HOOK_ISSUE_ASSIGNED HookIssueAction = "assigned"
- HOOK_ISSUE_UNASSIGNED HookIssueAction = "unassigned"
- HOOK_ISSUE_LABEL_UPDATED HookIssueAction = "label_updated"
- HOOK_ISSUE_LABEL_CLEARED HookIssueAction = "label_cleared"
- HOOK_ISSUE_SYNCHRONIZED HookIssueAction = "synchronized"
+ HookIssueOpened HookIssueAction = "opened"
+ HookIssueClosed HookIssueAction = "closed"
+ HookIssueReopened HookIssueAction = "reopened"
+ HookIssueEdited HookIssueAction = "edited"
+ HookIssueAssigned HookIssueAction = "assigned"
+ HookIssueUnassigned HookIssueAction = "unassigned"
+ HookIssueLabelUpdated HookIssueAction = "label_updated"
+ HookIssueLabelCleared HookIssueAction = "label_cleared"
+ HookIssueSynchronized HookIssueAction = "synchronized"
)
type ChangesFromPayload struct {