Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use actions-toolkit for arg parsing #2

Merged
merged 4 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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