Refactor createIssue for multiple arguments

This commit is contained in:
Michael Johnson 2017-01-24 10:00:49 -07:00
parent 6e41f77e20
commit a0eda23611
2 changed files with 32 additions and 7 deletions

View File

@ -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}));
});
}
};

View File

@ -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'
});
});
});
});
});