Skip to content

Commit eeba10b

Browse files
committed
Github webhook now working in real-life test
1 parent 4fb45f9 commit eeba10b

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

subprojects/listener/src/main/groovy/org/pipelinelabs/pipeline/listen/core/GitWorker.groovy

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ package org.pipelinelabs.pipeline.listen.core
33
import com.google.common.eventbus.EventBus
44
import com.google.common.eventbus.Subscribe
55
import com.yammer.dropwizard.lifecycle.Managed
6+
import groovy.util.logging.Slf4j
67

78
import java.nio.file.Files
9+
import java.nio.file.Path
10+
import java.nio.file.Paths
811

12+
@Slf4j
913
class GitWorker implements Managed {
1014

1115
private final EventBus bus
@@ -26,9 +30,25 @@ class GitWorker implements Managed {
2630

2731
@Subscribe
2832
void work(GitTriggerEvent event) {
29-
def dir = Files.createTempDirectory("pipeline/")
33+
log.info('Received event [{}]', event)
34+
def dir = Files.createTempDirectory("pipeline")
35+
log.debug('Created pipeline directory [{}]', dir)
36+
37+
def workDirName = "work"
38+
def workDir = Paths.get(dir.toString(), workDirName)
3039
List envProps = null
31-
"git clone ${event.url}".execute(envProps, dir.toFile())
32-
"pipe-runner run project.pipe".execute(envProps, dir.toFile())
40+
41+
def gitCommand = "git clone ${event.url} ${workDirName}"
42+
executeCommand(gitCommand, dir, envProps)
43+
44+
def runnerCommand = "pipe-runner run project.pipeline"
45+
executeCommand(runnerCommand, workDir, envProps)
46+
}
47+
48+
private void executeCommand(String command, Path workDir, List envProps) {
49+
log.info('Executing command [{}] in pipeline directory [{}]', command, workDir)
50+
def runnerProc = command.execute(envProps, workDir.toFile())
51+
def runnerExitStatus = runnerProc.waitFor()
52+
log.info('Command [{}] exitted with status [{}]', command, runnerExitStatus)
3353
}
3454
}

subprojects/listener/src/main/groovy/org/pipelinelabs/pipeline/listen/resources/GitHubWebHookResource.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import org.pipelinelabs.pipeline.listen.core.GitTriggerEvent
88
import javax.ws.rs.*
99
import javax.ws.rs.core.Response
1010

11+
import static javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED
1112
import static javax.ws.rs.core.MediaType.APPLICATION_JSON
1213
import static javax.ws.rs.core.Response.Status.BAD_REQUEST
1314

1415
@Slf4j
1516
@Path("/providers/github")
1617
@Produces(APPLICATION_JSON)
17-
@Consumes(APPLICATION_JSON)
18+
@Consumes(APPLICATION_FORM_URLENCODED)
1819
class GitHubWebHookResource {
1920

2021
private final EventBus bus

subprojects/listener/src/test/groovy/org/pipelinelabs/pipeline/listen/resources/GitHubWebHookResourceSpec.groovy

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import spock.lang.Unroll
1313
import static com.sun.jersey.api.client.ClientResponse.Status.BAD_REQUEST
1414
import static com.sun.jersey.api.client.ClientResponse.Status.NO_CONTENT
1515
import static com.yammer.dropwizard.testing.JsonHelpers.jsonFixture
16+
import static javax.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED_TYPE
1617
import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE
1718

1819
class GitHubWebHookResourceSpec extends Specification {
@@ -27,7 +28,7 @@ class GitHubWebHookResourceSpec extends Specification {
2728

2829
when:
2930
def response = requestBuilder()
30-
.type(APPLICATION_JSON_TYPE)
31+
.type(APPLICATION_FORM_URLENCODED_TYPE)
3132
.accept(APPLICATION_JSON_TYPE)
3233
.post(ClientResponse, form)
3334

@@ -46,7 +47,7 @@ class GitHubWebHookResourceSpec extends Specification {
4647

4748
when:
4849
def response = requestBuilder()
49-
.type(APPLICATION_JSON_TYPE)
50+
.type(APPLICATION_FORM_URLENCODED_TYPE)
5051
.accept(APPLICATION_JSON_TYPE)
5152
.post(ClientResponse, form)
5253

@@ -69,7 +70,7 @@ class GitHubWebHookResourceSpec extends Specification {
6970

7071
when:
7172
def response = requestBuilder()
72-
.type(APPLICATION_JSON_TYPE)
73+
.type(APPLICATION_FORM_URLENCODED_TYPE)
7374
.accept(APPLICATION_JSON_TYPE)
7475
.post(ClientResponse, form)
7576

0 commit comments

Comments
 (0)