From c8b26c51aa67fc9345b624e36aab6f819e7eed74 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Sun, 25 Nov 2012 11:35:31 -0500 Subject: [PATCH] Gitblit Certificate Authority revisions. Eliminate certificate scripts. --- groovy/sendmail-html.groovy | 227 ++++++++++++++++++++++++-------------------------------- 1 files changed, 99 insertions(+), 128 deletions(-) diff --git a/groovy/sendmail-html.groovy b/groovy/sendmail-html.groovy index fb89a14..e0cdecd 100644 --- a/groovy/sendmail-html.groovy +++ b/groovy/sendmail-html.groovy @@ -89,7 +89,7 @@ com.gitblit.models.UserModel userModel = user // Indicate we have started the script -logger.info("sendmail hook triggered by ${user.username} for ${repository.name}") +logger.info("sendmail-html hook triggered by ${user.username} for ${repository.name}") /* * Primitive email notification. @@ -115,7 +115,7 @@ } // add all mailing lists defined in gitblit.properties or web.xml -toAddresses.addAll(gitblit.getStrings(Keys.mail.mailingLists)) +toAddresses.addAll(GitBlit.getStrings(Keys.mail.mailingLists)) // add all team mailing lists def teams = gitblit.getRepositoryTeams(repository) @@ -135,9 +135,10 @@ def baseCommitUrl = url + "/commit?r=$repo&h=" def baseBlobDiffUrl = url + "/blobdiff/?r=$repo&h=" def baseCommitDiffUrl = url + "/commitdiff/?r=$repo&h=" +def forwardSlashChar = gitblit.getString(Keys.web.forwardSlashCharacter, '/') if (gitblit.getBoolean(Keys.web.mountParameters, true)) { - repo = repo.replace('/', gitblit.getString(Keys.web.forwardSlashCharacter, '/')).replace('/', '%2F') + repo = repo.replace('/', forwardSlashChar).replace('/', '%2F') summaryUrl = url + "/summary/$repo" baseCommitUrl = url + "/commit/$repo/" baseBlobDiffUrl = url + "/blobdiff/$repo/" @@ -151,6 +152,9 @@ def baseCommitDiffUrl def baseBlobDiffUrl def mountParameters + def forwardSlashChar + def includeGravatar + def shortCommitIdLength def commitCount = 0 def commands def writer = new StringWriter(); @@ -158,109 +162,58 @@ def writeStyle() { builder.style(type:"text/css", ''' - th, td { - padding: 2px; + .table td { + vertical-align: middle; } - thead { - text-align: left; - font-weight: bold; - } - thead tr { - border-bottom: 1px dotted #000; - } - a { - text-decoration: none; - } - .commits-table { - border-collapse: collapse; - font-family: sans-serif; - width: 100%; - } - .label-commit { - border-radius:4px; - background-color: #3A87AD; - padding: 2px 4px; - color: white; - vertical-align: baseline; - font-weight: bold; - font-family: monospace; - } - .label-add { - border-radius:4px; - background-color: green; - padding: 2px 4px; - color: white; - vertical-align: baseline; - font-weight: bold; - font-family: monospace; - } - .label-delete { - border-radius:4px; - background-color: grey; - padding: 2px 4px; - color: white; - vertical-align: baseline; - font-weight: bold; - font-family: monospace; - } - .label-rename { - border-radius:4px; - background-color: blue; - padding: 2px 4px; - color: white; - vertical-align: baseline; - font-weight: bold; - font-family: monospace; - } - .label-modify { - border-radius:4px; - background-color: orange; - padding: 2px 4px; - color: white; - vertical-align: baseline; - font-weight: bold; - font-family: monospace; - } - .label-copy { - border-radius:4px; - background-color: teal; - padding: 2px 4px; - color: white; - vertical-align: baseline; - font-weight: bold; - font-family: monospace; + tr.noborder td { + border: none; + padding-top: 0px; } .gravatar-column { width: 5%; } .author-column { - width: 10%; + width: 20%; } .commit-column { width: 5%; } .status-column { width: 10%; - padding-bottom: 5px; - padding-top: 5px; + } + .table-disable-hover.table tbody tr:hover td, + .table-disable-hover.table tbody tr:hover th { + background-color: inherit; + } + .table-disable-hover.table-striped tbody tr:nth-child(odd):hover td, + .table-disable-hover.table-striped tbody tr:nth-child(odd):hover th { + background-color: #f9f9f9; } ''') } def writeBranchTitle(type, name, action, number) { - builder.h2 { - mkp.yield "$type " - span(style:"font-family: monospace;", name ) - mkp.yield " $action ($number commits)" + builder.div('class' : 'pageTitle') { + builder.span('class':'project') { + mkp.yield "$type " + span('class': 'repository', name ) + if (number > 0) { + mkp.yield " $action ($number commits)" + } else { + mkp.yield " $action" + } + } } } def writeBranchDeletedTitle(type, name) { - builder.h2 { - mkp.yield "$type " - span(style:"font-family: monospace;", name ) - mkp.yield " deleted" - } + builder.div('class' : 'pageTitle', 'style':'color:red') { + builder.span('class':'project') { + mkp.yield "$type " + span('class': 'repository', name ) + mkp.yield " deleted" + } + } } def commitUrl(RevCommit commit) { @@ -272,7 +225,7 @@ } def encoded(String path) { - path.replace('/', '!') + path.replace('/', forwardSlashChar).replace('/', '%2F') } def blobDiffUrl(objectId, path) { @@ -285,12 +238,12 @@ } - def writeCommitTable(commits) { + def writeCommitTable(commits, includeChangedPaths=true) { // Write commits table - builder.table('class':"commits-table") { + builder.table('class':"table table-disable-hover") { thead { tr { - th(colspan:2, "Author") + th(colspan: includeGravatar ? 2 : 1, "Author") th( "Commit" ) th( "Message" ) } @@ -301,84 +254,90 @@ for (commit in commits) { writeCommit(commit) - // Write detail on that particular commit - tr { - td (colspan:3) - td { writeStatusTable(commit) } - } + if (includeChangedPaths) { + // Write detail on that particular commit + tr('class' : 'noborder') { + td (colspan: includeGravatar ? 3 : 2) + td (colspan:2) { writeStatusTable(commit) } + } + } } } } } def writeCommit(commit) { - def abbreviated = repository.newObjectReader().abbreviate(commit.id, 6).name() + def abbreviated = repository.newObjectReader().abbreviate(commit.id, shortCommitIdLength).name() def author = commit.authorIdent.name def email = commit.authorIdent.emailAddress def message = commit.shortMessage builder.tr { - td('class':"gravatar-column") { - img(src:gravatarUrl(email)) - } - td('class':"author-column") { p(author) } + if (includeGravatar) { + td('class':"gravatar-column") { + img(src:gravatarUrl(email), 'class':"gravatar") + } + } + td('class':"author-column", author) td('class':"commit-column") { a(href:commitUrl(commit)) { - span('class':"label-commit", abbreviated ) + span('class':"label label-info", abbreviated ) } } td { mkp.yield message - a(href:commitDiffUrl(commit), " [commitdiff]" ) + a('class':'link', href:commitDiffUrl(commit), " [commitdiff]" ) } } } - def writeStatusLabel(style, label) { - builder.span('class' : style, label ) + def writeStatusLabel(style, tooltip) { + builder.span('class' : style, 'title' : tooltip ) } - def writeAddStatusLine(ObjectId id, FileHeader header) { - builder.td('class':"status-column") { - a(href:blobDiffUrl(id, header.newPath)) { writeStatusLabel("label-add", "add") } + def writeAddStatusLine(ObjectId id, FileHeader header) { + builder.td('class':'changeType') { + writeStatusLabel("addition", "addition") } builder.td { - span(style:'font-family: monospace;', header.newPath) + a(href:blobDiffUrl(id, header.newPath), header.newPath) } } def writeCopyStatusLine(ObjectId id, FileHeader header) { - builder.td('class':"status-column") { - a(href:blobDiffUrl(id, header.newPath)) { writeStatusLabel("label-copy", "copy") } + builder.td('class':'changeType') { + writeStatusLabel("rename", "rename") } builder.td() { - span(style : "font-family: monospace; ", header.oldPath + " copied to " + header.newPath) + a(href:blobDiffUrl(id, header.newPath), header.oldPath + " copied to " + header.newPath) } } def writeDeleteStatusLine(ObjectId id, FileHeader header) { - builder.td('class':"status-column") { - a(href:blobDiffUrl(id, header.oldPath)) { writeStatusLabel("label-delete", "delete") } + builder.td('class':'changeType') { + writeStatusLabel("deletion", "deletion") } builder.td() { - span(style : "font-family: monospace; ", header.oldPath) + a(href:blobDiffUrl(id, header.oldPath), header.oldPath) } } def writeModifyStatusLine(ObjectId id, FileHeader header) { - builder.td('class':"status-column") { - a(href:blobDiffUrl(id, header.oldPath)) { writeStatusLabel("label-modify", "modify") } + builder.td('class':'changeType') { + writeStatusLabel("modification", "modification") } builder.td() { - span(style : "font-family: monospace; ", header.oldPath) + a(href:blobDiffUrl(id, header.oldPath), header.oldPath) } } def writeRenameStatusLine(ObjectId id, FileHeader header) { - builder.td('class':"status-column") { - a(href:blobDiffUrl(id, header.newPath)) { writeStatusLabel("label-rename", "rename") } + builder.td('class':'changeType') { + writeStatusLabel("rename", "rename") } builder.td() { - span(style : "font-family: monospace; ", header.olPath + " -> " + header.newPath) + mkp.yield header.oldPath + mkp.yieldUnescaped "<b> -&rt; </b>" + a(href:blobDiffUrl(id, header.newPath), header.newPath) } } @@ -420,7 +379,7 @@ new CanonicalTreeParser(null, rw.objectReader, commit.tree)) } // Write status table - builder.table('class':"commits-table") { + builder.table('class':"plain") { tbody() { for (DiffEntry entry in diffs) { FileHeader header = formatter.toFileHeader(entry) @@ -467,11 +426,14 @@ head { link(rel:"stylesheet", href:"${url}/bootstrap/css/bootstrap.css") link(rel:"stylesheet", href:"${url}/gitblit.css") + link(rel:"stylesheet", href:"${url}/bootstrap/css/bootstrap-responsive.css") writeStyle() } body { writeNavbar() + + div('class':"container") { for (command in commands) { def ref = command.refName @@ -485,12 +447,17 @@ switch (command.type) { case ReceiveCommand.Type.CREATE: - def commits = JGitUtils.getRevLog(repository, command.oldId.name, command.newId.name).reverse() - commitCount += commits.size() - // new branch - // Write header - writeBranchTitle(refType, ref, "created", commits.size()) - writeCommitTable(commits) + def commits = JGitUtils.getRevLog(repository, command.oldId.name, command.newId.name).reverse() + commitCount += commits.size() + if (refType == 'Branch') { + // new branch + writeBranchTitle(refType, ref, "created", commits.size()) + writeCommitTable(commits, true) + } else { + // new tag + writeBranchTitle(refType, ref, "created", 0) + writeCommitTable(commits, false) + } break case ReceiveCommand.Type.UPDATE: def commits = JGitUtils.getRevLog(repository, command.oldId.name, command.newId.name).reverse() @@ -516,6 +483,7 @@ break } } + } } } writer.toString() @@ -528,9 +496,12 @@ mailWriter.baseCommitUrl = baseCommitUrl mailWriter.baseBlobDiffUrl = baseBlobDiffUrl mailWriter.baseCommitDiffUrl = baseCommitDiffUrl +mailWriter.forwardSlashChar = forwardSlashChar mailWriter.commands = commands mailWriter.url = url -mailWriter.mountParameters = gitblit.getBoolean(Keys.web.mountParameters, true) +mailWriter.mountParameters = GitBlit.getBoolean(Keys.web.mountParameters, true) +mailWriter.includeGravatar = GitBlit.getBoolean(Keys.web.allowGravatar, true) +mailWriter.shortCommitIdLength = GitBlit.getInteger(Keys.web.shortCommitIdLength, 8) def content = mailWriter.write() @@ -539,6 +510,6 @@ // tell Gitblit to send the message (Gitblit filters duplicate addresses) def repositoryName = repository.name.substring(0, repository.name.length() - 4) -gitblit.sendHtmlMail("${emailprefix}[$repositoryName] ${userModel.displayName} pushed ${mailWriter.commitCount} commits", +gitblit.sendHtmlMail("${emailprefix} ${userModel.displayName} pushed ${mailWriter.commitCount} commits => $repositoryName", content, toAddresses) -- Gitblit v1.9.1