You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

redmine-fetch.groovy 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright 2014 Berke Viktor.
  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.UserModel
  20. import com.gitblit.utils.JGitUtils
  21. import org.eclipse.jgit.lib.Repository
  22. import org.slf4j.Logger
  23. /*
  24. * This script triggers automatic repo fetches in Redmine upon pushes.
  25. * It won't work out-of-box, you need to configure a few things.
  26. *
  27. * Redmine
  28. * - Go to Administration / Settings / Repositories, and make sure that the
  29. * "Enable WS for repository management" option is checked. Also generate an
  30. * API key and take note of it.
  31. * - Open a project page, go to Settings / Repositories and add a repo. Take
  32. * note of the Identifier.
  33. *
  34. * Gitblit
  35. * - Set the redmineProject custom field in gitblit.properties, e.g.
  36. * groovy.customFields = "redmineProject=Redmine Project Identifier"
  37. * - Edit the repo you added to Redmine, go to hook scripts and add this script
  38. * to the post-receive hooks. Also specify the Redmine project's identifier
  39. * under custom fields.
  40. *
  41. * Troubleshooting
  42. * - run Gitblit interactively and check its console output
  43. * - on the Redmine server, tail -f log/access.log
  44. *
  45. * If you want your repos to work with multiple Redmine projects, you don't need
  46. * to add the repos to all of them. Instead, add the repo to a single project,
  47. * then go to Administration / Settings / Repositories and enable the "Allow
  48. * issues of all the other projects to be referenced and fixed" option.
  49. */
  50. /* specify the URL of your Redmine instance here */
  51. def redmineURL = "http://redmine.foo.bar/"
  52. /* specify the API key you generated in Redmine Administration here */
  53. def apiKey = "FIXME"
  54. /*
  55. * construct the URL from global and repo properties, for more info refer to
  56. * http://www.redmine.org/projects/redmine/wiki/RedmineSettings#Fetch-commits-automatically
  57. */
  58. def triggerURL = redmineURL + "sys/fetch_changesets?id=" + repository.customFields.redmineProject + "&key=" + apiKey
  59. /* log the action */
  60. logger.info("Redmine Fetch hook triggered by ${user.username} for ${repository.name}: GET ${triggerURL}")
  61. /* send the HTTP GET query */
  62. new URL(triggerURL).getContent()