Skip to content

Commit 0933d72

Browse files
authoredOct 13, 2020
feat(1415): Add logic to handle webhook events from external repos (#2187)
1 parent 776384e commit 0933d72

File tree

5 files changed

+309
-82
lines changed

5 files changed

+309
-82
lines changed
 

‎plugins/pipelines/create.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,17 @@ module.exports = () => ({
113113
});
114114
}
115115

116-
const results = await Promise.all([
117-
pipeline.sync(),
118-
pipeline.addWebhooks(`${request.server.info.uri}/v4/webhooks`)
119-
]);
116+
const results = await pipeline.sync();
117+
118+
await pipeline.addWebhooks(`${request.server.info.uri}/v4/webhooks`);
120119

121120
const location = urlLib.format({
122121
host: request.headers.host,
123122
port: request.headers.port,
124123
protocol: request.server.info.protocol,
125124
pathname: `${request.path}/${pipeline.id}`
126125
});
127-
const data = await results[0].toJson();
126+
const data = await results.toJson();
128127

129128
return h
130129
.response(data)

‎plugins/pipelines/update.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,15 @@ module.exports = () => ({
135135
oldPipeline.name = scmRepo.name;
136136

137137
// update pipeline with new scmRepo and branch
138-
return oldPipeline
139-
.update()
140-
.then(updatedPipeline =>
141-
Promise.all([
142-
updatedPipeline.sync(),
143-
updatedPipeline.addWebhooks(
144-
`${request.server.info.uri}/v4/webhooks`
145-
)
146-
])
147-
)
148-
.then(results => h.response(results[0].toJson()).code(200));
138+
return oldPipeline.update().then(async updatedPipeline => {
139+
await updatedPipeline.addWebhooks(
140+
`${request.server.info.uri}/v4/webhooks`
141+
);
142+
143+
const result = await updatedPipeline.sync();
144+
145+
return h.response(result.toJson()).code(200);
146+
});
149147
})
150148
)
151149
);

0 commit comments

Comments
 (0)
Please sign in to comment.