選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

thebuggenie.groovy 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright 2011 Wolfgang Gassler gassler.org
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import com.gitblit.GitBlit
  17. import com.gitblit.Keys
  18. import com.gitblit.models.RepositoryModel
  19. import com.gitblit.models.TeamModel
  20. import com.gitblit.models.UserModel
  21. import com.gitblit.utils.JGitUtils
  22. import java.text.SimpleDateFormat
  23. import org.eclipse.jgit.lib.Repository
  24. import org.eclipse.jgit.lib.Config
  25. import org.eclipse.jgit.revwalk.RevCommit
  26. import org.eclipse.jgit.transport.ReceiveCommand
  27. import org.eclipse.jgit.transport.ReceiveCommand.Result
  28. import org.slf4j.Logger
  29. import org.eclipse.jgit.lib.IndexDiff
  30. import org.eclipse.jgit.lib.Constants
  31. import com.gitblit.utils.DiffUtils
  32. /**
  33. * Gitblit Post-Receive Hook: thebuggenie
  34. * www.thebuggenie.com
  35. *
  36. * Submit the commit information to thebuggenie bug tracker by calling thebuggenie client tool
  37. *
  38. * Config of the Script:
  39. *
  40. * Setup a custom gitblit field in the proprties file of gitblit by adding the following line
  41. * groovy.customFields = "thebuggenieProjectId=TheBugGennie project id (used for thebuggenie hoocks)"
  42. * This field allows to specify the project id of thebuggenie project in the edit section of gitblit
  43. *
  44. * Furthermore you need to set the path to thebuggenie client tool by adding the following property to
  45. * the gitblit properties file
  46. * thebuggenie.tbg_cli = /var/www/thebuggenie_root/tbg_cli
  47. */
  48. // Indicate we have started the script
  49. logger.info("thebuggenie hook triggered by ${user.username} for ${repository.name}")
  50. //fetch the repository data
  51. Repository r = gitblit.getRepository(repository.name)
  52. //get project id which is defined in the git repo metadata
  53. def tbgProjectId = repository.customFields.thebuggenieProjectId
  54. //get path to the thebuggenie client tool which is defined in the gitblit proprties files
  55. def tbgCliPath = gitblit.getString('thebuggenie.tbg_cli', '/var/www/thebuggenie/tbg_cli')
  56. def tbgCliDirPath = new File(tbgCliPath).getParent()
  57. for(command in commands) {
  58. //fetch all pushed commits
  59. def commits = JGitUtils.getRevLog(r, command.oldId.name, command.newId.name).reverse()
  60. for (commit in commits) {
  61. //get hashes and author data of commit
  62. def oldhash = commit.getParent(0).getId().getName()
  63. def newhash = commit.getId().getName()
  64. def authorIdent = commit.getAuthorIdent()
  65. def author = "${authorIdent.name} <${authorIdent.emailAddress}>"
  66. //fetch all changed files of the commit
  67. def files = JGitUtils.getFilesInCommit(r,commit)
  68. def changedFiles = ""
  69. for (f in files) {
  70. //transform file data to the format which is needed by thebuggenie
  71. changedFiles += f.changeType.toString().substring(0,1)+"\t${f.path}\n"
  72. }
  73. //ok let's submit all information to thebuggenie by calling the client tool
  74. // def shc = "$tbgCliPath vcs_integration:report_commit $tbgProjectId \"$author\" $newhash \"${commit.fullMessage}\" \"$changedFiles\" $oldhash ${commit.commitTime}"
  75. def shc = [tbgCliPath, "vcs_integration:report_commit", tbgProjectId, author, newhash, commit.getFullMessage(), changedFiles, oldhash, commit.getCommitTime()];
  76. logger.info("executing in path " + tbgCliDirPath + ": "+shc)
  77. shc.execute(null, new File(tbgCliDirPath))
  78. }
  79. }
  80. // close the repository reference
  81. r.close()