1 | import R from "ramda";
|
2 | import log from "./log";
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export default (apps, manifest) => {
|
9 | return {
|
10 | post(req, res) {
|
11 |
|
12 | const data = req.body;
|
13 | const branch = (data.ref && R.last(data.ref.split("/"))) || data.repository.default_branch;
|
14 | const repo = data.repository.full_name;
|
15 | const modified = (data.head_commit && data.head_commit.modified) || [];
|
16 |
|
17 | const isManifestMatch = R.any(path => path === manifest.repo.path, modified);
|
18 | if (isManifestMatch) {
|
19 | manifest.update()
|
20 | .catch(err => {
|
21 | log.error(`Failed while updating manifest.`);
|
22 | log.error((err));
|
23 | });
|
24 | } else {
|
25 |
|
26 | const isRepoMatch = (app) => app.repo.name === repo && app.branch === branch;
|
27 | const matchingApps = R.filter(isRepoMatch, apps);
|
28 |
|
29 |
|
30 | if (matchingApps.length > 0) {
|
31 | log.info(`Github webhook for '${ repo }:${ branch }' => Checking for updates: ${ matchingApps.map(item => item.id) }`);
|
32 | matchingApps.forEach(app => app.update());
|
33 | }
|
34 | }
|
35 |
|
36 |
|
37 | res.status(200).send();
|
38 | }
|
39 | };
|
40 | };
|