-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPatchronContext.js
62 lines (50 loc) · 1.44 KB
/
PatchronContext.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
51
52
53
54
55
56
57
58
59
60
61
62
const EventEmitter = require('events');
const {
nodeEnvironment,
settings: { isStoringLogsEnabled }
} = require('src/config');
const EventLog = require('src/utilities/EventLog');
const { TEST_ENVIRONMENT } = require('src/config/constants');
const updateLogPathJob = require('src/utilities/updateLogPathJob');
/**
* Class wrapping Probot's features and Patchron's logic.
*/
class PatchronContextBuilder {
/**
* @param {ProbotApp} app
*/
constructor(app) {
this.log = null;
this.repo = null;
this.pullRequest = {
owner: null,
id: null,
context: null
};
if (isStoringLogsEnabled && nodeEnvironment !== TEST_ENVIRONMENT) {
const eventEmitter = new EventEmitter();
eventEmitter.on('path-updated', (updatedLog) => {
this.log = new EventLog(updatedLog);
});
updateLogPathJob(eventEmitter);
} else {
this.log = new EventLog(app.log);
}
return this;
}
/**
* @param {ProbotContext} context
*/
initializePullRequestData(context) {
const payload = context.payload;
const repo = context.repo();
const { login: owner } = payload.sender;
this.pullRequest = {
owner,
context,
id: payload.number
};
this.repo = repo;
}
}
module.exports = PatchronContextBuilder;