--- /dev/null
+/*\r
+ * Copyright 2011 Wolfgang Gassler gassler.org\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+import com.gitblit.GitBlit\r
+import com.gitblit.Keys\r
+import com.gitblit.models.RepositoryModel\r
+import com.gitblit.models.TeamModel\r
+import com.gitblit.models.UserModel\r
+import com.gitblit.utils.JGitUtils\r
+import java.text.SimpleDateFormat\r
+import org.eclipse.jgit.lib.Repository\r
+import org.eclipse.jgit.lib.Config\r
+import org.eclipse.jgit.revwalk.RevCommit\r
+import org.eclipse.jgit.transport.ReceiveCommand\r
+import org.eclipse.jgit.transport.ReceiveCommand.Result\r
+import org.slf4j.Logger\r
+import org.eclipse.jgit.lib.IndexDiff\r
+import org.eclipse.jgit.lib.Constants\r
+import com.gitblit.utils.DiffUtils\r
+\r
+/**\r
+ * Gitblit Post-Receive Hook: thebuggenie\r
+ * www.thebuggenie.com\r
+ * \r
+ * Submit the commit information to thebuggenie bug tracker by calling thebuggenie client tool\r
+ * \r
+ * Config of the Script:\r
+ * \r
+ * Setup a custom gitblit field in the proprties file of gitblit by adding the following line\r
+ * groovy.customFields = "thebuggenieProjectId=TheBugGennie project id (used for thebuggenie hoocks)"\r
+ * This field allows to specify the project id of thebuggenie project in the edit section of gitblit\r
+ * \r
+ * Furthermore you need to set the path to thebuggenie client tool by adding the following property to\r
+ * the gitblit properties file\r
+ * thebuggenie.tbg_cli = /var/www/thebuggenie_root/tbg_cli\r
+ */\r
+\r
+// Indicate we have started the script\r
+logger.info("thebuggenie hook triggered by ${user.username} for ${repository.name}")\r
+\r
+//fetch the repository data\r
+Repository r = gitblit.getRepository(repository.name)\r
+\r
+//get project id which is defined in the git repo metadata\r
+def tbgProjectId = repository.customFields.thebuggenieProjectId\r
+//get path to the thebuggenie client tool which is defined in the gitblit proprties files\r
+def tbgCliPath = gitblit.getString('thebuggenie.tbg_cli', '/var/www/thebuggenie/tbg_cli')\r
+def tbgCliDirPath = new File(tbgCliPath).getParent()\r
+\r
+for(command in commands) {\r
+ //fetch all pushed commits\r
+ def commits = JGitUtils.getRevLog(r, command.oldId.name, command.newId.name).reverse()\r
+ for (commit in commits) {\r
+ //get hashes and author data of commit\r
+ def oldhash = commit.getParent(0).getId().getName()\r
+ def newhash = commit.getId().getName()\r
+ def authorIdent = commit.getAuthorIdent()\r
+ def author = "${authorIdent.name} <${authorIdent.emailAddress}>"\r
+ //fetch all changed files of the commit\r
+ def files = JGitUtils.getFilesInCommit(r,commit)\r
+ def changedFiles = ""\r
+ for (f in files) {\r
+ //transform file data to the format which is needed by thebuggenie\r
+ changedFiles += f.changeType.toString().substring(0,1)+"\t${f.path}\n"\r
+ }\r
+ //ok let's submit all information to thebuggenie by calling the client tool\r
+// def shc = "$tbgCliPath vcs_integration:report_commit $tbgProjectId \"$author\" $newhash \"${commit.fullMessage}\" \"$changedFiles\" $oldhash ${commit.commitTime}"\r
+ def shc = [tbgCliPath, "vcs_integration:report_commit", tbgProjectId, author, newhash, commit.getFullMessage(), changedFiles, oldhash, commit.getCommitTime()];\r
+ logger.info("executing in path " + tbgCliDirPath + ": "+shc)\r
+ shc.execute(null, new File(tbgCliDirPath))\r
+ }\r
+}\r
+\r
+// close the repository reference\r
+r.close()\r