mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-13 00:45:49 +01:00
Add "Compare & pull request" button on the top of the repository viewer (#1476)
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
13
src/main/twirl/gitbucket/core/pulls/proposals.scala.html
Normal file
13
src/main/twirl/gitbucket/core/pulls/proposals.scala.html
Normal 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>
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@
|
||||
</p>
|
||||
}
|
||||
}
|
||||
<div id="pull-request-area"></div>
|
||||
<div class="head" style="height: 24px;">
|
||||
<div class="pull-right">
|
||||
<div class="btn-group">
|
||||
@@ -204,19 +205,29 @@
|
||||
}
|
||||
}
|
||||
<script>
|
||||
@repository.sshUrl.map { sshUrl =>
|
||||
$('#repository-url-http').click(function(){
|
||||
$('#repository-url-proto').text('HTTP');
|
||||
$('#repository-url').val('@repository.httpUrl');
|
||||
$('#repository-clone-url').attr('href', '@RepositoryService.openRepoUrl(repository.httpUrl)')
|
||||
$('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
|
||||
});
|
||||
$(function() {
|
||||
@repository.sshUrl.map { sshUrl =>
|
||||
$('#repository-url-http').click(function(){
|
||||
$('#repository-url-proto').text('HTTP');
|
||||
$('#repository-url').val('@repository.httpUrl');
|
||||
$('#repository-clone-url').attr('href', '@RepositoryService.openRepoUrl(repository.httpUrl)')
|
||||
$('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
|
||||
});
|
||||
|
||||
$('#repository-url-ssh').click(function(){
|
||||
$('#repository-url-proto').text('SSH');
|
||||
$('#repository-url').val('@sshUrl');
|
||||
$('#repository-clone-url').attr('href', '@RepositoryService.openRepoUrl(sshUrl)');
|
||||
$('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
|
||||
});
|
||||
}
|
||||
$('#repository-url-ssh').click(function(){
|
||||
$('#repository-url-proto').text('SSH');
|
||||
$('#repository-url').val('@sshUrl');
|
||||
$('#repository-clone-url').attr('href', '@RepositoryService.openRepoUrl(sshUrl)');
|
||||
$('#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>
|
||||
|
||||
Reference in New Issue
Block a user