From 87d8a19e37c964ab419aaa4a98ce04a82cf66b2b Mon Sep 17 00:00:00 2001 From: shimamoto Date: Mon, 1 Jul 2013 21:05:52 +0900 Subject: [PATCH] Add close and re-open of the issue. --- src/main/scala/app/IssuesController.scala | 5 ++++- src/main/scala/service/IssuesService.scala | 12 ++++++++++-- .../scala/servlet/GitRepositoryServlet.scala | 2 +- src/main/twirl/issues/issue.scala.html | 16 ++++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/main/scala/app/IssuesController.scala b/src/main/scala/app/IssuesController.scala index 25083ae78..5847f705f 100644 --- a/src/main/scala/app/IssuesController.scala +++ b/src/main/scala/app/IssuesController.scala @@ -81,9 +81,12 @@ trait IssuesControllerBase extends ControllerBase { post("/:owner/:repository/issue_comments/new", commentForm)( usersOnly { form => val owner = params("owner") val repository = params("repository") + val action = params.get("action") filter { action => + updateClosed(owner, repository, form.issueId, if(action == "close") true else false) > 0 + } redirect("/%s/%s/issues/%d#comment-%d".format(owner, repository, form.issueId, - createComment(owner, repository, context.loginAccount.get.userName, form.issueId, form.content))) + createComment(owner, repository, context.loginAccount.get.userName, form.issueId, form.content, action))) }) // TODO Authenticator, repository checking diff --git a/src/main/scala/service/IssuesService.scala b/src/main/scala/service/IssuesService.scala index 7d6546381..424afd41a 100644 --- a/src/main/scala/service/IssuesService.scala +++ b/src/main/scala/service/IssuesService.scala @@ -185,12 +185,12 @@ trait IssuesService { } get def createComment(owner: String, repository: String, loginUser: String, - issueId: Int, content: String) = + issueId: Int, content: String, action: Option[String]) = IssueComments.autoInc insert ( owner, repository, issueId, - None, + action, loginUser, content, currentDate, @@ -213,6 +213,14 @@ trait IssuesService { t.content ~ t.updatedDate } update (content, currentDate) + def updateClosed(owner: String, repository: String, issueId: Int, closed: Boolean) = + Issues + .filter (_.byPrimaryKey(owner, repository, issueId)) + .map { t => + t.closed ~ t.updatedDate + } + .update (closed, currentDate) + } object IssuesService { diff --git a/src/main/scala/servlet/GitRepositoryServlet.scala b/src/main/scala/servlet/GitRepositoryServlet.scala index 41440e397..75d23549e 100644 --- a/src/main/scala/servlet/GitRepositoryServlet.scala +++ b/src/main/scala/servlet/GitRepositoryServlet.scala @@ -79,7 +79,7 @@ class CommitLogHook(owner: String, repository: String) extends PostReceiveHook "(^|\\W)#(\\d+)(\\W|$)".r.findAllIn(commit.fullMessage).matchData.foreach { matchData => val issueId = matchData.group(2) if(getAccountByUserName(commit.committer).isDefined && getIssue(owner, repository, issueId).isDefined){ - createComment(owner, repository, commit.committer, issueId.toInt, commit.fullMessage) + createComment(owner, repository, commit.committer, issueId.toInt, commit.fullMessage, None) } } } diff --git a/src/main/twirl/issues/issue.scala.html b/src/main/twirl/issues/issue.scala.html index 088336b31..9db84620e 100644 --- a/src/main/twirl/issues/issue.scala.html +++ b/src/main/twirl/issues/issue.scala.html @@ -33,6 +33,17 @@ @markdown(comment.content, repository, false, true, true) + @comment.action.map { action => +
+ @if(action == "close"){ + Closed + @comment.commentedUserName closed the issue @datetime(comment.registeredDate) + } else { + Reopened + @comment.commentedUserName reopened the issue @datetime(comment.registeredDate) + } +
+ } }
@@ -42,6 +53,7 @@
+
@@ -80,5 +92,9 @@ $(function(){ }); return false; }); + + $('#action').click(function(){ + $('').attr('name', 'action').val($(this).val().toLowerCase()).appendTo('form'); + }); }); \ No newline at end of file