]> source.dussan.org Git - gitblit.git/commitdiff
Groovy script tweaks
authorJames Moger <james.moger@gitblit.com>
Mon, 19 Dec 2011 13:51:30 +0000 (08:51 -0500)
committerJames Moger <james.moger@gitblit.com>
Mon, 19 Dec 2011 13:51:30 +0000 (08:51 -0500)
groovy/blockpush.groovy
groovy/jenkins.groovy
groovy/sendemail.groovy

index eac7d3f57ad0c801c0640b40a9c56c38c0779200..a4cede3e9d53ad3e02f3824223fe7464b83e5a70 100644 (file)
@@ -67,10 +67,10 @@ logger.info("blockpush hook triggered by ${user.username} for ${repository.name}
  */\r
 def blocked = false\r
 switch (repository.name) {\r
-       case "ex@mple.git":\r
+       case 'ex@mple.git':\r
                for (ReceiveCommand command : commands) {\r
                        def updatedRef = command.refName\r
-                       if (updatedRef.equals("refs/heads/master")) {\r
+                       if (updatedRef.equals('refs/heads/master')) {\r
                                // to reject a command set it's result to anything other than Result.NOT_ATTEMPTED\r
                                command.setResult(Result.REJECTED_OTHER_REASON, "You are not permitted to write to ${repository.name}:${updatedRef}")\r
                                blocked = true\r
index df4e588f32da414f195857fd5c1e2c1d7e1e4276..443e51de6d706355b41a64424902df9e9cdaf70a 100644 (file)
@@ -62,10 +62,10 @@ logger.info("jenkins hook triggered by ${user.username} for ${repository.name}")
 \r
 // define your jenkins url here or set groovy.jenkinsServer in \r
 // gitblit.properties or web.xml\r
-def jenkinsUrl = gitblit.getString("groovy.jenkinsServer", "http://yourserver/jenkins")\r
+def jenkinsUrl = gitblit.getString('groovy.jenkinsServer', 'http://yourserver/jenkins')\r
 \r
 // define the trigger url\r
-def triggerUrl = jenkinsUrl + "/git/notifyCommit?url=" + url + "/git/" + repository.name\r
+def triggerUrl = jenkinsUrl + "/git/notifyCommit?url=$url/git/$repository.name"\r
 \r
 // trigger the build\r
 new URL(triggerUrl).getContent()\r
index 471ede8a202332a42f457182d812b4131d79a9b9..f90d7ff5811a900aa9cb76f122237145bce6e674 100644 (file)
@@ -71,16 +71,16 @@ Repository r = gitblit.getRepository(repository.name)
 \r
 // reuse some existing repository config settings, if available\r
 Config config = r.getConfig()\r
-def mailinglist = config.getString("hooks", null, "mailinglist")\r
-def emailprefix = config.getString("hooks", null, "emailprefix")\r
+def mailinglist = config.getString('hooks', null, 'mailinglist')\r
+def emailprefix = config.getString('hooks', null, 'emailprefix')\r
 \r
 // set default values\r
 def toAddresses = []\r
 if (emailprefix == null)\r
-       emailprefix = "[Gitblit]"\r
+emailprefix = '"[Gitblit]'\r
 \r
 if (mailinglist != null) {\r
-       def addrs = mailinglist.split("(,|\\s)")\r
+       def addrs = mailinglist.split('(,|\\s)')\r
        toAddresses.addAll(addrs)\r
 }\r
 \r
@@ -92,45 +92,57 @@ toAddresses.addAll(repository.mailRecipients)
 \r
 // special custom cases\r
 switch(repository.name) {\r
-       case "ex@mple.git":\r
-               toAddresses.add "dev-team@somewhere.com"\r
-               toAddresses.add "qa-team@somewhere.com"\r
+       case 'ex@mple.git':\r
+               toAddresses.add 'dev-team@somewhere.com'\r
+               toAddresses.add 'qa-team@somewhere.com'\r
                break\r
 }\r
 \r
+// define the summary and commit urls\r
+def summaryUrl\r
+def commitUrl\r
+if (gitblit.getBoolean(Keys.web.mountParameters, true)) {\r
+       summaryUrl = url + '/summary/' + repository.name.replace('/', gitblit.getString(Keys.web.forwardSlashCharacter, '/'))\r
+       commitUrl = url + '/commit/'\r
+} else {\r
+       summaryUrl = url + '/summary?r=' + repository.name\r
+       commitUrl = url + '/commit?h='\r
+}\r
+\r
 // construct a simple text summary of the changes contained in the push\r
 def commitCount = 0\r
-def changes = ""\r
-def table = { it.id.name[0..8] + " " + it.authorIdent.name.padRight(20, " ") + it.shortMessage }\r
+def changes = ''\r
+def table = { it.authorIdent.name.padRight(25, ' ') + it.shortMessage + "\n$commitUrl" + it.id.name }\r
 for (command in commands) {\r
+       def ref = command.refName.substring('refs/heads/'.length())\r
        switch (command.type) {\r
                case ReceiveCommand.Type.CREATE:\r
                        def commits = JGitUtils.getRevLog(r, command.oldId.name, command.newId.name)\r
                        commitCount += commits.size()\r
                        // new branch commits table\r
-                       changes += "created ${command.refName}\n\n"\r
-                       changes += commits.collect(table).join("\n")\r
-                       changes += "\n"\r
+                       changes += "created $ref ($commits.size commits)\n\n"\r
+                       changes += commits.collect(table).join('\n\n')\r
+                       changes += '\n'\r
                        break\r
                case ReceiveCommand.Type.UPDATE:\r
                        def commits = JGitUtils.getRevLog(r, command.oldId.name, command.newId.name)\r
                        commitCount += commits.size()\r
                        // fast-forward branch commits table\r
-                       changes += "updated ${command.refName}\n\n"\r
-                       changes += commits.collect(table).join("\n")\r
-                       changes += "\n"\r
+                       changes += "updated $ref ($commits.size commits)\n\n"\r
+                       changes += commits.collect(table).join('\n\n')\r
+                       changes += '\n'\r
                        break\r
                case ReceiveCommand.Type.UPDATE_NONFASTFORWARD:\r
                        def commits = JGitUtils.getRevLog(r, command.oldId.name, command.newId.name)\r
                        commitCount += commits.size()\r
                        // non-fast-forward branch commits table\r
-                       changes += "updated ${command.refName} (NON fast-forward)\n\n"\r
-                       changes += commits.collect(table).join("\n")\r
-                       changes += "\n"\r
+                       changes += "updated $ref [NON fast-forward] ($commits.size commits)\n\n"\r
+                       changes += commits.collect(table).join('\n\n')\r
+                       changes += '\n'\r
                        break\r
                case ReceiveCommand.Type.DELETE:\r
                        // deleted branch\r
-                       changes += "deleted ${command.refName}\n\n"\r
+                       changes += "deleted $ref\n\n"\r
                        break\r
                default:\r
                        break\r
@@ -139,17 +151,5 @@ for (command in commands) {
 // close the repository reference\r
 r.close()\r
 \r
-// build a link to the summary page, either mounted or parameterized\r
-def summaryUrl\r
-if (gitblit.getBoolean(Keys.web.mountParameters, true))\r
-       summaryUrl = url + "/summary/" + repository.name.replace("/", gitblit.getString(Keys.web.forwardSlashCharacter, "/"))\r
-else\r
-       summaryUrl = url + "/summary?r=" + repository.name\r
-\r
-// create the message body\r
-def msg = """${summaryUrl}\r
-\r
-${changes}"""\r
-\r
 // tell Gitblit to send the message (Gitblit filters duplicate addresses)\r
-gitblit.sendEmail("${emailprefix} ${user.username} pushed ${commitCount} commits => ${repository.name}", msg, toAddresses)
\ No newline at end of file
+gitblit.sendEmail("$emailprefix $user.username pushed $commitCount commits => $repository.name", "$summaryUrl\n\n$changes", toAddresses)
\ No newline at end of file