forked from mirrors/probot
Refactor createIssue for multiple arguments
This commit is contained in:
parent
6e41f77e20
commit
a0eda23611
|
@ -55,12 +55,12 @@ module.exports = class Issues extends Plugin {
|
|||
return deleteFunction(context.toRepo({id: comment.id}));
|
||||
}
|
||||
|
||||
create(context, content) {
|
||||
var lines = content.split('\n');
|
||||
const titleTemplate = handlebars.compile(lines[0])(context.payload);
|
||||
lines.splice(0,1);
|
||||
const bodyTemplate = handlebars.compile(lines.join('\n'))(context.payload);
|
||||
createIssue(context, content) {
|
||||
return Promise.resolve(content.body).then(body => {
|
||||
const titleTemplate = handlebars.compile(content.title)(context.payload);
|
||||
const bodyTemplate = handlebars.compile(body)(context.payload);
|
||||
|
||||
return context.github.issues.create(context.toRepo({title: titleTemplate, body: bodyTemplate}));
|
||||
return context.github.issues.create(context.toRepo({title: titleTemplate, body: bodyTemplate}));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -20,7 +20,8 @@ describe('issues plugin', () => {
|
|||
addAssigneesToIssue: createSpy(),
|
||||
removeAssigneesFromIssue: createSpy(),
|
||||
removeLabel: createSpy(),
|
||||
deleteComment: createSpy()
|
||||
deleteComment: createSpy(),
|
||||
create: createSpy()
|
||||
},
|
||||
repos: {
|
||||
deleteCommitComment: createSpy()
|
||||
|
@ -238,4 +239,28 @@ describe('issues plugin', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('createIssue', () => {
|
||||
it('creates an issues', () => {
|
||||
return this.issues.createIssue(context, {title: 'testing', body: 'body'}).then(() => {
|
||||
expect(github.issues.create).toHaveBeenCalledWith({
|
||||
owner: 'bkeepers-inc',
|
||||
repo: 'test',
|
||||
title: 'testing',
|
||||
body: 'body'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('resolves body content', () => {
|
||||
return this.issues.createIssue(context, {title: 'testing', body: Promise.resolve('body')}).then(() => {
|
||||
expect(github.issues.create).toHaveBeenCalledWith({
|
||||
owner: 'bkeepers-inc',
|
||||
repo: 'test',
|
||||
title: 'testing',
|
||||
body: 'body'
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue