add test for issue option (#20)
This commit is contained in:
44
__tests__/issue.test.ts
Normal file
44
__tests__/issue.test.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import * as issue from '../src/issue'
|
||||||
|
import {IssueOption} from '../src/interface'
|
||||||
|
|
||||||
|
describe('getIssueOption', () => {
|
||||||
|
test('without assignee and label', () => {
|
||||||
|
process.env.INPUT_ISSUE_TITLE = 'npm audit found vulnerabilities'
|
||||||
|
|
||||||
|
const expected: IssueOption = {
|
||||||
|
title: 'npm audit found vulnerabilities',
|
||||||
|
body: 'hi',
|
||||||
|
assignees: [''],
|
||||||
|
labels: ['']
|
||||||
|
}
|
||||||
|
expect(issue.getIssueOption('hi')).toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('with 1 assignee and 1 label', () => {
|
||||||
|
process.env.INPUT_ISSUE_TITLE = 'npm audit found vulnerabilities'
|
||||||
|
process.env.INPUT_ISSUE_ASSIGNEES = 'alice'
|
||||||
|
process.env.INPUT_ISSUE_LABELS = 'foo'
|
||||||
|
|
||||||
|
const expected: IssueOption = {
|
||||||
|
title: 'npm audit found vulnerabilities',
|
||||||
|
body: 'hi',
|
||||||
|
assignees: ['alice'],
|
||||||
|
labels: ['foo']
|
||||||
|
}
|
||||||
|
expect(issue.getIssueOption('hi')).toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('with 2 assignees and 2 labels', () => {
|
||||||
|
process.env.INPUT_ISSUE_TITLE = 'npm audit found vulnerabilities'
|
||||||
|
process.env.INPUT_ISSUE_ASSIGNEES = 'alice,bob'
|
||||||
|
process.env.INPUT_ISSUE_LABELS = 'foo,bar'
|
||||||
|
|
||||||
|
const expected: IssueOption = {
|
||||||
|
title: 'npm audit found vulnerabilities',
|
||||||
|
body: 'hi',
|
||||||
|
assignees: ['alice', 'bob'],
|
||||||
|
labels: ['foo', 'bar']
|
||||||
|
}
|
||||||
|
expect(issue.getIssueOption('hi')).toEqual(expected)
|
||||||
|
})
|
||||||
|
})
|
||||||
3220
dist/index.js
vendored
3220
dist/index.js
vendored
File diff suppressed because one or more lines are too long
6
src/interface.ts
Normal file
6
src/interface.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
export interface IssueOption {
|
||||||
|
title: string
|
||||||
|
body: string
|
||||||
|
assignees?: string[]
|
||||||
|
labels?: string[]
|
||||||
|
}
|
||||||
17
src/issue.ts
Normal file
17
src/issue.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import * as core from '@actions/core'
|
||||||
|
import {IssueOption} from './interface'
|
||||||
|
|
||||||
|
export function getIssueOption(body: string): IssueOption {
|
||||||
|
return {
|
||||||
|
title: core.getInput('issue_title'),
|
||||||
|
body,
|
||||||
|
assignees: core
|
||||||
|
.getInput('issue_assignees')
|
||||||
|
.replace(/\s+/g, '')
|
||||||
|
.split(','),
|
||||||
|
labels: core
|
||||||
|
.getInput('issue_labels')
|
||||||
|
.replace(/\s+/g, '')
|
||||||
|
.split(',')
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/main.ts
21
src/main.ts
@@ -3,6 +3,8 @@ import * as github from '@actions/github'
|
|||||||
import stripAnsi from 'strip-ansi'
|
import stripAnsi from 'strip-ansi'
|
||||||
import Octokit, {IssuesCreateResponse} from '@octokit/rest'
|
import Octokit, {IssuesCreateResponse} from '@octokit/rest'
|
||||||
import {Audit} from './audit'
|
import {Audit} from './audit'
|
||||||
|
import * as issue from '../src/issue'
|
||||||
|
import {IssueOption} from '../src/interface'
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
@@ -22,25 +24,14 @@ async function run(): Promise<void> {
|
|||||||
|
|
||||||
// remove control characters and create a code block
|
// remove control characters and create a code block
|
||||||
const issueBody = `\`\`\`\n${stripAnsi(audit.stdout)}\n\`\`\``
|
const issueBody = `\`\`\`\n${stripAnsi(audit.stdout)}\n\`\`\``
|
||||||
const issueOptions = {
|
const option: IssueOption = issue.getIssueOption(issueBody)
|
||||||
title: core.getInput('issue_title'),
|
|
||||||
body: issueBody,
|
|
||||||
assignees: core
|
|
||||||
.getInput('issue_assignees')
|
|
||||||
.replace(/\s+/g, '')
|
|
||||||
.split(','),
|
|
||||||
labels: core
|
|
||||||
.getInput('issue_labels')
|
|
||||||
.replace(/\s+/g, '')
|
|
||||||
.split(',')
|
|
||||||
}
|
|
||||||
const {
|
const {
|
||||||
data: issue
|
data: createdIssue
|
||||||
}: Octokit.Response<IssuesCreateResponse> = await client.issues.create({
|
}: Octokit.Response<IssuesCreateResponse> = await client.issues.create({
|
||||||
...github.context.repo,
|
...github.context.repo,
|
||||||
...issueOptions
|
...option
|
||||||
})
|
})
|
||||||
core.debug(`#${issue.number}`)
|
core.debug(`#${createdIssue.number}`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message)
|
core.setFailed(error.message)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user