Improve issue and pull request creation form

This commit is contained in:
Naoki Takezoe
2015-08-19 10:20:52 +09:00
parent 8634191bd2
commit 28c0262e74
4 changed files with 93 additions and 57 deletions

View File

@@ -46,7 +46,10 @@ trait PullRequestsControllerBase extends ControllerBase {
"requestRepositoryName" -> trim(text(required, maxlength(100))), "requestRepositoryName" -> trim(text(required, maxlength(100))),
"requestBranch" -> trim(text(required, maxlength(100))), "requestBranch" -> trim(text(required, maxlength(100))),
"commitIdFrom" -> trim(text(required, maxlength(40))), "commitIdFrom" -> trim(text(required, maxlength(40))),
"commitIdTo" -> trim(text(required, maxlength(40))) "commitIdTo" -> trim(text(required, maxlength(40))),
"assignedUserName" -> trim(optional(text())),
"milestoneId" -> trim(optional(number())),
"labelNames" -> trim(optional(text()))
)(PullRequestForm.apply) )(PullRequestForm.apply)
val mergeForm = mapping( val mergeForm = mapping(
@@ -62,7 +65,11 @@ trait PullRequestsControllerBase extends ControllerBase {
requestRepositoryName: String, requestRepositoryName: String,
requestBranch: String, requestBranch: String,
commitIdFrom: String, commitIdFrom: String,
commitIdTo: String) commitIdTo: String,
assignedUserName: Option[String],
milestoneId: Option[Int],
labelNames: Option[String]
)
case class MergeForm(message: String) case class MergeForm(message: String)
@@ -332,7 +339,12 @@ trait PullRequestsControllerBase extends ControllerBase {
forkedRepository, forkedRepository,
originRepository, originRepository,
forkedRepository, forkedRepository,
hasWritePermission(forkedRepository.owner, forkedRepository.name, context.loginAccount)) hasWritePermission(originRepository.owner, originRepository.name, context.loginAccount),
hasWritePermission(forkedRepository.owner, forkedRepository.name, context.loginAccount),
(getCollaborators(originRepository.owner, originRepository.name) ::: (if(getAccountByUserName(originRepository.owner).get.isGroupAccount) Nil else List(originRepository.owner))).sorted,
getMilestones(originRepository.owner, originRepository.name),
getLabels(originRepository.owner, originRepository.name)
)
} }
}) getOrElse NotFound }) getOrElse NotFound
}) })
@@ -368,46 +380,61 @@ trait PullRequestsControllerBase extends ControllerBase {
}) })
post("/:owner/:repository/pulls/new", pullRequestForm)(referrersOnly { (form, repository) => post("/:owner/:repository/pulls/new", pullRequestForm)(referrersOnly { (form, repository) =>
val loginUserName = context.loginAccount.get.userName defining(repository.owner, repository.name){ case (owner, name) =>
val writable = hasWritePermission(owner, name, context.loginAccount)
val loginUserName = context.loginAccount.get.userName
val issueId = createIssue( val issueId = createIssue(
owner = repository.owner, owner = repository.owner,
repository = repository.name, repository = repository.name,
loginUser = loginUserName, loginUser = loginUserName,
title = form.title, title = form.title,
content = form.content, content = form.content,
assignedUserName = None, assignedUserName = if(writable) form.assignedUserName else None,
milestoneId = None, milestoneId = if(writable) form.milestoneId else None,
isPullRequest = true) isPullRequest = true)
createPullRequest( createPullRequest(
originUserName = repository.owner, originUserName = repository.owner,
originRepositoryName = repository.name, originRepositoryName = repository.name,
issueId = issueId, issueId = issueId,
originBranch = form.targetBranch, originBranch = form.targetBranch,
requestUserName = form.requestUserName, requestUserName = form.requestUserName,
requestRepositoryName = form.requestRepositoryName, requestRepositoryName = form.requestRepositoryName,
requestBranch = form.requestBranch, requestBranch = form.requestBranch,
commitIdFrom = form.commitIdFrom, commitIdFrom = form.commitIdFrom,
commitIdTo = form.commitIdTo) commitIdTo = form.commitIdTo)
// fetch requested branch // insert labels
fetchAsPullRequest(repository.owner, repository.name, form.requestUserName, form.requestRepositoryName, form.requestBranch, issueId) if(writable){
form.labelNames.map { value =>
// record activity val labels = getLabels(owner, name)
recordPullRequestActivity(repository.owner, repository.name, loginUserName, issueId, form.title) value.split(",").foreach { labelName =>
labels.find(_.labelName == labelName).map { label =>
// call web hook registerIssueLabel(repository.owner, repository.name, issueId, label.labelId)
callPullRequestWebHook("opened", repository, issueId, context.baseUrl, context.loginAccount.get) }
}
// notifications }
getIssue(repository.owner, repository.name, issueId.toString) foreach { issue =>
Notifier().toNotify(repository, issue, form.content.getOrElse("")){
Notifier.msgPullRequest(s"${context.baseUrl}/${repository.owner}/${repository.name}/pull/${issueId}")
} }
}
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}") // fetch requested branch
fetchAsPullRequest(owner, name, form.requestUserName, form.requestRepositoryName, form.requestBranch, issueId)
// record activity
recordPullRequestActivity(owner, name, loginUserName, issueId, form.title)
// call web hook
callPullRequestWebHook("opened", repository, issueId, context.baseUrl, context.loginAccount.get)
// notifications
getIssue(owner, name, issueId.toString) foreach { issue =>
Notifier().toNotify(repository, issue, form.content.getOrElse("")){
Notifier.msgPullRequest(s"${context.baseUrl}/${owner}/${name}/pull/${issueId}")
}
}
redirect(s"/${owner}/${name}/pull/${issueId}")
}
}) })
/** /**

View File

@@ -16,7 +16,7 @@
<div class="box issue-box"> <div class="box issue-box">
<div class="box-content"> <div class="box-content">
<span id="error-title" class="error"></span> <span id="error-title" class="error"></span>
<input type="text" name="title" value="" placeholder="Title" style="width: 565px;" autofocus/> <input type="text" name="title" value="" placeholder="Title" style="width: 690px;" autofocus/>
@helper.html.preview( @helper.html.preview(
repository = repository, repository = repository,
content = "", content = "",
@@ -24,14 +24,14 @@
enableRefsLink = true, enableRefsLink = true,
enableTaskList = true, enableTaskList = true,
hasWritePermission = hasWritePermission, hasWritePermission = hasWritePermission,
style = "width: 565px; height: 200px; max-height: 250px;", style = "width: 690px; height: 200px; max-height: 250px;",
elastic = true elastic = true
) )
<div class="align-right">
<input type="submit" class="btn btn-success" value="Submit new issue"/>
</div>
</div> </div>
</div> </div>
<div class="pull-right">
<input type="submit" class="btn btn-success" value="Submit new issue"/>
</div>
</div> </div>
<div class="span2"> <div class="span2">
@issueinfo(None, Nil, Nil, collaborators, milestones.map(x => (x, 0, 0)), labels, hasWritePermission, repository) @issueinfo(None, Nil, Nil, collaborators, milestones.map(x => (x, 0, 0)), labels, hasWritePermission, repository)

View File

@@ -9,7 +9,11 @@
repository: gitbucket.core.service.RepositoryService.RepositoryInfo, repository: gitbucket.core.service.RepositoryService.RepositoryInfo,
originRepository: gitbucket.core.service.RepositoryService.RepositoryInfo, originRepository: gitbucket.core.service.RepositoryService.RepositoryInfo,
forkedRepository: gitbucket.core.service.RepositoryService.RepositoryInfo, forkedRepository: gitbucket.core.service.RepositoryService.RepositoryInfo,
hasWritePermission: Boolean)(implicit context: gitbucket.core.controller.Context) hasOriginWritePermission: Boolean,
hasForkedWritePermission: Boolean,
collaborators: List[String],
milestones: List[gitbucket.core.model.Milestone],
labels: List[gitbucket.core.model.Label])(implicit context: gitbucket.core.controller.Context)
@import context._ @import context._
@import gitbucket.core.view.helpers._ @import gitbucket.core.view.helpers._
@html.main(s"Pull Requests - ${repository.owner}/${repository.name}", Some(repository)){ @html.main(s"Pull Requests - ${repository.owner}/${repository.name}", Some(repository)){
@@ -47,27 +51,27 @@
<img src="@assets/common/images/indicator.gif"/> Checking... <img src="@assets/common/images/indicator.gif"/> Checking...
</div> </div>
</div> </div>
@if(commits.nonEmpty && hasWritePermission){ @if(commits.nonEmpty && hasForkedWritePermission){
<div style="margin-bottom: 10px;" id="create-pull-request"> <div style="margin-bottom: 10px;" id="create-pull-request">
<a href="#" class="btn btn-success" id="show-form">Create pull request</a> <a href="#" class="btn btn-success" id="show-form">Create pull request</a>
</div> </div>
<div id="pull-request-form" @*class="box"*@ style="display: none; margin-bottom: 20px;"> <div id="pull-request-form" @*class="box"*@ style="display: none; margin-bottom: 20px;">
<form method="POST" action="@path/@originRepository.owner/@originRepository.name/pulls/new" validate="true"> <form method="POST" action="@path/@originRepository.owner/@originRepository.name/pulls/new" validate="true">
<div class="row-fluid"> <div class="row-fluid">
<div class="span9"> <div class="span10">
<div class="issue-avatar-image">@avatar(loginAccount.get.userName, 48)</div> <div class="issue-avatar-image">@avatar(loginAccount.get.userName, 48)</div>
<div class="box issue-box"> <div class="box issue-box">
<div class="box-content"> <div class="box-content">
<span class="error" id="error-title"></span> <span class="error" id="error-title"></span>
<input type="text" name="title" style="width: 580px" placeholder="Title"/> <input type="text" name="title" style="width: 690px" placeholder="Title"/>
@helper.html.preview( @helper.html.preview(
repository = repository, repository = repository,
content = "", content = "",
enableWikiLink = false, enableWikiLink = false,
enableRefsLink = true, enableRefsLink = true,
enableTaskList = true, enableTaskList = true,
hasWritePermission = hasWritePermission, hasWritePermission = hasForkedWritePermission,
style = "width: 580px; height: 200px;" style = "width: 690px; height: 200px;"
) )
<input type="hidden" name="targetUserName" value="@originRepository.owner"/> <input type="hidden" name="targetUserName" value="@originRepository.owner"/>
<input type="hidden" name="targetBranch" value="@originId"/> <input type="hidden" name="targetBranch" value="@originId"/>
@@ -76,14 +80,15 @@
<input type="hidden" name="requestBranch" value="@forkedId"/> <input type="hidden" name="requestBranch" value="@forkedId"/>
<input type="hidden" name="commitIdFrom" value="@sourceId"/> <input type="hidden" name="commitIdFrom" value="@sourceId"/>
<input type="hidden" name="commitIdTo" value="@commitId"/> <input type="hidden" name="commitIdTo" value="@commitId"/>
<div class="align-right">
<input type="submit" class="btn btn-success" value="Create pull request"/>
</div>
</div> </div>
</div> </div>
<div class="pull-right">
<input type="submit" class="btn btn-success" value="Create pull request"/>
</div>
</div> </div>
</div> <div class="span2">
<div class="span3"> @gitbucket.core.issues.html.issueinfo(None, Nil, Nil, collaborators, milestones.map((_, 0, 0)), labels, hasOriginWritePermission, repository)
</div>
</div> </div>
</form> </form>
</div> </div>
@@ -127,9 +132,9 @@
</table> </table>
</div> </div>
@pulls.html.commits(commits, Some(comments), repository) @pulls.html.commits(commits, Some(comments), repository)
@helper.html.diff(diffs, repository, Some(commitId), Some(sourceId), true, None, hasWritePermission, false) @helper.html.diff(diffs, repository, Some(commitId), Some(sourceId), true, None, hasForkedWritePermission, false)
<p>Showing you all comments on commits in this comparison.</p> <p>Showing you all comments on commits in this comparison.</p>
@issues.html.commentlist(None, comments, hasWritePermission, repository, None) @issues.html.commentlist(None, comments, hasForkedWritePermission, repository, None)
} }
} }
} }
@@ -174,7 +179,7 @@ $(function(){
$('#show-form').click(); $('#show-form').click();
} }
@if(hasWritePermission){ @if(hasForkedWritePermission){
function checkConflict(from, to){ function checkConflict(from, to){
$('.check-conflict').show(); $('.check-conflict').show();
$.get('@url(repository)/compare/' + from + '...' + to + '/mergecheck', $.get('@url(repository)/compare/' + from + '...' + to + '/mergecheck',

View File

@@ -60,6 +60,10 @@ h6 {
.head .octicon,.head .mega-octicon{ .head .octicon,.head .mega-octicon{
color : #BBB; color : #BBB;
} }
.align-right {
text-align: right;
}
/* ======================================================================== */ /* ======================================================================== */
/* Global Header */ /* Global Header */
/* ======================================================================== */ /* ======================================================================== */