-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from JasonEtco/actions-toolkit-200
- Loading branch information
Showing
8 changed files
with
160 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,44 @@ | ||
const { Toolkit } = require('actions-toolkit') | ||
const fm = require('front-matter') | ||
const nunjucks = require('nunjucks') | ||
const dateFilter = require('nunjucks-date-filter') | ||
|
||
class IssueCreator { | ||
/** | ||
* @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) | ||
Toolkit.run(async tools => { | ||
const template = tools.arguments._[0] || '.github/ISSUE_TEMPLATE.md' | ||
const env = nunjucks.configure({ autoescape: false }) | ||
env.addFilter('date', dateFilter) | ||
|
||
const templateVariables = { | ||
...tools.context, | ||
date: Date.now() | ||
} | ||
|
||
async go () { | ||
const templateVariables = { | ||
...this.tools.context, | ||
date: Date.now() | ||
} | ||
|
||
// Get the file | ||
this.tools.log('Reading from file', this.template) | ||
const file = this.tools.getFile(this.template) | ||
|
||
// Grab the front matter as JSON | ||
const { attributes, body } = fm(file) | ||
this.tools.log(`Front matter for ${this.template} is`, attributes) | ||
|
||
const templated = { | ||
body: this.env.renderString(body, templateVariables), | ||
title: this.env.renderString(attributes.title, templateVariables) | ||
} | ||
|
||
this.tools.log('Templates compiled', templated) | ||
this.tools.log('Creating new issue') | ||
|
||
// Create the new issue | ||
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/') | ||
return this.tools.github.issues.create({ | ||
owner, | ||
repo, | ||
...templated, | ||
assignees: attributes.assignees || [], | ||
labels: attributes.labels || [], | ||
milestone: attributes.milestone | ||
}) | ||
// Get the file | ||
tools.log('Reading from file', template) | ||
const file = tools.getFile(template) | ||
|
||
// Grab the front matter as JSON | ||
const { attributes, body } = fm(file) | ||
tools.log(`Front matter for ${template} is`, attributes) | ||
|
||
const templated = { | ||
body: env.renderString(body, templateVariables), | ||
title: env.renderString(attributes.title, templateVariables) | ||
} | ||
} | ||
|
||
module.exports = IssueCreator | ||
tools.log('Templates compiled', templated) | ||
tools.log('Creating new issue') | ||
|
||
// Create the new issue | ||
const issue = await tools.github.issues.create({ | ||
...tools.context.repo, | ||
...templated, | ||
assignees: attributes.assignees || [], | ||
labels: attributes.labels || [], | ||
milestone: attributes.milestone | ||
}) | ||
|
||
tools.log.success(`Created issue ${issue.data.title}#${issue.data.number}: ${issue.data.html_url}`) | ||
}, { | ||
secrets: ['GITHUB_TOKEN'] | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
"author": "Jason Etcovitch <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"actions-toolkit": "^1.5.0", | ||
"actions-toolkit": "^2.0.0", | ||
"front-matter": "^3.0.1", | ||
"js-yaml": "^3.12.0", | ||
"nunjucks": "^3.1.4", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"repository": { | ||
"owner": { "login": "JasonEtco" }, | ||
"name": "waddup" | ||
} | ||
} |
Oops, something went wrong.