Skip to content

Commit

Permalink
Merge pull request #2 from JasonEtco/leaner-args
Browse files Browse the repository at this point in the history
Use actions-toolkit for arg parsing
  • Loading branch information
JasonEtco authored Jan 28, 2019
2 parents 8a69e9a + 7720b85 commit 11c8e67
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
11 changes: 7 additions & 4 deletions entrypoint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const IssueCreator = require('.')
const Toolkit = require('actions-toolkit')

const issueCreator = new IssueCreator(process.argv[2])
issueCreator.go().then(issue => {
console.log(`Created issue ${issue.data.title}#${issue.data.number}: ${issue.data.html_url}`)
})
const tools = new Toolkit()
const issueCreator = new IssueCreator(tools)
issueCreator.go()
.then(issue => {
console.log(`Created issue ${issue.data.title}#${issue.data.number}: ${issue.data.html_url}`)
})
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const { Toolkit } = require('actions-toolkit')
const fm = require('front-matter')
const nunjucks = require('nunjucks')
const dateFilter = require('nunjucks-date-filter')

class IssueCreator {
constructor (template) {
this.template = template || '.github/ISSUE_TEMPLATE.md'
this.tools = new Toolkit()
/**
* @param {import('actions-toolkit').Toolkit} tools
*/
constructor (tools) {
this.tools = tools
this.template = this.tools.arguments._[0] || '.github/ISSUE_TEMPLATE.md'
this.env = nunjucks.configure({ autoescape: false })
this.env.addFilter('date', dateFilter)
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions tests/index.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
const path = require('path')
const IssueCreator = require('..')
const { Toolkit } = require('actions-toolkit')

describe('create-an-issue', () => {
let issueCreator, github
let issueCreator, tools, github

beforeEach(() => {
issueCreator = new IssueCreator()
tools = new Toolkit()
github = { issues: { create: jest.fn() } }

issueCreator.tools.workspace = path.join(__dirname, 'fixtures')
issueCreator.tools.context.payload = { repository: { owner: { login: 'JasonEtco' }, name: 'waddup' } }
issueCreator.tools.github = github
tools.workspace = path.join(__dirname, 'fixtures')
tools.context.payload = { repository: { owner: { login: 'JasonEtco' }, name: 'waddup' } }
tools.github = github

issueCreator = new IssueCreator(tools)
})

it('creates a new issue', async () => {
Expand All @@ -20,7 +23,8 @@ describe('create-an-issue', () => {
})

it('creates a new issue from a different template', async () => {
issueCreator = new IssueCreator('.github/different-template.md')
tools.arguments._ = ['.github/different-template.md']
issueCreator = new IssueCreator(tools)
issueCreator.tools.workspace = path.join(__dirname, 'fixtures')
issueCreator.tools.context.payload = { repository: { owner: { login: 'JasonEtco' }, name: 'waddup' } }
issueCreator.tools.github = github
Expand Down

0 comments on commit 11c8e67

Please sign in to comment.