Add close and re-open of the issue.

This commit is contained in:
shimamoto
2013-07-01 21:05:52 +09:00
parent 56cec26c5b
commit 87d8a19e37
4 changed files with 31 additions and 4 deletions

View File

@@ -81,9 +81,12 @@ trait IssuesControllerBase extends ControllerBase {
post("/:owner/:repository/issue_comments/new", commentForm)( usersOnly { form => post("/:owner/:repository/issue_comments/new", commentForm)( usersOnly { form =>
val owner = params("owner") val owner = params("owner")
val repository = params("repository") 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, 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 // TODO Authenticator, repository checking

View File

@@ -185,12 +185,12 @@ trait IssuesService {
} get } get
def createComment(owner: String, repository: String, loginUser: String, def createComment(owner: String, repository: String, loginUser: String,
issueId: Int, content: String) = issueId: Int, content: String, action: Option[String]) =
IssueComments.autoInc insert ( IssueComments.autoInc insert (
owner, owner,
repository, repository,
issueId, issueId,
None, action,
loginUser, loginUser,
content, content,
currentDate, currentDate,
@@ -213,6 +213,14 @@ trait IssuesService {
t.content ~ t.updatedDate t.content ~ t.updatedDate
} update (content, currentDate) } 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 { object IssuesService {

View File

@@ -79,7 +79,7 @@ class CommitLogHook(owner: String, repository: String) extends PostReceiveHook
"(^|\\W)#(\\d+)(\\W|$)".r.findAllIn(commit.fullMessage).matchData.foreach { matchData => "(^|\\W)#(\\d+)(\\W|$)".r.findAllIn(commit.fullMessage).matchData.foreach { matchData =>
val issueId = matchData.group(2) val issueId = matchData.group(2)
if(getAccountByUserName(commit.committer).isDefined && getIssue(owner, repository, issueId).isDefined){ 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)
} }
} }
} }

View File

@@ -33,6 +33,17 @@
@markdown(comment.content, repository, false, true, true) @markdown(comment.content, repository, false, true, true)
</div> </div>
</div> </div>
@comment.action.map { action =>
<div class="small">
@if(action == "close"){
<span class="label label-important">Closed</span>
<a href="@url(comment.commentedUserName)">@comment.commentedUserName</a> closed the issue @datetime(comment.registeredDate)
} else {
<span class="label label-success">Reopened</span>
<a href="@url(comment.commentedUserName)">@comment.commentedUserName</a> reopened the issue @datetime(comment.registeredDate)
}
</div>
}
} }
<form action="@url(repository)/issue_comments/new" method="POST" validate="true"> <form action="@url(repository)/issue_comments/new" method="POST" validate="true">
<div class="box"> <div class="box">
@@ -42,6 +53,7 @@
</div> </div>
<input type="hidden" name="issueId" value="@issue.issueId"/> <input type="hidden" name="issueId" value="@issue.issueId"/>
<input type="submit" class="btn btn-success" value="Comment"/> <input type="submit" class="btn btn-success" value="Comment"/>
<input type="submit" class="btn" value="@{if(issue.closed) "Reopen" else "Close"}" id="action"/>
</form> </form>
</div> </div>
<div class="span2"> <div class="span2">
@@ -80,5 +92,9 @@ $(function(){
}); });
return false; return false;
}); });
$('#action').click(function(){
$('<input type="hidden">').attr('name', 'action').val($(this).val().toLowerCase()).appendTo('form');
});
}); });
</script> </script>