-
Notifications
You must be signed in to change notification settings - Fork 8
/
worker.js
46 lines (44 loc) · 1.64 KB
/
worker.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
var debug = require('debug')('strider-github-status');
module.exports = {
init: function (config, job, context, callback) {
var sha;
debug('initing', job._id, job.plugin_data);
if (job.plugin_data && job.plugin_data.github && job.plugin_data.github.pull_request) {
debug('found pr!', job.plugin_data.github.pull_request);
sha = job.plugin_data.github.pull_request.sha;
} else if (job.trigger.type === 'commit') {
debug('found commit!', job.ref);
sha = job.ref.id;
} else {
debug('No github PR data nor github commit', job.plugin_data, job);
return callback(null, {});
}
var projectName = job.project.name;
var creator = job.project.creator;
var account;
var token;
account = creator.account(job.project.provider);
if (!account || !account.config.accessToken) {
console.error('Account not found for', job.project.provider);
debug(job.project.provider, creator.accounts, account);
return;
}
token = account.config.accessToken;
debug('Token', account, token);
return callback(null, {
listen: function (emitter) {
debug('listening');
var github_repo_data = {
user: job.project.provider.config.owner,
repo: job.project.provider.config.repo,
sha: sha
};
emitter.emit('plugin.github-status.started', job._id, projectName, token, github_repo_data, config);
emitter.once('job.status.tested', function (jobId) {
debug('job was tested', jobId);
emitter.emit('plugin.github-status.done', jobId, projectName, token, github_repo_data, config);
});
}
});
}
};