Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8f487347ab | |||
| 6e06a5b4b9 | |||
| c4fbe28317 | |||
| 6ef1707d4b |
@@ -0,0 +1,49 @@
|
||||
name: Test
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- run: npm ci
|
||||
- run: |
|
||||
set -o pipefail
|
||||
mkdir -p ./pr
|
||||
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
|
||||
echo "all_result<<$EOF" >> "$GITHUB_ENV"
|
||||
npm run all >> "$GITHUB_ENV" 2>&1 || true # proceed even if npm run all fails
|
||||
echo >> "$GITHUB_ENV" # npm run all doesn't necessarily produce a newline
|
||||
echo "$EOF" >> "$GITHUB_ENV"
|
||||
id: all
|
||||
- uses: ./
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
with:
|
||||
header: All
|
||||
message: |
|
||||
<details open>
|
||||
<summary>Output of npm run all</summary>
|
||||
|
||||
```shell
|
||||
${{ env.all_result }}
|
||||
```
|
||||
</details>
|
||||
- uses: ./
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
with:
|
||||
header: All
|
||||
append: true
|
||||
hide_details: true
|
||||
message: |
|
||||
The build is over.
|
||||
- name: Lint
|
||||
run: npm run lint
|
||||
- name: Format Check
|
||||
run: npm run format-check
|
||||
@@ -1,7 +1,6 @@
|
||||
__tests__/runner/*
|
||||
|
||||
lib/*
|
||||
dist/src/
|
||||
rollup.config.js
|
||||
# ^^^ compiled output of rollup.config.ts (generated by --configPlugin at build time)
|
||||
# comment out in distribution branches
|
||||
|
||||
@@ -112,22 +112,6 @@ with:
|
||||
path: path-to-comment-contents.txt
|
||||
```
|
||||
|
||||
### Embed file content inside a message template
|
||||
|
||||
Use `{{{content}}}` as a placeholder in the `message` to insert file content at that position.
|
||||
|
||||
````yaml
|
||||
- name: Run Test
|
||||
run: rake test > result.txt
|
||||
- uses: marocchino/sticky-pull-request-comment@v3
|
||||
with:
|
||||
path: result.txt
|
||||
message: |
|
||||
```
|
||||
{{{content}}}
|
||||
```
|
||||
````
|
||||
|
||||
### Delete the previous comment and add a comment at the end
|
||||
|
||||
```yaml
|
||||
@@ -236,11 +220,11 @@ For more detailed information about permissions, you can read from the link belo
|
||||
|
||||
### `message`
|
||||
|
||||
**Optional** Comment message. When used together with `path`, use `{{{content}}}` as a placeholder in the message where the file content should be inserted.
|
||||
**Optional** Comment message
|
||||
|
||||
### `path`
|
||||
|
||||
**Optional** Path to file containing comment message. When `message` is also provided and contains `{{{content}}}`, the file content is embedded at that placeholder position.
|
||||
**Optional** Path to file containing comment message
|
||||
|
||||
### `number`
|
||||
|
||||
|
||||
@@ -210,61 +210,4 @@ describe("getBody", () => {
|
||||
expect(await config.getBody()).toBe("")
|
||||
expect(core.setFailed).toHaveBeenCalledWith("glob error")
|
||||
})
|
||||
|
||||
test("embeds file content in message when {{{content}}} placeholder is used", async () => {
|
||||
const {config, core} = await loadConfig()
|
||||
vi.mocked(core.getMultilineInput).mockReturnValue(["__tests__/assets/result"])
|
||||
vi.mocked(core.getInput).mockImplementation(name => {
|
||||
if (name === "message") return "```\n{{{content}}}\n```"
|
||||
return ""
|
||||
})
|
||||
mockGlobCreate.mockResolvedValue({
|
||||
glob: vi.fn().mockResolvedValue([resolve("__tests__/assets/result")]),
|
||||
})
|
||||
expect(await config.getBody()).toBe("```\nhi there\n\n```")
|
||||
})
|
||||
|
||||
test("replaces {{{content}}} in message with file content", async () => {
|
||||
const {config, core} = await loadConfig()
|
||||
vi.mocked(core.getMultilineInput).mockReturnValue(["__tests__/assets/result"])
|
||||
vi.mocked(core.getInput).mockImplementation(name => {
|
||||
if (name === "message") return "{{{content}}}\n---\n{{{content}}}"
|
||||
return ""
|
||||
})
|
||||
mockGlobCreate.mockResolvedValue({
|
||||
glob: vi.fn().mockResolvedValue([resolve("__tests__/assets/result")]),
|
||||
})
|
||||
expect(await config.getBody()).toBe("hi there\n\n---\n{{{content}}}")
|
||||
})
|
||||
|
||||
test("uses message as body when path is provided but message has no {{{content}}} placeholder", async () => {
|
||||
const {config, core} = await loadConfig()
|
||||
vi.mocked(core.getMultilineInput).mockReturnValue(["__tests__/assets/result"])
|
||||
vi.mocked(core.getInput).mockImplementation(name => {
|
||||
if (name === "message") return "no placeholder here"
|
||||
return ""
|
||||
})
|
||||
mockGlobCreate.mockResolvedValue({
|
||||
glob: vi.fn().mockResolvedValue([resolve("__tests__/assets/result")]),
|
||||
})
|
||||
expect(await config.getBody()).toBe("no placeholder here")
|
||||
})
|
||||
|
||||
test("embeds multiple files content in message when {{{content}}} placeholder is used", async () => {
|
||||
const {config, core} = await loadConfig()
|
||||
vi.mocked(core.getMultilineInput).mockReturnValue(["__tests__/assets/*"])
|
||||
vi.mocked(core.getInput).mockImplementation(name => {
|
||||
if (name === "message") return "```\n{{{content}}}\n```"
|
||||
return ""
|
||||
})
|
||||
mockGlobCreate.mockResolvedValue({
|
||||
glob: vi
|
||||
.fn()
|
||||
.mockResolvedValue([
|
||||
resolve("__tests__/assets/result"),
|
||||
resolve("__tests__/assets/result2"),
|
||||
]),
|
||||
})
|
||||
expect(await config.getBody()).toBe("```\nhi there\n\nhey there\n\n```")
|
||||
})
|
||||
})
|
||||
|
||||
+2
-2
@@ -52,10 +52,10 @@ inputs:
|
||||
default: "OUTDATED"
|
||||
required: false
|
||||
message:
|
||||
description: "comment message. When used together with path, use `{{{content}}}` as a placeholder in the message where the file content should be inserted."
|
||||
description: "comment message"
|
||||
required: false
|
||||
path:
|
||||
description: "glob path to file(s) containing comment message. When message is also provided and contains `{{{content}}}`, the file content is embedded at that placeholder position."
|
||||
description: "glob path to file(s) containing comment message"
|
||||
required: false
|
||||
ignore_empty:
|
||||
description: "Indicates whether to ignore missing or empty messages"
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "https://biomejs.dev/schemas/2.4.14/schema.json",
|
||||
"$schema": "https://biomejs.dev/schemas/2.4.10/schema.json",
|
||||
"files": {
|
||||
"includes": ["src/**/*.ts"]
|
||||
},
|
||||
|
||||
+1326
-2437
File diff suppressed because it is too large
Load Diff
+1
-1
File diff suppressed because one or more lines are too long
Generated
+372
-347
File diff suppressed because it is too large
Load Diff
+9
-9
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sticky-pull-request-comment",
|
||||
"version": "3.0.4",
|
||||
"version": "3.0.1",
|
||||
"private": true,
|
||||
"description": "Create comment on pull request, if exists update that comment.",
|
||||
"main": "lib/main.js",
|
||||
@@ -29,21 +29,21 @@
|
||||
"author": "marocchino",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^3.0.1",
|
||||
"@actions/github": "^9.1.1",
|
||||
"@actions/glob": "^0.7.0",
|
||||
"@actions/core": "^3.0.0",
|
||||
"@actions/github": "^9.0.0",
|
||||
"@actions/glob": "^0.6.1",
|
||||
"@octokit/graphql-schema": "^15.26.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "2.4.14",
|
||||
"@biomejs/biome": "2.4.10",
|
||||
"@rollup/plugin-commonjs": "^29.0.2",
|
||||
"@rollup/plugin-node-resolve": "^16.0.3",
|
||||
"@rollup/plugin-typescript": "^12.3.0",
|
||||
"@types/node": "^25.6.2",
|
||||
"@types/node": "^25.5.2",
|
||||
"js-yaml": "^4.1.0",
|
||||
"rimraf": "^6.1.3",
|
||||
"rollup": "^4.60.3",
|
||||
"typescript": "^6.0.3",
|
||||
"vitest": "^4.1.5"
|
||||
"rollup": "^4.60.1",
|
||||
"typescript": "^6.0.2",
|
||||
"vitest": "^4.1.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,12 @@ import typescript from "@rollup/plugin-typescript"
|
||||
const config = {
|
||||
context: "globalThis",
|
||||
input: "src/main.ts",
|
||||
onwarn: (warning, warn) => {
|
||||
if (warning.code === "CIRCULAR_DEPENDENCY" && warning.ids?.every(id => id.includes("/node_modules/"))) {
|
||||
return
|
||||
}
|
||||
warn(warning)
|
||||
},
|
||||
output: {
|
||||
exports: "auto",
|
||||
file: "dist/index.js",
|
||||
|
||||
+3
-10
@@ -50,27 +50,20 @@ export async function getBody(): Promise<string> {
|
||||
const followSymbolicLinks = core.getBooleanInput("follow_symbolic_links", {
|
||||
required: true,
|
||||
})
|
||||
const messageInput = core.getInput("message", {required: false})
|
||||
|
||||
if (pathInput && pathInput.length > 0) {
|
||||
try {
|
||||
const globber = await create(pathInput.join("\n"), {
|
||||
followSymbolicLinks,
|
||||
matchDirectories: false,
|
||||
})
|
||||
const fileContent = (await globber.glob())
|
||||
.map(path => readFileSync(path, "utf-8"))
|
||||
.join("\n")
|
||||
if (messageInput) {
|
||||
return messageInput.replace("{{{content}}}", fileContent)
|
||||
}
|
||||
return fileContent
|
||||
return (await globber.glob()).map(path => readFileSync(path, "utf-8")).join("\n")
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
} else {
|
||||
return core.getInput("message", {required: false})
|
||||
}
|
||||
return messageInput
|
||||
}
|
||||
|
||||
+3
-3
@@ -15,13 +15,13 @@
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": false,
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"types": ["node"],
|
||||
"pretty": true,
|
||||
"resolveJsonModule": true,
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"strictNullChecks": true,
|
||||
"target": "ES2022",
|
||||
"types": ["node"]
|
||||
"target": "ES2022"
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts", "dist"],
|
||||
"include": ["src"]
|
||||
|
||||
Reference in New Issue
Block a user