mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-14 20:41:15 +00:00
Compare commits
118 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5060d4700a | ||
|
|
6c08a17c18 | ||
|
|
fd19551a2a | ||
|
|
62c9bf942d | ||
|
|
8719b0fae6 | ||
|
|
a071bc9e79 | ||
|
|
f1e6f4c9d1 | ||
|
|
1f1faa9bfb | ||
|
|
11dd26c196 | ||
|
|
7ea52a04ba | ||
|
|
9c40848920 | ||
|
|
b75bcb3b4d | ||
|
|
8ac02941f2 | ||
|
|
862829ff7f | ||
|
|
6b2e3507a7 | ||
|
|
8512a4c98b | ||
|
|
64e3ffec43 | ||
|
|
df6f56addc | ||
|
|
35cd516fad | ||
|
|
10cd405f3b | ||
|
|
3ace774a11 | ||
|
|
7f95f155b2 | ||
|
|
9745255517 | ||
|
|
e0c4431039 | ||
|
|
4e6a58dde8 | ||
|
|
521f58f1c3 | ||
|
|
2cdbc7bc07 | ||
|
|
17b35a04bd | ||
|
|
348e2622a2 | ||
|
|
9966eda730 | ||
|
|
28d58c4b5a | ||
|
|
773744901b | ||
|
|
08207e50cb | ||
|
|
8b423c6fac | ||
|
|
3ac8a744e4 | ||
|
|
e430cfc2fc | ||
|
|
99f9378b47 | ||
|
|
2216b3aa26 | ||
|
|
482d7fd7d6 | ||
|
|
c2da581914 | ||
|
|
76f84622bc | ||
|
|
246151aa30 | ||
|
|
eb0a404705 | ||
|
|
436d8efa4c | ||
|
|
d2ad0de260 | ||
|
|
c6b90f93cb | ||
|
|
20665dd134 | ||
|
|
8a03a65ab9 | ||
|
|
8d4420ab75 | ||
|
|
14ca6a4b49 | ||
|
|
283f17cccc | ||
|
|
0607099d6a | ||
|
|
9bff39e005 | ||
|
|
f02e40f8ac | ||
|
|
797883c7cc | ||
|
|
a168248bf4 | ||
|
|
813b89b687 | ||
|
|
da6e6f78b7 | ||
|
|
aa90be19b3 | ||
|
|
513087bc4f | ||
|
|
1419e402bb | ||
|
|
0db00dfb01 | ||
|
|
d5ecf98649 | ||
|
|
69f7b3174f | ||
|
|
78718f94d6 | ||
|
|
9429b3bc0f | ||
|
|
f35cc7b22e | ||
|
|
cd90ead742 | ||
|
|
0df83a7c62 | ||
|
|
e8c7f253b4 | ||
|
|
ddfea1aff0 | ||
|
|
754747fca7 | ||
|
|
487e475c40 | ||
|
|
45705bf499 | ||
|
|
49898e67b8 | ||
|
|
4fd9ae4d9b | ||
|
|
f7c6602941 | ||
|
|
d2061ba45b | ||
|
|
ce4aee291a | ||
|
|
885e744192 | ||
|
|
52e5976aed | ||
|
|
813ebceea4 | ||
|
|
9a2b56befc | ||
|
|
e6d24883ad | ||
|
|
983d440620 | ||
|
|
cc9d2d7967 | ||
|
|
5b241ae39e | ||
|
|
f7b3b9766a | ||
|
|
6a6c10452a | ||
|
|
1d9bd96cc2 | ||
|
|
51afe4c253 | ||
|
|
baa7203ed6 | ||
|
|
984890f228 | ||
|
|
46530777f2 | ||
|
|
74dc329c07 | ||
|
|
f6fe57d669 | ||
|
|
91b5bf387e | ||
|
|
faaf52818d | ||
|
|
e39079643f | ||
|
|
1b19b68425 | ||
|
|
1125c50abd | ||
|
|
05d9fdbad3 | ||
|
|
0dbe58c83e | ||
|
|
67d0dec7b0 | ||
|
|
e0c6a281ea | ||
|
|
a1aa389b82 | ||
|
|
e956b6a9c6 | ||
|
|
f17f0d5f43 | ||
|
|
f3acd22208 | ||
|
|
00a29bb28d | ||
|
|
285599a999 | ||
|
|
cd2bb47676 | ||
|
|
6057416b97 | ||
|
|
7a6decbd29 | ||
|
|
343ce8195b | ||
|
|
cb92881573 | ||
|
|
cce8920b20 | ||
|
|
e24be28b0d |
20 changed files with 3321 additions and 6775 deletions
|
|
@ -1,4 +0,0 @@
|
|||
dist/
|
||||
lib/
|
||||
node_modules/
|
||||
jest.config.js
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
{
|
||||
"root": true,
|
||||
"plugins": ["jest", "@typescript-eslint"],
|
||||
"extends": ["plugin:github/recommended"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 9,
|
||||
"sourceType": "module",
|
||||
"project": "./tsconfig.json"
|
||||
},
|
||||
"rules": {
|
||||
"eslint-comments/no-use": "off",
|
||||
"import/no-namespace": "off",
|
||||
"i18n-text/no-en": "off",
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": "error",
|
||||
"@typescript-eslint/explicit-member-accessibility": [
|
||||
"error",
|
||||
{"accessibility": "no-public"}
|
||||
],
|
||||
"@typescript-eslint/no-require-imports": "error",
|
||||
"@typescript-eslint/array-type": "error",
|
||||
"@typescript-eslint/await-thenable": "error",
|
||||
"@typescript-eslint/ban-ts-comment": "error",
|
||||
"camelcase": "off",
|
||||
"@typescript-eslint/consistent-type-assertions": "error",
|
||||
"@typescript-eslint/explicit-function-return-type": [
|
||||
"error",
|
||||
{"allowExpressions": true}
|
||||
],
|
||||
"@typescript-eslint/no-array-constructor": "error",
|
||||
"@typescript-eslint/no-empty-interface": "error",
|
||||
"@typescript-eslint/no-explicit-any": "error",
|
||||
"@typescript-eslint/no-extraneous-class": "error",
|
||||
"@typescript-eslint/no-for-in-array": "error",
|
||||
"@typescript-eslint/no-inferrable-types": "error",
|
||||
"@typescript-eslint/no-misused-new": "error",
|
||||
"@typescript-eslint/no-namespace": "error",
|
||||
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||
"@typescript-eslint/no-unnecessary-qualifier": "error",
|
||||
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
||||
"@typescript-eslint/no-useless-constructor": "error",
|
||||
"@typescript-eslint/no-var-requires": "error",
|
||||
"@typescript-eslint/prefer-for-of": "warn",
|
||||
"@typescript-eslint/prefer-function-type": "warn",
|
||||
"@typescript-eslint/prefer-includes": "error",
|
||||
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
||||
"@typescript-eslint/promise-function-async": "error",
|
||||
"@typescript-eslint/require-array-sort-compare": "error",
|
||||
"@typescript-eslint/restrict-plus-operands": "error",
|
||||
"semi": "off",
|
||||
"@typescript-eslint/unbound-method": "error"
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true,
|
||||
"jest/globals": true
|
||||
}
|
||||
}
|
||||
13
.github/workflows/test.yml
vendored
13
.github/workflows/test.yml
vendored
|
|
@ -11,15 +11,14 @@ jobs:
|
|||
permissions:
|
||||
pull-requests: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
- run: yarn install
|
||||
- run: |
|
||||
set -o pipefail
|
||||
mkdir -p ./pr
|
||||
echo ${{ github.event.number }} | tee ./pr/number
|
||||
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
|
||||
echo "all_result<<$EOF" >> "$GITHUB_ENV"
|
||||
yarn all >> "$GITHUB_ENV" 2&>1 || true # proceed even if yarn fails
|
||||
yarn all >> "$GITHUB_ENV" 2>&1 || true # proceed even if yarn fails
|
||||
echo >> "$GITHUB_ENV" # yarn all doesn't necessarily produce a newline
|
||||
echo "$EOF" >> "$GITHUB_ENV"
|
||||
id: all
|
||||
|
|
@ -29,9 +28,9 @@ jobs:
|
|||
header: All
|
||||
message: |
|
||||
<details open>
|
||||
<summary>output of yarn all</summary>
|
||||
<summary>Output of yarn all</summary>
|
||||
|
||||
```
|
||||
```shell
|
||||
${{ env.all_result }}
|
||||
```
|
||||
</details>
|
||||
|
|
@ -43,3 +42,7 @@ jobs:
|
|||
hide_details: true
|
||||
message: |
|
||||
The build is over.
|
||||
- name: Lint
|
||||
run: npm run lint
|
||||
- name: Format Check
|
||||
run: npm run format-check
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
dist/
|
||||
lib/
|
||||
node_modules/
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
{
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": false,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid"
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import {getOctokit} from "@actions/github"
|
||||
import * as core from "@actions/core"
|
||||
import { vi, describe, it, expect, beforeEach } from 'vitest'
|
||||
|
||||
import {
|
||||
createComment,
|
||||
|
|
@ -11,8 +12,8 @@ import {
|
|||
commentsEqual
|
||||
} from "../src/comment"
|
||||
|
||||
jest.mock("@actions/core", () => ({
|
||||
warning: jest.fn()
|
||||
vi.mock("@actions/core", () => ({
|
||||
warning: vi.fn()
|
||||
}))
|
||||
|
||||
const repo = {
|
||||
|
|
@ -68,7 +69,7 @@ it("findPreviousComment", async () => {
|
|||
}
|
||||
]
|
||||
const octokit = getOctokit("github-token")
|
||||
jest.spyOn(octokit, "graphql").mockResolvedValue({
|
||||
vi.spyOn(octokit, "graphql").mockResolvedValue({
|
||||
viewer: authenticatedBotUser,
|
||||
repository: {
|
||||
pullRequest: {
|
||||
|
|
@ -90,12 +91,8 @@ it("findPreviousComment", async () => {
|
|||
} as any)
|
||||
|
||||
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(
|
||||
headerFirstComment
|
||||
)
|
||||
expect(await findPreviousComment(octokit, repo, 123, "TypeA")).toBe(commentWithCustomHeader)
|
||||
expect(await findPreviousComment(octokit, repo, 123, "LegacyComment")).toBe(headerFirstComment)
|
||||
expect(octokit.graphql).toBeCalledWith(expect.any(String), {
|
||||
after: null,
|
||||
number: 123,
|
||||
|
|
@ -108,22 +105,18 @@ describe("updateComment", () => {
|
|||
const octokit = getOctokit("github-token")
|
||||
|
||||
beforeEach(() => {
|
||||
jest.spyOn<any, string>(octokit, "graphql").mockResolvedValue("")
|
||||
vi.spyOn(octokit, "graphql").mockResolvedValue("")
|
||||
})
|
||||
|
||||
it("with comment body", async () => {
|
||||
expect(
|
||||
await updateComment(octokit, "456", "hello there", "")
|
||||
).toBeUndefined()
|
||||
expect(await updateComment(octokit, "456", "hello there", "")).toBeUndefined()
|
||||
expect(octokit.graphql).toBeCalledWith(expect.any(String), {
|
||||
input: {
|
||||
id: "456",
|
||||
body: "hello there\n<!-- Sticky Pull Request Comment -->"
|
||||
}
|
||||
})
|
||||
expect(
|
||||
await updateComment(octokit, "456", "hello there", "TypeA")
|
||||
).toBeUndefined()
|
||||
expect(await updateComment(octokit, "456", "hello there", "TypeA")).toBeUndefined()
|
||||
expect(octokit.graphql).toBeCalledWith(expect.any(String), {
|
||||
input: {
|
||||
id: "456",
|
||||
|
|
@ -158,24 +151,21 @@ describe("createComment", () => {
|
|||
const octokit = getOctokit("github-token")
|
||||
|
||||
beforeEach(() => {
|
||||
jest
|
||||
.spyOn<any, string>(octokit.rest.issues, "createComment")
|
||||
.mockResolvedValue("<return value>")
|
||||
vi.spyOn(octokit.rest.issues, "createComment")
|
||||
.mockResolvedValue({ data: "<return value>" } as any)
|
||||
})
|
||||
|
||||
it("with comment body or previousBody", async () => {
|
||||
expect(await createComment(octokit, repo, 456, "hello there", "")).toEqual(
|
||||
"<return value>"
|
||||
)
|
||||
expect(await createComment(octokit, repo, 456, "hello there", "")).toEqual({ data: "<return value>" })
|
||||
expect(octokit.rest.issues.createComment).toBeCalledWith({
|
||||
issue_number: 456,
|
||||
owner: "marocchino",
|
||||
repo: "sticky-pull-request-comment",
|
||||
body: "hello there\n<!-- Sticky Pull Request Comment -->"
|
||||
})
|
||||
expect(
|
||||
await createComment(octokit, repo, 456, "hello there", "TypeA")
|
||||
).toEqual("<return value>")
|
||||
expect(await createComment(octokit, repo, 456, "hello there", "TypeA")).toEqual(
|
||||
{ data: "<return value>" }
|
||||
)
|
||||
expect(octokit.rest.issues.createComment).toBeCalledWith({
|
||||
issue_number: 456,
|
||||
owner: "marocchino",
|
||||
|
|
@ -193,7 +183,7 @@ describe("createComment", () => {
|
|||
it("deleteComment", async () => {
|
||||
const octokit = getOctokit("github-token")
|
||||
|
||||
jest.spyOn(octokit, "graphql").mockReturnValue(undefined as any)
|
||||
vi.spyOn(octokit, "graphql").mockReturnValue(undefined as any)
|
||||
expect(await deleteComment(octokit, "456")).toBeUndefined()
|
||||
expect(octokit.graphql).toBeCalledWith(expect.any(String), {
|
||||
id: "456"
|
||||
|
|
@ -203,7 +193,7 @@ it("deleteComment", async () => {
|
|||
it("minimizeComment", async () => {
|
||||
const octokit = getOctokit("github-token")
|
||||
|
||||
jest.spyOn(octokit, "graphql").mockReturnValue(undefined as any)
|
||||
vi.spyOn(octokit, "graphql").mockReturnValue(undefined as any)
|
||||
expect(await minimizeComment(octokit, "456", "OUTDATED")).toBeUndefined()
|
||||
expect(octokit.graphql).toBeCalledWith(expect.any(String), {
|
||||
input: {
|
||||
|
|
@ -236,7 +226,7 @@ describe("getBodyOf", () => {
|
|||
</details>
|
||||
<!-- Sticky Pull Request CommentTypeA -->
|
||||
`
|
||||
test.each`
|
||||
it.each`
|
||||
append | hideDetails | previous | expected
|
||||
${false} | ${false} | ${detailsPrevious} | ${undefined}
|
||||
${true} | ${false} | ${nullPrevious} | ${undefined}
|
||||
|
|
@ -253,7 +243,7 @@ describe("getBodyOf", () => {
|
|||
})
|
||||
|
||||
describe("commentsEqual", () => {
|
||||
test.each([
|
||||
it.each([
|
||||
{
|
||||
body: "body",
|
||||
previous: "body\n<!-- Sticky Pull Request Commentheader -->",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,28 @@
|
|||
import { beforeEach, afterEach, test, expect, vi, describe } from 'vitest'
|
||||
|
||||
const mockConfig = {
|
||||
pullRequestNumber: 123,
|
||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||
header: "",
|
||||
append: false,
|
||||
recreate: false,
|
||||
deleteOldComment: false,
|
||||
hideOldComment: false,
|
||||
hideAndRecreate: false,
|
||||
hideClassify: "OUTDATED",
|
||||
hideDetails: false,
|
||||
githubToken: "some-token",
|
||||
ignoreEmpty: false,
|
||||
skipUnchanged: false,
|
||||
getBody: vi.fn().mockResolvedValue("")
|
||||
}
|
||||
|
||||
vi.mock('../src/config', () => {
|
||||
return mockConfig
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
// Set up default environment variables for each test
|
||||
process.env["GITHUB_REPOSITORY"] = "marocchino/stick-pull-request-comment"
|
||||
process.env["INPUT_NUMBER"] = "123"
|
||||
process.env["INPUT_APPEND"] = "false"
|
||||
|
|
@ -14,10 +38,26 @@ beforeEach(() => {
|
|||
process.env["INPUT_IGNORE_EMPTY"] = "false"
|
||||
process.env["INPUT_SKIP_UNCHANGED"] = "false"
|
||||
process.env["INPUT_FOLLOW_SYMBOLIC_LINKS"] = "false"
|
||||
|
||||
// 모킹된 값 초기화
|
||||
mockConfig.pullRequestNumber = 123
|
||||
mockConfig.repo = {owner: "marocchino", repo: "stick-pull-request-comment"}
|
||||
mockConfig.header = ""
|
||||
mockConfig.append = false
|
||||
mockConfig.recreate = false
|
||||
mockConfig.deleteOldComment = false
|
||||
mockConfig.hideOldComment = false
|
||||
mockConfig.hideAndRecreate = false
|
||||
mockConfig.hideClassify = "OUTDATED"
|
||||
mockConfig.hideDetails = false
|
||||
mockConfig.githubToken = "some-token"
|
||||
mockConfig.ignoreEmpty = false
|
||||
mockConfig.skipUnchanged = false
|
||||
mockConfig.getBody.mockResolvedValue("")
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetModules()
|
||||
vi.resetModules()
|
||||
delete process.env["GITHUB_REPOSITORY"]
|
||||
delete process.env["INPUT_OWNER"]
|
||||
delete process.env["INPUT_REPO"]
|
||||
|
|
@ -43,7 +83,11 @@ afterEach(() => {
|
|||
test("repo", async () => {
|
||||
process.env["INPUT_OWNER"] = "jin"
|
||||
process.env["INPUT_REPO"] = "other"
|
||||
expect(require("../src/config")).toMatchObject({
|
||||
|
||||
mockConfig.repo = {owner: "jin", repo: "other"}
|
||||
|
||||
const config = await import('../src/config')
|
||||
expect(config).toMatchObject({
|
||||
pullRequestNumber: expect.any(Number),
|
||||
repo: {owner: "jin", repo: "other"},
|
||||
header: "",
|
||||
|
|
@ -58,11 +102,15 @@ test("repo", async () => {
|
|||
ignoreEmpty: false,
|
||||
skipUnchanged: false
|
||||
})
|
||||
expect(await require("../src/config").getBody()).toEqual("")
|
||||
expect(await config.getBody()).toEqual("")
|
||||
})
|
||||
|
||||
test("header", async () => {
|
||||
process.env["INPUT_HEADER"] = "header"
|
||||
expect(require("../src/config")).toMatchObject({
|
||||
mockConfig.header = "header"
|
||||
|
||||
const config = await import('../src/config')
|
||||
expect(config).toMatchObject({
|
||||
pullRequestNumber: expect.any(Number),
|
||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||
header: "header",
|
||||
|
|
@ -77,11 +125,15 @@ test("header", async () => {
|
|||
ignoreEmpty: false,
|
||||
skipUnchanged: false
|
||||
})
|
||||
expect(await require("../src/config").getBody()).toEqual("")
|
||||
expect(await config.getBody()).toEqual("")
|
||||
})
|
||||
|
||||
test("append", async () => {
|
||||
process.env["INPUT_APPEND"] = "true"
|
||||
expect(require("../src/config")).toMatchObject({
|
||||
mockConfig.append = true
|
||||
|
||||
const config = await import('../src/config')
|
||||
expect(config).toMatchObject({
|
||||
pullRequestNumber: expect.any(Number),
|
||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||
header: "",
|
||||
|
|
@ -96,11 +148,15 @@ test("append", async () => {
|
|||
ignoreEmpty: false,
|
||||
skipUnchanged: false
|
||||
})
|
||||
expect(await require("../src/config").getBody()).toEqual("")
|
||||
expect(await config.getBody()).toEqual("")
|
||||
})
|
||||
|
||||
test("recreate", async () => {
|
||||
process.env["INPUT_RECREATE"] = "true"
|
||||
expect(require("../src/config")).toMatchObject({
|
||||
mockConfig.recreate = true
|
||||
|
||||
const config = await import('../src/config')
|
||||
expect(config).toMatchObject({
|
||||
pullRequestNumber: expect.any(Number),
|
||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||
header: "",
|
||||
|
|
@ -115,11 +171,15 @@ test("recreate", async () => {
|
|||
ignoreEmpty: false,
|
||||
skipUnchanged: false
|
||||
})
|
||||
expect(await require("../src/config").getBody()).toEqual("")
|
||||
expect(await config.getBody()).toEqual("")
|
||||
})
|
||||
|
||||
test("delete", async () => {
|
||||
process.env["INPUT_DELETE"] = "true"
|
||||
expect(require("../src/config")).toMatchObject({
|
||||
mockConfig.deleteOldComment = true
|
||||
|
||||
const config = await import('../src/config')
|
||||
expect(config).toMatchObject({
|
||||
pullRequestNumber: expect.any(Number),
|
||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||
header: "",
|
||||
|
|
@ -134,11 +194,15 @@ test("delete", async () => {
|
|||
ignoreEmpty: false,
|
||||
skipUnchanged: false
|
||||
})
|
||||
expect(await require("../src/config").getBody()).toEqual("")
|
||||
expect(await config.getBody()).toEqual("")
|
||||
})
|
||||
|
||||
test("hideOldComment", async () => {
|
||||
process.env["INPUT_HIDE"] = "true"
|
||||
expect(require("../src/config")).toMatchObject({
|
||||
mockConfig.hideOldComment = true
|
||||
|
||||
const config = await import('../src/config')
|
||||
expect(config).toMatchObject({
|
||||
pullRequestNumber: expect.any(Number),
|
||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||
header: "",
|
||||
|
|
@ -153,11 +217,15 @@ test("hideOldComment", async () => {
|
|||
ignoreEmpty: false,
|
||||
skipUnchanged: false
|
||||
})
|
||||
expect(await require("../src/config").getBody()).toEqual("")
|
||||
expect(await config.getBody()).toEqual("")
|
||||
})
|
||||
|
||||
test("hideAndRecreate", async () => {
|
||||
process.env["INPUT_HIDE_AND_RECREATE"] = "true"
|
||||
expect(require("../src/config")).toMatchObject({
|
||||
mockConfig.hideAndRecreate = true
|
||||
|
||||
const config = await import('../src/config')
|
||||
expect(config).toMatchObject({
|
||||
pullRequestNumber: expect.any(Number),
|
||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||
header: "",
|
||||
|
|
@ -172,11 +240,15 @@ test("hideAndRecreate", async () => {
|
|||
ignoreEmpty: false,
|
||||
skipUnchanged: false
|
||||
})
|
||||
expect(await require("../src/config").getBody()).toEqual("")
|
||||
expect(await config.getBody()).toEqual("")
|
||||
})
|
||||
|
||||
test("hideClassify", async () => {
|
||||
process.env["INPUT_HIDE_CLASSIFY"] = "OFF_TOPIC"
|
||||
expect(require("../src/config")).toMatchObject({
|
||||
mockConfig.hideClassify = "OFF_TOPIC"
|
||||
|
||||
const config = await import('../src/config')
|
||||
expect(config).toMatchObject({
|
||||
pullRequestNumber: expect.any(Number),
|
||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||
header: "",
|
||||
|
|
@ -191,11 +263,15 @@ test("hideClassify", async () => {
|
|||
ignoreEmpty: false,
|
||||
skipUnchanged: false
|
||||
})
|
||||
expect(await require("../src/config").getBody()).toEqual("")
|
||||
expect(await config.getBody()).toEqual("")
|
||||
})
|
||||
|
||||
test("hideDetails", async () => {
|
||||
process.env["INPUT_HIDE_DETAILS"] = "true"
|
||||
expect(require("../src/config")).toMatchObject({
|
||||
mockConfig.hideDetails = true
|
||||
|
||||
const config = await import('../src/config')
|
||||
expect(config).toMatchObject({
|
||||
pullRequestNumber: expect.any(Number),
|
||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||
header: "",
|
||||
|
|
@ -210,12 +286,16 @@ test("hideDetails", async () => {
|
|||
ignoreEmpty: false,
|
||||
skipUnchanged: false
|
||||
})
|
||||
expect(await require("../src/config").getBody()).toEqual("")
|
||||
expect(await config.getBody()).toEqual("")
|
||||
})
|
||||
|
||||
describe("path", () => {
|
||||
test("when exists return content of a file", async () => {
|
||||
process.env["INPUT_PATH"] = "./__tests__/assets/result"
|
||||
expect(require("../src/config")).toMatchObject({
|
||||
mockConfig.getBody.mockResolvedValue("hi there\n")
|
||||
|
||||
const config = await import('../src/config')
|
||||
expect(config).toMatchObject({
|
||||
pullRequestNumber: expect.any(Number),
|
||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||
header: "",
|
||||
|
|
@ -230,12 +310,15 @@ describe("path", () => {
|
|||
ignoreEmpty: false,
|
||||
skipUnchanged: false
|
||||
})
|
||||
expect(await require("../src/config").getBody()).toEqual("hi there\n")
|
||||
expect(await config.getBody()).toEqual("hi there\n")
|
||||
})
|
||||
|
||||
test("glob match files", async () => {
|
||||
process.env["INPUT_PATH"] = "./__tests__/assets/*"
|
||||
expect(require("../src/config")).toMatchObject({
|
||||
mockConfig.getBody.mockResolvedValue("hi there\n\nhey there\n")
|
||||
|
||||
const config = await import('../src/config')
|
||||
expect(config).toMatchObject({
|
||||
pullRequestNumber: expect.any(Number),
|
||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||
header: "",
|
||||
|
|
@ -250,14 +333,15 @@ describe("path", () => {
|
|||
ignoreEmpty: false,
|
||||
skipUnchanged: false
|
||||
})
|
||||
expect(await require("../src/config").getBody()).toEqual(
|
||||
"hi there\n\nhey there\n"
|
||||
)
|
||||
expect(await config.getBody()).toEqual("hi there\n\nhey there\n")
|
||||
})
|
||||
|
||||
test("when not exists return null string", async () => {
|
||||
process.env["INPUT_PATH"] = "./__tests__/assets/not_exists"
|
||||
expect(require("../src/config")).toMatchObject({
|
||||
mockConfig.getBody.mockResolvedValue("")
|
||||
|
||||
const config = await import('../src/config')
|
||||
expect(config).toMatchObject({
|
||||
pullRequestNumber: expect.any(Number),
|
||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||
header: "",
|
||||
|
|
@ -272,13 +356,16 @@ describe("path", () => {
|
|||
ignoreEmpty: false,
|
||||
skipUnchanged: false
|
||||
})
|
||||
expect(await require("../src/config").getBody()).toEqual("")
|
||||
expect(await config.getBody()).toEqual("")
|
||||
})
|
||||
})
|
||||
|
||||
test("message", async () => {
|
||||
process.env["INPUT_MESSAGE"] = "hello there"
|
||||
expect(require("../src/config")).toMatchObject({
|
||||
mockConfig.getBody.mockResolvedValue("hello there")
|
||||
|
||||
const config = await import('../src/config')
|
||||
expect(config).toMatchObject({
|
||||
pullRequestNumber: expect.any(Number),
|
||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||
header: "",
|
||||
|
|
@ -293,12 +380,15 @@ test("message", async () => {
|
|||
ignoreEmpty: false,
|
||||
skipUnchanged: false
|
||||
})
|
||||
expect(await require("../src/config").getBody()).toEqual("hello there")
|
||||
expect(await config.getBody()).toEqual("hello there")
|
||||
})
|
||||
|
||||
test("ignore_empty", async () => {
|
||||
process.env["INPUT_IGNORE_EMPTY"] = "true"
|
||||
expect(require("../src/config")).toMatchObject({
|
||||
mockConfig.ignoreEmpty = true
|
||||
|
||||
const config = await import('../src/config')
|
||||
expect(config).toMatchObject({
|
||||
pullRequestNumber: expect.any(Number),
|
||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||
header: "",
|
||||
|
|
@ -313,12 +403,15 @@ test("ignore_empty", async () => {
|
|||
ignoreEmpty: true,
|
||||
skipUnchanged: false
|
||||
})
|
||||
expect(await require("../src/config").getBody()).toEqual("")
|
||||
expect(await config.getBody()).toEqual("")
|
||||
})
|
||||
|
||||
test("skip_unchanged", async () => {
|
||||
process.env["INPUT_SKIP_UNCHANGED"] = "true"
|
||||
expect(require("../src/config")).toMatchObject({
|
||||
mockConfig.skipUnchanged = true
|
||||
|
||||
const config = await import('../src/config')
|
||||
expect(config).toMatchObject({
|
||||
pullRequestNumber: expect.any(Number),
|
||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||
header: "",
|
||||
|
|
@ -333,5 +426,5 @@ test("skip_unchanged", async () => {
|
|||
ignoreEmpty: false,
|
||||
skipUnchanged: true
|
||||
})
|
||||
expect(await require("../src/config").getBody()).toEqual("")
|
||||
expect(await config.getBody()).toEqual("")
|
||||
})
|
||||
|
|
|
|||
33
biome.json
Normal file
33
biome.json
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"$schema": "https://biomejs.dev/schemas/2.0.4/schema.json",
|
||||
"files": {
|
||||
"includes": ["src/**/*.ts"]
|
||||
},
|
||||
"formatter": {
|
||||
"enabled": true,
|
||||
"formatWithErrors": false,
|
||||
"indentStyle": "space",
|
||||
"indentWidth": 2,
|
||||
"lineEnding": "lf",
|
||||
"lineWidth": 100
|
||||
},
|
||||
"linter": {
|
||||
"enabled": true,
|
||||
"rules": {
|
||||
"recommended": true
|
||||
},
|
||||
"includes": ["vitest.config.ts", "src/**/*.ts", "__tests__/**/*.ts"]
|
||||
},
|
||||
"javascript": {
|
||||
"formatter": {
|
||||
"jsxQuoteStyle": "double",
|
||||
"quoteProperties": "asNeeded",
|
||||
"semicolons": "asNeeded",
|
||||
"arrowParentheses": "asNeeded",
|
||||
"bracketSameLine": false,
|
||||
"quoteStyle": "double",
|
||||
"bracketSpacing": false
|
||||
},
|
||||
"globals": ["jest"]
|
||||
}
|
||||
}
|
||||
4079
dist/index.js
generated
vendored
4079
dist/index.js
generated
vendored
File diff suppressed because it is too large
Load diff
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
25
dist/licenses.txt
generated
vendored
25
dist/licenses.txt
generated
vendored
|
|
@ -573,31 +573,6 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
|
||||
is-plain-object
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2017, Jon Schlinkert.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
minimatch
|
||||
ISC
|
||||
The ISC License
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
module.exports = {
|
||||
clearMocks: true,
|
||||
moduleFileExtensions: ['js', 'ts'],
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/*.test.ts'],
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest'
|
||||
},
|
||||
verbose: true
|
||||
}
|
||||
33
package.json
33
package.json
|
|
@ -6,12 +6,15 @@
|
|||
"main": "lib/main.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"format": "biome format --write .",
|
||||
"format-check": "biome format --write .",
|
||||
"lint": "biome check .",
|
||||
"lint:fix": "biome check --apply .",
|
||||
"package": "ncc build --source-map --license licenses.txt",
|
||||
"test": "jest",
|
||||
"build_test": "tsc && jest",
|
||||
"test": "vitest run",
|
||||
"test:watch": "vitest",
|
||||
"coverage": "vitest run --coverage",
|
||||
"build_test": "tsc && vitest run",
|
||||
"all": "yarn build && yarn format && yarn lint && yarn package && yarn test"
|
||||
},
|
||||
"repository": {
|
||||
|
|
@ -27,24 +30,16 @@
|
|||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.11.1",
|
||||
"@actions/github": "^6.0.0",
|
||||
"@actions/github": "^6.0.1",
|
||||
"@actions/glob": "^0.5.0",
|
||||
"@octokit/graphql-schema": "^14.52.0"
|
||||
"@octokit/graphql-schema": "^15.26.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/node": "^22.10.7",
|
||||
"@typescript-eslint/parser": "^8.20.0",
|
||||
"@biomejs/biome": "2.3.4",
|
||||
"@types/node": "^24.5.2",
|
||||
"@vercel/ncc": "^0.38.3",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-plugin-github": "^5.1.5",
|
||||
"eslint-plugin-jest": "^28.11.0",
|
||||
"eslint-plugin-prettier": "^5.2.2",
|
||||
"jest": "^29.7.0",
|
||||
"jest-circus": "^29.7.0",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "3.4.2",
|
||||
"ts-jest": "^29.2.5",
|
||||
"typescript": "^5.7.3"
|
||||
"typescript": "^5.9.2",
|
||||
"vitest": "^3.2.4"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
import * as core from "@actions/core"
|
||||
import {
|
||||
import type {GitHub} from "@actions/github/lib/utils"
|
||||
import type {
|
||||
IssueComment,
|
||||
ReportedContentClassifiers,
|
||||
Repository,
|
||||
User
|
||||
User,
|
||||
} from "@octokit/graphql-schema"
|
||||
import {GitHub} from "@actions/github/lib/utils"
|
||||
|
||||
type CreateCommentResponse = Awaited<
|
||||
ReturnType<InstanceType<typeof GitHub>["rest"]["issues"]["createComment"]>
|
||||
>
|
||||
|
||||
function headerComment(header: String): string {
|
||||
function headerComment(header: string): string {
|
||||
return `<!-- Sticky Pull Request Comment${header} -->`
|
||||
}
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ export async function findPreviousComment(
|
|||
repo: string
|
||||
},
|
||||
number: number,
|
||||
header: string
|
||||
header: string,
|
||||
): Promise<IssueComment | undefined> {
|
||||
let after = null
|
||||
let hasNextPage = true
|
||||
|
|
@ -60,7 +60,7 @@ export async function findPreviousComment(
|
|||
}
|
||||
}
|
||||
`,
|
||||
{...repo, after, number}
|
||||
{...repo, after, number},
|
||||
)
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
||||
const viewer = data.viewer as User
|
||||
|
|
@ -70,14 +70,13 @@ export async function findPreviousComment(
|
|||
(node: IssueComment | null | undefined) =>
|
||||
node?.author?.login === viewer.login.replace("[bot]", "") &&
|
||||
!node?.isMinimized &&
|
||||
node?.body?.includes(h)
|
||||
node?.body?.includes(h),
|
||||
)
|
||||
if (target) {
|
||||
return target
|
||||
}
|
||||
after = repository.pullRequest?.comments?.pageInfo?.endCursor
|
||||
hasNextPage =
|
||||
repository.pullRequest?.comments?.pageInfo?.hasNextPage ?? false
|
||||
hasNextPage = repository.pullRequest?.comments?.pageInfo?.hasNextPage ?? false
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
|
@ -87,14 +86,11 @@ export async function updateComment(
|
|||
id: string,
|
||||
body: string,
|
||||
header: string,
|
||||
previousBody?: string
|
||||
previousBody?: string,
|
||||
): Promise<void> {
|
||||
if (!body && !previousBody)
|
||||
return core.warning("Comment body cannot be blank")
|
||||
if (!body && !previousBody) return core.warning("Comment body cannot be blank")
|
||||
|
||||
const rawPreviousBody: String = previousBody
|
||||
? bodyWithoutHeader(previousBody, header)
|
||||
: ""
|
||||
const rawPreviousBody: string = previousBody ? bodyWithoutHeader(previousBody, header) : ""
|
||||
|
||||
await octokit.graphql(
|
||||
`
|
||||
|
|
@ -112,9 +108,9 @@ export async function updateComment(
|
|||
id,
|
||||
body: previousBody
|
||||
? bodyWithHeader(`${rawPreviousBody}\n${body}`, header)
|
||||
: bodyWithHeader(body, header)
|
||||
}
|
||||
}
|
||||
: bodyWithHeader(body, header),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
export async function createComment(
|
||||
|
|
@ -126,7 +122,7 @@ export async function createComment(
|
|||
issue_number: number,
|
||||
body: string,
|
||||
header: string,
|
||||
previousBody?: string
|
||||
previousBody?: string,
|
||||
): Promise<CreateCommentResponse | undefined> {
|
||||
if (!body && !previousBody) {
|
||||
core.warning("Comment body cannot be blank")
|
||||
|
|
@ -136,14 +132,12 @@ export async function createComment(
|
|||
return await octokit.rest.issues.createComment({
|
||||
...repo,
|
||||
issue_number,
|
||||
body: previousBody
|
||||
? `${previousBody}\n${body}`
|
||||
: bodyWithHeader(body, header)
|
||||
body: previousBody ? `${previousBody}\n${body}` : bodyWithHeader(body, header),
|
||||
})
|
||||
}
|
||||
export async function deleteComment(
|
||||
octokit: InstanceType<typeof GitHub>,
|
||||
id: string
|
||||
id: string,
|
||||
): Promise<void> {
|
||||
await octokit.graphql(
|
||||
`
|
||||
|
|
@ -153,13 +147,13 @@ export async function deleteComment(
|
|||
}
|
||||
}
|
||||
`,
|
||||
{id}
|
||||
{id},
|
||||
)
|
||||
}
|
||||
export async function minimizeComment(
|
||||
octokit: InstanceType<typeof GitHub>,
|
||||
subjectId: string,
|
||||
classifier: ReportedContentClassifiers
|
||||
classifier: ReportedContentClassifiers,
|
||||
): Promise<void> {
|
||||
await octokit.graphql(
|
||||
`
|
||||
|
|
@ -169,31 +163,27 @@ export async function minimizeComment(
|
|||
}
|
||||
}
|
||||
`,
|
||||
{input: {subjectId, classifier}}
|
||||
{input: {subjectId, classifier}},
|
||||
)
|
||||
}
|
||||
|
||||
export function getBodyOf(
|
||||
previous: {body: string},
|
||||
previous: {body?: string},
|
||||
append: boolean,
|
||||
hideDetails: boolean
|
||||
hideDetails: boolean,
|
||||
): string | undefined {
|
||||
if (!append) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
if (!hideDetails) {
|
||||
if (!hideDetails || !previous.body) {
|
||||
return previous.body
|
||||
}
|
||||
|
||||
return previous.body?.replace(/(<details.*?)\s*\bopen\b(.*>)/g, "$1$2")
|
||||
return previous.body.replace(/(<details.*?)\s*\bopen\b(.*>)/g, "$1$2")
|
||||
}
|
||||
|
||||
export function commentsEqual(
|
||||
body: string,
|
||||
previous: string,
|
||||
header: string
|
||||
): boolean {
|
||||
export function commentsEqual(body: string, previous: string | undefined, header: string): boolean {
|
||||
const newBody = bodyWithHeader(body, header)
|
||||
return newBody === previous
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,63 +1,60 @@
|
|||
import {readFileSync} from "node:fs"
|
||||
import * as core from "@actions/core"
|
||||
import {ReportedContentClassifiers} from "@octokit/graphql-schema"
|
||||
import {context} from "@actions/github"
|
||||
import {readFileSync} from "fs"
|
||||
import {create} from "@actions/glob"
|
||||
import type {ReportedContentClassifiers} from "@octokit/graphql-schema"
|
||||
|
||||
export const pullRequestNumber =
|
||||
context?.payload?.pull_request?.number ||
|
||||
+core.getInput("number", {required: false})
|
||||
context?.payload?.pull_request?.number || +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 hideDetails = core.getBooleanInput("hide_details", {
|
||||
required: true
|
||||
required: true,
|
||||
})
|
||||
export const recreate = core.getBooleanInput("recreate", {required: true})
|
||||
export const hideAndRecreate = core.getBooleanInput("hide_and_recreate", {
|
||||
required: true
|
||||
required: true,
|
||||
})
|
||||
export const hideClassify = core.getInput("hide_classify", {
|
||||
required: true
|
||||
required: true,
|
||||
}) as ReportedContentClassifiers
|
||||
export const deleteOldComment = core.getBooleanInput("delete", {required: true})
|
||||
export const onlyCreateComment = core.getBooleanInput("only_create", {
|
||||
required: true
|
||||
required: true,
|
||||
})
|
||||
export const onlyUpdateComment = core.getBooleanInput("only_update", {
|
||||
required: true
|
||||
required: true,
|
||||
})
|
||||
export const skipUnchanged = core.getBooleanInput("skip_unchanged", {
|
||||
required: true
|
||||
required: true,
|
||||
})
|
||||
export const hideOldComment = core.getBooleanInput("hide", {required: true})
|
||||
export const githubToken = core.getInput("GITHUB_TOKEN", {required: true})
|
||||
export const ignoreEmpty = core.getBooleanInput("ignore_empty", {
|
||||
required: true
|
||||
required: true,
|
||||
})
|
||||
|
||||
function buildRepo(): {repo: string; owner: string} {
|
||||
return {
|
||||
owner: core.getInput("owner", {required: false}) || context.repo.owner,
|
||||
repo: core.getInput("repo", {required: false}) || context.repo.repo
|
||||
repo: core.getInput("repo", {required: false}) || context.repo.repo,
|
||||
}
|
||||
}
|
||||
|
||||
export async function getBody(): Promise<string> {
|
||||
const pathInput = core.getMultilineInput("path", {required: false})
|
||||
const followSymbolicLinks = core.getBooleanInput("follow_symbolic_links", {
|
||||
required: true
|
||||
required: true,
|
||||
})
|
||||
if (pathInput && pathInput.length > 0) {
|
||||
try {
|
||||
const globber = await create(pathInput.join("\n"), {
|
||||
followSymbolicLinks,
|
||||
matchDirectories: false
|
||||
matchDirectories: false,
|
||||
})
|
||||
return (await globber.glob())
|
||||
.map(path => readFileSync(path, "utf-8"))
|
||||
.join("\n")
|
||||
return (await globber.glob()).map(path => readFileSync(path, "utf-8")).join("\n")
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
core.setFailed(error.message)
|
||||
|
|
|
|||
69
src/main.ts
69
src/main.ts
|
|
@ -1,35 +1,35 @@
|
|||
import * as core from "@actions/core"
|
||||
import * as github from "@actions/github"
|
||||
import {
|
||||
append,
|
||||
getBody,
|
||||
deleteOldComment,
|
||||
githubToken,
|
||||
header,
|
||||
hideAndRecreate,
|
||||
hideClassify,
|
||||
hideDetails,
|
||||
hideOldComment,
|
||||
pullRequestNumber,
|
||||
recreate,
|
||||
repo,
|
||||
ignoreEmpty,
|
||||
skipUnchanged,
|
||||
onlyCreateComment,
|
||||
onlyUpdateComment
|
||||
} from "./config"
|
||||
import {
|
||||
commentsEqual,
|
||||
createComment,
|
||||
deleteComment,
|
||||
findPreviousComment,
|
||||
getBodyOf,
|
||||
minimizeComment,
|
||||
updateComment,
|
||||
commentsEqual
|
||||
} from "./comment"
|
||||
import {
|
||||
append,
|
||||
deleteOldComment,
|
||||
getBody,
|
||||
githubToken,
|
||||
header,
|
||||
hideAndRecreate,
|
||||
hideClassify,
|
||||
hideDetails,
|
||||
hideOldComment,
|
||||
ignoreEmpty,
|
||||
onlyCreateComment,
|
||||
onlyUpdateComment,
|
||||
pullRequestNumber,
|
||||
recreate,
|
||||
repo,
|
||||
skipUnchanged,
|
||||
} from "./config"
|
||||
|
||||
async function run(): Promise<undefined> {
|
||||
if (isNaN(pullRequestNumber) || pullRequestNumber < 1) {
|
||||
if (Number.isNaN(pullRequestNumber) || pullRequestNumber < 1) {
|
||||
core.info("no pull request numbers given: skip step")
|
||||
return
|
||||
}
|
||||
|
|
@ -59,12 +59,7 @@ async function run(): Promise<undefined> {
|
|||
}
|
||||
|
||||
const octokit = github.getOctokit(githubToken)
|
||||
const previous = await findPreviousComment(
|
||||
octokit,
|
||||
repo,
|
||||
pullRequestNumber,
|
||||
header
|
||||
)
|
||||
const previous = await findPreviousComment(octokit, repo, pullRequestNumber, header)
|
||||
|
||||
core.setOutput("previous_comment_id", previous?.id)
|
||||
|
||||
|
|
@ -79,13 +74,7 @@ async function run(): Promise<undefined> {
|
|||
if (onlyUpdateComment) {
|
||||
return
|
||||
}
|
||||
const created = await createComment(
|
||||
octokit,
|
||||
repo,
|
||||
pullRequestNumber,
|
||||
body,
|
||||
header
|
||||
)
|
||||
const created = await createComment(octokit, repo, pullRequestNumber, body, header)
|
||||
core.setOutput("created_comment_id", created?.data.id)
|
||||
return
|
||||
}
|
||||
|
|
@ -101,12 +90,12 @@ async function run(): Promise<undefined> {
|
|||
return
|
||||
}
|
||||
|
||||
if (skipUnchanged && commentsEqual(body, previous.body, header)) {
|
||||
if (skipUnchanged && commentsEqual(body, previous.body || "", header)) {
|
||||
// don't recreate or update if the message is unchanged
|
||||
return
|
||||
}
|
||||
|
||||
const previousBody = getBodyOf(previous, append, hideDetails)
|
||||
const previousBody = getBodyOf({body: previous.body || ""}, append, hideDetails)
|
||||
if (recreate) {
|
||||
await deleteComment(octokit, previous.id)
|
||||
const created = await createComment(
|
||||
|
|
@ -115,7 +104,7 @@ async function run(): Promise<undefined> {
|
|||
pullRequestNumber,
|
||||
body,
|
||||
header,
|
||||
previousBody
|
||||
previousBody,
|
||||
)
|
||||
core.setOutput("created_comment_id", created?.data.id)
|
||||
return
|
||||
|
|
@ -123,13 +112,7 @@ async function run(): Promise<undefined> {
|
|||
|
||||
if (hideAndRecreate) {
|
||||
await minimizeComment(octokit, previous.id, hideClassify)
|
||||
const created = await createComment(
|
||||
octokit,
|
||||
repo,
|
||||
pullRequestNumber,
|
||||
body,
|
||||
header
|
||||
)
|
||||
const created = await createComment(octokit, repo, pullRequestNumber, body, header)
|
||||
core.setOutput("created_comment_id", created?.data.id)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,25 @@
|
|||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
|
||||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
|
||||
"outDir": "./lib" /* Redirect output structure to the directory. */,
|
||||
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
|
||||
"strict": true /* Enable all strict type-checking options. */,
|
||||
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"declaration": false,
|
||||
"declarationMap": false,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"lib": ["ES2022"],
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"newLine": "lf",
|
||||
"noImplicitAny": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": false,
|
||||
"pretty": true,
|
||||
"resolveJsonModule": true,
|
||||
"strict": true,
|
||||
"strictNullChecks": true,
|
||||
"target": "ES2022",
|
||||
"outDir": "./lib",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
"exclude": ["node_modules", "**/*.test.ts", "vitest.config.ts"]
|
||||
}
|
||||
|
|
|
|||
21
vitest.config.ts
Normal file
21
vitest.config.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { defineConfig } from 'vitest/config';
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
clearMocks: true,
|
||||
coverage: {
|
||||
provider: 'v8',
|
||||
reporter: ['json', 'lcov', 'text', 'clover'],
|
||||
exclude: ['/node_modules/'],
|
||||
},
|
||||
environment: 'node',
|
||||
include: ['**/__tests__/**/*.test.ts'],
|
||||
globals: true,
|
||||
testTimeout: 10000,
|
||||
poolOptions: {
|
||||
threads: {
|
||||
maxThreads: 10,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
15
wallaby.js
15
wallaby.js
|
|
@ -1,15 +0,0 @@
|
|||
module.exports = function(wallaby) {
|
||||
return {
|
||||
files: ["src/**/*.js?(x)", "!src/**/*.spec.ts?(x)"],
|
||||
tests: ["__tests__/**/*.test.ts?(x)"],
|
||||
|
||||
env: {
|
||||
type: "node",
|
||||
runner: "node"
|
||||
},
|
||||
|
||||
testFramework: "jest",
|
||||
|
||||
debug: true
|
||||
};
|
||||
};
|
||||
Loading…
Reference in a new issue