probot/lib/context.js

25 lines
559 B
JavaScript
Raw Normal View History

2016-10-29 21:18:29 +08:00
const Payload = require('./payload');
module.exports = class Context {
2016-12-04 02:41:43 +08:00
constructor(github, event) {
2016-10-29 21:18:29 +08:00
this.github = github;
this.event = event;
this.payload = new Payload(event.payload);
}
2016-12-04 01:43:07 +08:00
toRepo(object) {
2016-12-06 11:28:23 +08:00
const repo = this.payload.repository;
return Object.assign({
2016-12-06 11:28:23 +08:00
owner: repo.owner.login || repo.owner.name,
repo: repo.name
}, object);
2016-12-04 01:43:07 +08:00
}
toIssue(object) {
return Object.assign({
2016-12-04 01:43:07 +08:00
number: (this.payload.issue || this.payload.pull_request || this.payload).number
}, this.toRepo(), object);
2016-12-04 01:43:07 +08:00
}
2016-10-29 21:18:29 +08:00
};