mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-05-07 12:26:32 +02:00
Issue and PR template per repository
This commit is contained in:
@@ -107,6 +107,7 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
getMilestones(owner, name),
|
||||
getLabels(owner, name),
|
||||
isIssueManageable(repository),
|
||||
getContentTemplate(repository, "ISSUE_TEMPLATE"),
|
||||
repository)
|
||||
}
|
||||
} else Unauthorized()
|
||||
|
||||
@@ -368,6 +368,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
forkedId,
|
||||
oldId.getName,
|
||||
newId.getName,
|
||||
getContentTemplate(originRepository, "PULL_REQUEST_TEMPLATE"),
|
||||
forkedRepository,
|
||||
originRepository,
|
||||
forkedRepository,
|
||||
|
||||
@@ -3,7 +3,14 @@ package gitbucket.core.service
|
||||
import gitbucket.core.controller.Context
|
||||
import gitbucket.core.model.{Collaborator, Repository, RepositoryOptions, Account, Role}
|
||||
import gitbucket.core.model.Profile._
|
||||
import gitbucket.core.plugin.PluginRegistry
|
||||
import gitbucket.core.util.JGitUtil
|
||||
import gitbucket.core.util.JGitUtil.FileInfo
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.Directory
|
||||
import gitbucket.core.util.FileUtil
|
||||
import gitbucket.core.util.StringUtil
|
||||
import org.eclipse.jgit.api.Git
|
||||
import profile.simple._
|
||||
|
||||
trait RepositoryService { self: AccountService =>
|
||||
@@ -416,6 +423,36 @@ trait RepositoryService { self: AccountService =>
|
||||
}
|
||||
.sortBy(_.userName asc).map(t => t.userName -> t.repositoryName).list
|
||||
|
||||
private val templateExtensions = Seq("md", "markdown")
|
||||
|
||||
/**
|
||||
* Returns content of template set per repository.
|
||||
*
|
||||
* @param repository the repository information
|
||||
* @param fileBaseName the file basename without extension of template
|
||||
* @return The content of template if the repository has it, otherwise empty string.
|
||||
*/
|
||||
def getContentTemplate(repository: RepositoryInfo, fileBaseName: String)(implicit s: Session): String = {
|
||||
val withExtFilenames = templateExtensions.map(extension => s"${fileBaseName.toLowerCase()}.${extension}")
|
||||
|
||||
def choiceTemplate(files: List[FileInfo]): Option[FileInfo] =
|
||||
files.find { f =>
|
||||
f.name.toLowerCase() == fileBaseName
|
||||
}.orElse {
|
||||
files.find(f => withExtFilenames.contains(f.name.toLowerCase()))
|
||||
}
|
||||
|
||||
// Get template file from project root. When didn't find, will lookup default folder.
|
||||
using(Git.open(Directory.getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||
choiceTemplate(JGitUtil.getFileList(git, repository.repository.defaultBranch, ".")).orElse {
|
||||
choiceTemplate(JGitUtil.getFileList(git, repository.repository.defaultBranch, ".gitbucket"))
|
||||
}.map { file =>
|
||||
JGitUtil.getContentFromId(git, file.id, true).collect {
|
||||
case bytes if FileUtil.isText(bytes) => StringUtil.convertFromByteArray(bytes)
|
||||
}
|
||||
} getOrElse None
|
||||
} getOrElse ""
|
||||
}
|
||||
}
|
||||
|
||||
object RepositoryService {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
milestones: List[gitbucket.core.model.Milestone],
|
||||
labels: List[gitbucket.core.model.Label],
|
||||
isManageable: Boolean,
|
||||
content: String,
|
||||
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
|
||||
@import gitbucket.core.view.helpers
|
||||
@gitbucket.core.html.main(s"New Issue - ${repository.owner}/${repository.name}", Some(repository)){
|
||||
@@ -13,7 +14,7 @@
|
||||
<input type="text" id="issue-title" name="title" class="form-control" value="" placeholder="Title" style="margin-bottom: 6px;" autofocus/>
|
||||
@gitbucket.core.helper.html.preview(
|
||||
repository = repository,
|
||||
content = "",
|
||||
content = content,
|
||||
enableWikiLink = false,
|
||||
enableRefsLink = true,
|
||||
enableLineBreaks = true,
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
forkedId: String,
|
||||
sourceId: String,
|
||||
commitId: String,
|
||||
content: String,
|
||||
repository: gitbucket.core.service.RepositoryService.RepositoryInfo,
|
||||
originRepository: gitbucket.core.service.RepositoryService.RepositoryInfo,
|
||||
forkedRepository: gitbucket.core.service.RepositoryService.RepositoryInfo,
|
||||
@@ -59,7 +60,7 @@
|
||||
<input type="text" name="title" value="@title" class="form-control" style="margin-bottom: 6px;" placeholder="Title"/>
|
||||
@gitbucket.core.helper.html.preview(
|
||||
repository = repository,
|
||||
content = "",
|
||||
content = content,
|
||||
enableWikiLink = false,
|
||||
enableRefsLink = true,
|
||||
enableLineBreaks = true,
|
||||
|
||||
Reference in New Issue
Block a user