This repository has been archived by the owner on Jan 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
intree.js
50 lines (42 loc) · 1.74 KB
/
intree.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const debug = require('debug')('taskcluster-github:intree');
const yaml = require('js-yaml');
const TcYaml = require('./tc-yaml');
module.exports = {};
/**
* Returns a function that merges an existing taskcluster github config with
* a pull request message's payload to generate a full task graph config.
* params {
* config: '...', A yaml string
* payload: {}, GitHub WebHook message payload
* schema: url, Url to the taskcluster config schema
* }
**/
module.exports.setup = async function({cfg, schemaset}) {
const validate = await schemaset.validator(cfg.taskcluster.rootUrl);
return function({config, payload, schema}) {
config = yaml.safeLoad(config);
const version = config.version;
const errors = validate(config, schema[version]);
if (errors) {
throw new Error(errors);
}
debug(`intree config for ${payload.organization}/${payload.repository} matches valid schema.`);
// We need to toss out the config version number; it's the only
// field that's not also in graph/task definitions
delete config.version;
const tcyaml = TcYaml.instantiate(version);
// Perform parameter substitutions. This happens after verification
// because templating may change with schema version, and parameter
// functions are used as default values for some fields.
config = tcyaml.substituteParameters(config, cfg, payload);
try {
// Compile individual tasks, filtering any that are not intended
// for the current github event type. Append taskGroupId while
// we're at it.
return tcyaml.compileTasks(config, cfg, payload, new Date().toJSON());
} catch (e) {
debug('Error processing tasks!');
throw e;
}
};
};