Add "Compare & pull request" button on the top of the repository viewer (#1476)

This commit is contained in:
Naoki Takezoe
2017-12-09 04:52:21 +09:00
committed by GitHub
parent 6bd58b0c45
commit 332a1b4b0b
3 changed files with 59 additions and 14 deletions

View File

@@ -502,6 +502,27 @@ trait PullRequestsControllerBase extends ControllerBase {
} }
}) })
ajaxGet("/:owner/:repository/pulls/proposals")(readableUsersOnly { repository =>
(for {
parentUserName <- repository.repository.parentUserName
parentRepoName <- repository.repository.parentRepositoryName
parentRepository <- getRepository(parentUserName, parentRepoName).orElse(Some(repository))
} yield {
val branches = JGitUtil.getBranches(
owner = repository.owner,
name = repository.name,
defaultBranch = repository.repository.defaultBranch,
origin = repository.repository.originUserName.isEmpty
)
.filter(x => x.mergeInfo.map(_.ahead).getOrElse(0) > 0 && x.mergeInfo.map(_.behind).getOrElse(0) == 0)
.sortBy(br => (br.mergeInfo.isEmpty, br.commitTime))
.map(_.name)
.reverse
html.proposals(branches, parentRepository, repository)
}).getOrElse(NotFound())
})
/** /**
* Parses branch identifier and extracts owner and branch name as tuple. * Parses branch identifier and extracts owner and branch name as tuple.
* *

View File

@@ -0,0 +1,13 @@
@(branches: Seq[String],
parent: gitbucket.core.service.RepositoryService.RepositoryInfo,
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers
@if(branches.nonEmpty){
@branches.map { branch =>
<div class="box-content" style="line-height: 20pt; margin-bottom: 6px; padding: 10px 6px 10px 10px; background-color: #fff9ea">
<strong><i class="menu-icon octicon octicon-git-branch"></i><span class="muted">@branch</span></strong>
<a class="pull-right btn btn-success" style="position: relative; top: -4px;"
href="@helpers.url(repository)/compare/@{parent.owner}:@{parent.repository.defaultBranch}...@{repository.owner}:@{branch}">Compare & pull request</a>
</div>
}
}

View File

@@ -29,6 +29,7 @@
</p> </p>
} }
} }
<div id="pull-request-area"></div>
<div class="head" style="height: 24px;"> <div class="head" style="height: 24px;">
<div class="pull-right"> <div class="pull-right">
<div class="btn-group"> <div class="btn-group">
@@ -204,6 +205,7 @@
} }
} }
<script> <script>
$(function() {
@repository.sshUrl.map { sshUrl => @repository.sshUrl.map { sshUrl =>
$('#repository-url-http').click(function(){ $('#repository-url-http').click(function(){
$('#repository-url-proto').text('HTTP'); $('#repository-url-proto').text('HTTP');
@@ -219,4 +221,13 @@
$('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val()); $('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
}); });
} }
@if(pathList.isEmpty && hasWritePermission){
$.get('@{helpers.url(repository)}/pulls/proposals', function(res){
if(res) {
$('#pull-request-area').html(res);
}
});
}
});
</script> </script>