summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-02-22 12:40:00 -0500
committerUnknwon <u@gogs.io>2016-02-22 12:40:00 -0500
commit912f7b51e90b2e6c4ff01570f1413c736cfc4d04 (patch)
tree9f618018d3f35a090432b04dd7ad962460e4a41f /models
parent90fab0be6bc5acce1faa4b97a85ddde5f37f31d9 (diff)
downloadgitea-912f7b51e90b2e6c4ff01570f1413c736cfc4d04.tar.gz
gitea-912f7b51e90b2e6c4ff01570f1413c736cfc4d04.zip
#1821 add actions for close and reopen issues
Diffstat (limited to 'models')
-rw-r--r--models/action.go40
-rw-r--r--models/issue.go42
-rw-r--r--models/pull.go2
3 files changed, 47 insertions, 37 deletions
diff --git a/models/action.go b/models/action.go
index 3bcf999d9f..c1e23339f1 100644
--- a/models/action.go
+++ b/models/action.go
@@ -28,17 +28,19 @@ import (
type ActionType int
const (
- CREATE_REPO ActionType = iota + 1 // 1
- RENAME_REPO // 2
- STAR_REPO // 3
- FOLLOW_REPO // 4
- COMMIT_REPO // 5
- CREATE_ISSUE // 6
- CREATE_PULL_REQUEST // 7
- TRANSFER_REPO // 8
- PUSH_TAG // 9
- COMMENT_ISSUE // 10
- MERGE_PULL_REQUEST // 11
+ 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
)
var (
@@ -178,7 +180,7 @@ func newRepoAction(e Engine, u *User, repo *Repository) (err error) {
ActUserID: u.Id,
ActUserName: u.Name,
ActEmail: u.Email,
- OpType: CREATE_REPO,
+ OpType: ACTION_CREATE_REPO,
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,
RepoName: repo.Name,
@@ -201,7 +203,7 @@ func renameRepoAction(e Engine, actUser *User, oldRepoName string, repo *Reposit
ActUserID: actUser.Id,
ActUserName: actUser.Name,
ActEmail: actUser.Email,
- OpType: RENAME_REPO,
+ OpType: ACTION_RENAME_REPO,
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,
RepoName: repo.Name,
@@ -443,10 +445,10 @@ func CommitRepoAction(
}
isNewBranch := false
- opType := COMMIT_REPO
+ opType := ACTION_COMMIT_REPO
// Check it's tag push or branch.
if strings.HasPrefix(refFullName, "refs/tags/") {
- opType = PUSH_TAG
+ opType = ACTION_PUSH_TAG
commit = &PushCommits{}
} else {
// if not the first commit, set the compareUrl
@@ -502,7 +504,7 @@ func CommitRepoAction(
}
switch opType {
- case COMMIT_REPO: // Push
+ case ACTION_COMMIT_REPO: // Push
p := &api.PushPayload{
Ref: refFullName,
Before: oldCommitID,
@@ -530,7 +532,7 @@ func CommitRepoAction(
})
}
- case PUSH_TAG: // Create
+ case ACTION_PUSH_TAG: // Create
return PrepareWebhooks(repo, HOOK_EVENT_CREATE, &api.CreatePayload{
Ref: refName,
RefType: "tag",
@@ -547,7 +549,7 @@ func transferRepoAction(e Engine, actUser, oldOwner, newOwner *User, repo *Repos
ActUserID: actUser.Id,
ActUserName: actUser.Name,
ActEmail: actUser.Email,
- OpType: TRANSFER_REPO,
+ OpType: ACTION_TRANSFER_REPO,
RepoID: repo.ID,
RepoUserName: newOwner.Name,
RepoName: repo.Name,
@@ -578,7 +580,7 @@ func mergePullRequestAction(e Engine, actUser *User, repo *Repository, pull *Iss
ActUserID: actUser.Id,
ActUserName: actUser.Name,
ActEmail: actUser.Email,
- OpType: MERGE_PULL_REQUEST,
+ OpType: ACTION_MERGE_PULL_REQUEST,
Content: fmt.Sprintf("%d|%s", pull.Index, pull.Name),
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,
diff --git a/models/issue.go b/models/issue.go
index c34c3f5574..7d7fb49a61 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -364,7 +364,7 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string)
ActUserID: issue.Poster.Id,
ActUserName: issue.Poster.Name,
ActEmail: issue.Poster.Email,
- OpType: CREATE_ISSUE,
+ OpType: ACTION_CREATE_ISSUE,
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Name),
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,
@@ -1564,9 +1564,24 @@ func createComment(e *xorm.Session, u *User, repo *Repository, issue *Issue, com
return nil, err
}
+ // Compose comment action, could be plain comment, close or reopen issue.
+ // This object will be used to notify watchers in the end of function.
+ act := &Action{
+ ActUserID: u.Id,
+ ActUserName: u.Name,
+ ActEmail: u.Email,
+ Content: fmt.Sprintf("%d|%s", issue.Index, strings.Split(content, "\n")[0]),
+ RepoID: repo.ID,
+ RepoUserName: repo.Owner.Name,
+ RepoName: repo.Name,
+ IsPrivate: repo.IsPrivate,
+ }
+
// Check comment type.
switch cmtType {
case COMMENT_TYPE_COMMENT:
+ act.OpType = ACTION_COMMENT_ISSUE
+
if _, err = e.Exec("UPDATE `issue` SET num_comments=num_comments+1 WHERE id=?", issue.ID); err != nil {
return nil, err
}
@@ -1593,23 +1608,9 @@ func createComment(e *xorm.Session, u *User, repo *Repository, issue *Issue, com
}
}
- // Notify watchers.
- act := &Action{
- ActUserID: u.Id,
- ActUserName: u.Name,
- ActEmail: u.Email,
- OpType: COMMENT_ISSUE,
- Content: fmt.Sprintf("%d|%s", issue.Index, strings.Split(content, "\n")[0]),
- RepoID: repo.ID,
- RepoUserName: repo.Owner.Name,
- RepoName: repo.Name,
- IsPrivate: repo.IsPrivate,
- }
- if err = notifyWatchers(e, act); err != nil {
- return nil, err
- }
-
case COMMENT_TYPE_REOPEN:
+ act.OpType = ACTION_REOPEN_ISSUE
+
if issue.IsPull {
_, err = e.Exec("UPDATE `repository` SET num_closed_pulls=num_closed_pulls-1 WHERE id=?", repo.ID)
} else {
@@ -1619,6 +1620,8 @@ func createComment(e *xorm.Session, u *User, repo *Repository, issue *Issue, com
return nil, err
}
case COMMENT_TYPE_CLOSE:
+ act.OpType = ACTION_CLOSE_ISSUE
+
if issue.IsPull {
_, err = e.Exec("UPDATE `repository` SET num_closed_pulls=num_closed_pulls+1 WHERE id=?", repo.ID)
} else {
@@ -1629,6 +1632,11 @@ func createComment(e *xorm.Session, u *User, repo *Repository, issue *Issue, com
}
}
+ // Notify watchers for whatever action comes in.
+ if err = notifyWatchers(e, act); err != nil {
+ return nil, fmt.Errorf("notifyWatchers: %v", err)
+ }
+
return comment, nil
}
diff --git a/models/pull.go b/models/pull.go
index bf16d98fa7..47da2dd67e 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -330,7 +330,7 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str
ActUserID: pull.Poster.Id,
ActUserName: pull.Poster.Name,
ActEmail: pull.Poster.Email,
- OpType: CREATE_PULL_REQUEST,
+ OpType: ACTION_CREATE_PULL_REQUEST,
Content: fmt.Sprintf("%d|%s", pull.Index, pull.Name),
RepoID: repo.ID,
RepoUserName: repo.Owner.Name,