style: ๐Ÿ’„ lint error

This commit is contained in:
marocchino 2021-05-31 15:32:58 +09:00
parent 7874cc39cf
commit 6ee941ecc7
No known key found for this signature in database
GPG key ID: AFF521DBDB122570
6 changed files with 154 additions and 155 deletions

View file

@ -3,7 +3,6 @@
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid"

View file

@ -3,49 +3,49 @@ import {
createComment,
updateComment,
deleteComment
} from '../src/comment'
} from "../src/comment"
import * as core from '@actions/core'
import * as core from "@actions/core"
jest.mock('@actions/core', () => ({
jest.mock("@actions/core", () => ({
warning: jest.fn()
}))
const repo = {
owner: 'marocchino',
repo: 'sticky-pull-request-comment'
owner: "marocchino",
repo: "sticky-pull-request-comment"
}
it('findPreviousComment', async () => {
it("findPreviousComment", async () => {
const comment = {
user: {
login: 'github-actions[bot]'
login: "github-actions[bot]"
},
body: 'previous message\n<!-- Sticky Pull Request Comment -->'
body: "previous message\n<!-- Sticky Pull Request Comment -->"
}
const commentWithCustomHeader = {
user: {
login: 'github-actions[bot]'
login: "github-actions[bot]"
},
body: 'previous message\n<!-- Sticky Pull Request CommentTypeA -->'
body: "previous message\n<!-- Sticky Pull Request CommentTypeA -->"
}
const headerFirstComment = {
user: {
login: 'github-actions[bot]'
login: "github-actions[bot]"
},
body: '<!-- Sticky Pull Request CommentLegacyComment -->\nheader first message'
body: "<!-- Sticky Pull Request CommentLegacyComment -->\nheader first message"
}
const otherComments = [
{
user: {
login: 'some-user'
login: "some-user"
},
body: 'lgtm'
body: "lgtm"
},
{
user: {
login: 'github-actions[bot]'
login: "github-actions[bot]"
},
body: 'previous message\n<!-- Sticky Pull Request CommentTypeB -->'
body: "previous message\n<!-- Sticky Pull Request CommentTypeB -->"
}
]
const octokit: any = {
@ -65,21 +65,21 @@ it('findPreviousComment', async () => {
}
}
expect(await findPreviousComment(octokit, repo, 123, '')).toBe(comment)
expect(await findPreviousComment(octokit, repo, 123, 'TypeA')).toBe(
expect(await findPreviousComment(octokit, repo, 123, "")).toBe(comment)
expect(await findPreviousComment(octokit, repo, 123, "TypeA")).toBe(
commentWithCustomHeader
)
expect(await findPreviousComment(octokit, repo, 123, 'LegacyComment')).toBe(
expect(await findPreviousComment(octokit, repo, 123, "LegacyComment")).toBe(
headerFirstComment
)
expect(octokit.rest.issues.listComments).toBeCalledWith({
owner: 'marocchino',
repo: 'sticky-pull-request-comment',
owner: "marocchino",
repo: "sticky-pull-request-comment",
issue_number: 123
})
})
describe('updateComment', () => {
describe("updateComment", () => {
let octokit
beforeEach(() => {
@ -92,51 +92,51 @@ describe('updateComment', () => {
}
})
it('with comment body', async () => {
it("with comment body", async () => {
expect(
await updateComment(octokit, repo, 456, 'hello there', '')
await updateComment(octokit, repo, 456, "hello there", "")
).toBeUndefined()
expect(octokit.rest.issues.updateComment).toBeCalledWith({
comment_id: 456,
owner: 'marocchino',
repo: 'sticky-pull-request-comment',
body: 'hello there\n<!-- Sticky Pull Request Comment -->'
owner: "marocchino",
repo: "sticky-pull-request-comment",
body: "hello there\n<!-- Sticky Pull Request Comment -->"
})
expect(
await updateComment(octokit, repo, 456, 'hello there', 'TypeA')
await updateComment(octokit, repo, 456, "hello there", "TypeA")
).toBeUndefined()
expect(octokit.rest.issues.updateComment).toBeCalledWith({
comment_id: 456,
owner: 'marocchino',
repo: 'sticky-pull-request-comment',
body: 'hello there\n<!-- Sticky Pull Request CommentTypeA -->'
owner: "marocchino",
repo: "sticky-pull-request-comment",
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->"
})
expect(
await updateComment(
octokit,
repo,
456,
'hello there',
'TypeA',
'hello there\n<!-- Sticky Pull Request CommentTypeA -->'
"hello there",
"TypeA",
"hello there\n<!-- Sticky Pull Request CommentTypeA -->"
)
).toBeUndefined()
expect(octokit.rest.issues.updateComment).toBeCalledWith({
comment_id: 456,
owner: 'marocchino',
repo: 'sticky-pull-request-comment',
body: 'hello there\n<!-- Sticky Pull Request CommentTypeA -->\nhello there'
owner: "marocchino",
repo: "sticky-pull-request-comment",
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->\nhello there"
})
})
it('without comment body and previous body', async () => {
expect(await updateComment(octokit, repo, 456, '', '')).toBeUndefined()
it("without comment body and previous body", async () => {
expect(await updateComment(octokit, repo, 456, "", "")).toBeUndefined()
expect(octokit.rest.issues.updateComment).not.toBeCalled()
expect(core.warning).toBeCalledWith('Comment body cannot be blank')
expect(core.warning).toBeCalledWith("Comment body cannot be blank")
})
})
describe('createComment', () => {
describe("createComment", () => {
let octokit
beforeEach(() => {
@ -149,34 +149,34 @@ describe('createComment', () => {
}
})
it('with comment body or previousBody', async () => {
it("with comment body or previousBody", async () => {
expect(
await createComment(octokit, repo, 456, 'hello there', '')
await createComment(octokit, repo, 456, "hello there", "")
).toBeUndefined()
expect(octokit.rest.issues.createComment).toBeCalledWith({
issue_number: 456,
owner: 'marocchino',
repo: 'sticky-pull-request-comment',
body: 'hello there\n<!-- Sticky Pull Request Comment -->'
owner: "marocchino",
repo: "sticky-pull-request-comment",
body: "hello there\n<!-- Sticky Pull Request Comment -->"
})
expect(
await createComment(octokit, repo, 456, 'hello there', 'TypeA')
await createComment(octokit, repo, 456, "hello there", "TypeA")
).toBeUndefined()
expect(octokit.rest.issues.createComment).toBeCalledWith({
issue_number: 456,
owner: 'marocchino',
repo: 'sticky-pull-request-comment',
body: 'hello there\n<!-- Sticky Pull Request CommentTypeA -->'
owner: "marocchino",
repo: "sticky-pull-request-comment",
body: "hello there\n<!-- Sticky Pull Request CommentTypeA -->"
})
})
it('without comment body and previousBody', async () => {
expect(await createComment(octokit, repo, 456, '', '')).toBeUndefined()
it("without comment body and previousBody", async () => {
expect(await createComment(octokit, repo, 456, "", "")).toBeUndefined()
expect(octokit.rest.issues.createComment).not.toBeCalled()
expect(core.warning).toBeCalledWith('Comment body cannot be blank')
expect(core.warning).toBeCalledWith("Comment body cannot be blank")
})
})
it('deleteComment', async () => {
it("deleteComment", async () => {
const octokit: any = {
rest: {
issues: {
@ -187,7 +187,7 @@ it('deleteComment', async () => {
expect(await deleteComment(octokit, repo, 456)).toBeUndefined()
expect(octokit.rest.issues.deleteComment).toBeCalledWith({
comment_id: 456,
owner: 'marocchino',
repo: 'sticky-pull-request-comment'
owner: "marocchino",
repo: "sticky-pull-request-comment"
})
})

View file

@ -1,131 +1,131 @@
beforeEach(() => {
process.env['GITHUB_REPOSITORY'] = 'marocchino/stick-pull-request-comment'
process.env['INPUT_NUMBER'] = '123'
process.env['INPUT_APPEND'] = 'false'
process.env['INPUT_RECREATE'] = 'false'
process.env['INPUT_DELETE'] = 'false'
process.env['INPUT_GITHUB_TOKEN'] = 'some-token'
process.env["GITHUB_REPOSITORY"] = "marocchino/stick-pull-request-comment"
process.env["INPUT_NUMBER"] = "123"
process.env["INPUT_APPEND"] = "false"
process.env["INPUT_RECREATE"] = "false"
process.env["INPUT_DELETE"] = "false"
process.env["INPUT_GITHUB_TOKEN"] = "some-token"
})
afterEach(() => {
jest.resetModules()
delete process.env['GITHUB_REPOSITORY']
delete process.env['INPUT_REPO']
delete process.env['INPUT_HEADER']
delete process.env['INPUT_MESSAGE']
delete process.env['INPUT_NUMBER']
delete process.env['INPUT_APPEND']
delete process.env['INPUT_RECREATE']
delete process.env['INPUT_DELETE']
delete process.env['INPUT_GITHUB_TOKEN']
delete process.env['INPUT_PATH']
delete process.env["GITHUB_REPOSITORY"]
delete process.env["INPUT_REPO"]
delete process.env["INPUT_HEADER"]
delete process.env["INPUT_MESSAGE"]
delete process.env["INPUT_NUMBER"]
delete process.env["INPUT_APPEND"]
delete process.env["INPUT_RECREATE"]
delete process.env["INPUT_DELETE"]
delete process.env["INPUT_GITHUB_TOKEN"]
delete process.env["INPUT_PATH"]
})
test('repo', () => {
process.env['INPUT_REPO'] = 'other'
expect(require('../src/config')).toMatchObject({
test("repo", () => {
process.env["INPUT_REPO"] = "other"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: 'marocchino', repo: 'other'},
body: '',
header: '',
repo: {owner: "marocchino", repo: "other"},
body: "",
header: "",
append: false,
recreate: false,
deleteOldComment: false,
githubToken: 'some-token'
githubToken: "some-token"
})
})
test('header', () => {
process.env['INPUT_HEADER'] = 'header'
expect(require('../src/config')).toMatchObject({
test("header", () => {
process.env["INPUT_HEADER"] = "header"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: 'marocchino', repo: 'stick-pull-request-comment'},
body: '',
header: 'header',
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "",
header: "header",
append: false,
recreate: false,
deleteOldComment: false,
githubToken: 'some-token'
githubToken: "some-token"
})
})
test('append', () => {
process.env['INPUT_APPEND'] = 'true'
expect(require('../src/config')).toMatchObject({
test("append", () => {
process.env["INPUT_APPEND"] = "true"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: 'marocchino', repo: 'stick-pull-request-comment'},
body: '',
header: '',
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "",
header: "",
append: true,
recreate: false,
deleteOldComment: false,
githubToken: 'some-token'
githubToken: "some-token"
})
})
test('recreate', () => {
process.env['INPUT_RECREATE'] = 'true'
expect(require('../src/config')).toMatchObject({
test("recreate", () => {
process.env["INPUT_RECREATE"] = "true"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: 'marocchino', repo: 'stick-pull-request-comment'},
body: '',
header: '',
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "",
header: "",
append: false,
recreate: true,
deleteOldComment: false,
githubToken: 'some-token'
githubToken: "some-token"
})
})
test('delete', () => {
process.env['INPUT_DELETE'] = 'true'
expect(require('../src/config')).toMatchObject({
test("delete", () => {
process.env["INPUT_DELETE"] = "true"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: 'marocchino', repo: 'stick-pull-request-comment'},
body: '',
header: '',
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "",
header: "",
append: false,
recreate: false,
deleteOldComment: true,
githubToken: 'some-token'
githubToken: "some-token"
})
})
describe('path', () => {
test('when exists return content of a file', () => {
process.env['INPUT_PATH'] = './__tests__/assets/result'
expect(require('../src/config')).toMatchObject({
describe("path", () => {
test("when exists return content of a file", () => {
process.env["INPUT_PATH"] = "./__tests__/assets/result"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: 'marocchino', repo: 'stick-pull-request-comment'},
body: 'hi there\n',
header: '',
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "hi there\n",
header: "",
append: false,
recreate: false,
deleteOldComment: false,
githubToken: 'some-token'
githubToken: "some-token"
})
})
test('when not exists return null string', () => {
process.env['INPUT_PATH'] = './__tests__/assets/not_exists'
expect(require('../src/config')).toMatchObject({
test("when not exists return null string", () => {
process.env["INPUT_PATH"] = "./__tests__/assets/not_exists"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: 'marocchino', repo: 'stick-pull-request-comment'},
body: '',
header: '',
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "",
header: "",
append: false,
recreate: false,
deleteOldComment: false,
githubToken: 'some-token'
githubToken: "some-token"
})
})
})
test('message', () => {
process.env['INPUT_MESSAGE'] = 'hello there'
expect(require('../src/config')).toMatchObject({
test("message", () => {
process.env["INPUT_MESSAGE"] = "hello there"
expect(require("../src/config")).toMatchObject({
pullRequestNumber: expect.any(Number),
repo: {owner: 'marocchino', repo: 'stick-pull-request-comment'},
body: 'hello there',
header: '',
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
body: "hello there",
header: "",
append: false,
recreate: false,
deleteOldComment: false,
githubToken: 'some-token'
githubToken: "some-token"
})
})

View file

@ -1,5 +1,5 @@
import * as core from '@actions/core'
import {GitHub} from '@actions/github/lib/utils'
import * as core from "@actions/core"
import {GitHub} from "@actions/github/lib/utils"
function headerComment(header: String): string {
return `<!-- Sticky Pull Request Comment${header} -->`
@ -33,7 +33,7 @@ export async function updateComment(
previousBody?: string
): Promise<void> {
if (!body && !previousBody)
return core.warning('Comment body cannot be blank')
return core.warning("Comment body cannot be blank")
await octokit.rest.issues.updateComment({
...repo,
@ -55,7 +55,7 @@ export async function createComment(
previousBody?: string
): Promise<void> {
if (!body && !previousBody)
return core.warning('Comment body cannot be blank')
return core.warning("Comment body cannot be blank")
await octokit.rest.issues.createComment({
...repo,

View file

@ -1,37 +1,37 @@
import * as core from '@actions/core'
import {context} from '@actions/github'
import {readFileSync} from 'fs'
import * as core from "@actions/core"
import {context} from "@actions/github"
import {readFileSync} from "fs"
export const pullRequestNumber =
context?.payload?.pull_request?.number ||
+core.getInput('number', {required: false})
+core.getInput("number", {required: false})
export const repo = buildRepo()
export const header = core.getInput('header', {required: false})
export const append = core.getBooleanInput('append', {required: true})
export const recreate = core.getBooleanInput('recreate', {required: true})
export const deleteOldComment = core.getBooleanInput('delete', {required: true})
export const githubToken = core.getInput('GITHUB_TOKEN', {required: true})
export const header = core.getInput("header", {required: false})
export const append = core.getBooleanInput("append", {required: true})
export const recreate = core.getBooleanInput("recreate", {required: true})
export const deleteOldComment = core.getBooleanInput("delete", {required: true})
export const githubToken = core.getInput("GITHUB_TOKEN", {required: true})
export const body = buildBody()
function buildRepo(): {repo: string; owner: string} {
return {
owner: context.repo.owner,
repo: core.getInput('repo', {required: false}) || context.repo.repo
repo: core.getInput("repo", {required: false}) || context.repo.repo
}
}
function buildBody(): string {
const path = core.getInput('path', {required: false})
const path = core.getInput("path", {required: false})
if (path) {
try {
return readFileSync(path, 'utf-8')
return readFileSync(path, "utf-8")
} catch (error) {
core.setFailed(error.message)
return ''
return ""
}
} else {
return core.getInput('message', {required: false})
return core.getInput("message", {required: false})
}
}

View file

@ -1,11 +1,11 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import * as core from "@actions/core"
import * as github from "@actions/github"
import {
findPreviousComment,
createComment,
updateComment,
deleteComment
} from './comment'
} from "./comment"
import {
pullRequestNumber,
repo,
@ -15,21 +15,21 @@ import {
recreate,
deleteOldComment,
githubToken
} from './config'
} from "./config"
async function run(): Promise<undefined> {
if (isNaN(pullRequestNumber) || pullRequestNumber < 1) {
core.info('no pull request numbers given: skip step')
core.info("no pull request numbers given: skip step")
return
}
try {
if (!deleteOldComment && !body) {
throw new Error('Either message or path input is required')
throw new Error("Either message or path input is required")
}
if (deleteOldComment && recreate) {
throw new Error('delete and recreate cannot be both set to true')
throw new Error("delete and recreate cannot be both set to true")
}
const octokit = github.getOctokit(githubToken)