diff options
author | Berke Viktor <sundayfunday1234@outlook.com> | 2014-01-28 12:07:02 -0500 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-01-28 12:09:28 -0500 |
commit | 0dfb9845d7b5877bd0273a931121209b7cea4c86 (patch) | |
tree | fff79fcc57470ed2b78d8fa702dff08caca3cdfa /src/main/distrib/data/groovy | |
parent | 5be43be6a2788f97ae741d2c7be2cb63f1bd0ede (diff) | |
download | gitblit-0dfb9845d7b5877bd0273a931121209b7cea4c86.tar.gz gitblit-0dfb9845d7b5877bd0273a931121209b7cea4c86.zip |
Add Redmine Fetch groovy hook (issue-359)
Diffstat (limited to 'src/main/distrib/data/groovy')
-rw-r--r-- | src/main/distrib/data/groovy/redmine-fetch.groovy | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/main/distrib/data/groovy/redmine-fetch.groovy b/src/main/distrib/data/groovy/redmine-fetch.groovy new file mode 100644 index 00000000..60738353 --- /dev/null +++ b/src/main/distrib/data/groovy/redmine-fetch.groovy @@ -0,0 +1,68 @@ +/*
+ * Copyright 2014 Berke Viktor.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import com.gitblit.GitBlit
+import com.gitblit.Keys
+import com.gitblit.models.RepositoryModel
+import com.gitblit.models.UserModel
+import com.gitblit.utils.JGitUtils
+import org.eclipse.jgit.lib.Repository
+import org.slf4j.Logger
+
+/*
+ * This script triggers automatic repo fetches in Redmine upon pushes.
+ * It won't work out-of-box, you need to configure a few things.
+ *
+ * Redmine
+ * - Go to Administration / Settings / Repositories, and make sure that the
+ * "Enable WS for repository management" option is checked. Also generate an
+ * API key and take note of it.
+ * - Open a project page, go to Settings / Repositories and add a repo. Take
+ * note of the Identifier.
+ *
+ * Gitblit
+ * - Set the redmineProject custom field in gitblit.properties, e.g.
+ * groovy.customFields = "redmineProject=Redmine Project Identifier"
+ * - Edit the repo you added to Redmine, go to hook scripts and add this script
+ * to the post-receive hooks. Also specify the Redmine project's identifier
+ * under custom fields.
+ *
+ * Troubleshooting
+ * - run Gitblit interactively and check its console output
+ * - on the Redmine server, tail -f log/access.log
+ *
+ * If you want your repos to work with multiple Redmine projects, you don't need
+ * to add the repos to all of them. Instead, add the repo to a single project,
+ * then go to Administration / Settings / Repositories and enable the "Allow
+ * issues of all the other projects to be referenced and fixed" option.
+ */
+
+/* specify the URL of your Redmine instance here */
+def redmineURL = "http://redmine.foo.bar/"
+
+/* specify the API key you generated in Redmine Administration here */
+def apiKey = "FIXME"
+
+/*
+ * construct the URL from global and repo properties, for more info refer to
+ * http://www.redmine.org/projects/redmine/wiki/RedmineSettings#Fetch-commits-automatically
+ */
+def triggerURL = redmineURL + "sys/fetch_changesets?id=" + repository.customFields.redmineProject + "&key=" + apiKey
+
+/* log the action */
+logger.info("Redmine Fetch hook triggered by ${user.username} for ${repository.name}: GET ${triggerURL}")
+
+/* send the HTTP GET query */
+new URL(triggerURL).getContent()
|