|
20 | 20 | import java.util.Set;
|
21 | 21 | import java.util.TreeSet;
|
22 | 22 | import static org.junit.Assert.*;
|
| 23 | + |
| 24 | +import org.apache.commons.io.IOUtils; |
| 25 | +import org.apache.commons.lang.StringUtils; |
23 | 26 | import org.junit.Assume;
|
24 | 27 | import org.junit.AssumptionViolatedException;
|
25 | 28 | import org.junit.rules.ExternalResource;
|
@@ -189,26 +192,21 @@ public void registerHook(FilePath repo) throws Exception {
|
189 | 192 | FilePath hgDir = repo.child(".hg");
|
190 | 193 | FilePath enforcePython3 = hgDir.child("enforce-python3.py");
|
191 | 194 | enforcePython3.write(
|
192 |
| - "import urllib.request, urllib.parse\n" + |
193 |
| - "def precommit(**kwargs):\n" + |
194 |
| - " urllib.request.Request('http://nowhere.net/')\n", null); |
| 195 | + "import urllib.request, urllib.parse\n" + |
| 196 | + "def precommit(**kwargs):\n" + |
| 197 | + " urllib.request.Request('http://nowhere.net/')\n", null); |
| 198 | + |
195 | 199 | FilePath hook = hgDir.child("hook.py");
|
196 |
| - hook.write( |
197 |
| - "import urllib.request, urllib.parse\n" + |
198 |
| - "def commit(ui, repo, node, **kwargs):\n" + |
199 |
| - " data = {\n" + |
200 |
| - " 'url': '" + repo.toURI().toString() + "',\n" + |
201 |
| - " 'branch': repo[node].branch(),\n" + |
202 |
| - " 'changesetId': node,\n" + |
203 |
| - " }\n" + |
204 |
| - " req = urllib.request.Request('" + j.getURL() + "mercurial/notifyCommit')\n" + |
205 |
| - " rsp = urllib.request.urlopen(req, urllib.parse.urlencode(data).encode(\"utf-8\"))\n" + |
206 |
| - " # TODO gives some error about bytes vs. str: ui.warn('Notify Commit hook response: %s\\n' % rsp.read())\n" + |
207 |
| - " pass\n", null); |
| 200 | + |
| 201 | + String hook_text = IOUtils.toString(this.getClass().getResourceAsStream("hook.py"), "UTF-8"); |
| 202 | + StringUtils.replace(hook_text, "@JENKINS_URL@", j.getURL().toString()); |
| 203 | + StringUtils.replace(hook_text, "@REPO_URL@", repo.toURI().toString()); |
| 204 | + hook.write(hook_text, null); |
| 205 | + |
208 | 206 | hgDir.child("hgrc").write(
|
209 |
| - "[hooks]\n" + |
210 |
| - "precommit.enforce-python3 = python:" + enforcePython3.getRemote() + ":precommit\n" + |
211 |
| - "commit.jenkins = python:" + hook.getRemote() + ":commit", null); |
| 207 | + "[hooks]\n" + |
| 208 | + "precommit.enforce-python3 = python:" + enforcePython3.getRemote() + ":precommit\n" + |
| 209 | + "commit.jenkins = python:" + hook.getRemote() + ":commit", null); |
212 | 210 | }
|
213 | 211 |
|
214 | 212 | }
|
0 commit comments