mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-04-24 14:48:50 +00:00
Compare commits
16 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae583cebed | ||
|
|
64ebf23022 | ||
|
|
4aa7401fe7 | ||
|
|
8b12ac0bc7 | ||
|
|
6933bae077 | ||
|
|
9d7bda1a6d | ||
|
|
ac6d945897 | ||
|
|
136562024a | ||
|
|
b3fac8ac2f | ||
|
|
0ea0beb66e | ||
|
|
df6c1bd759 | ||
|
|
3ad213f54e | ||
|
|
58072e51b1 | ||
|
|
313a9382f7 | ||
|
|
159c67730e | ||
|
|
b37c1a1c07 |
10 changed files with 464 additions and 390 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,6 +1,7 @@
|
|||
__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
|
||||
|
|
|
|||
20
README.md
20
README.md
|
|
@ -112,6 +112,22 @@ 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
|
||||
|
|
@ -220,11 +236,11 @@ For more detailed information about permissions, you can read from the link belo
|
|||
|
||||
### `message`
|
||||
|
||||
**Optional** Comment message
|
||||
**Optional** Comment message. When used together with `path`, use `{{{content}}}` as a placeholder in the message where the file content should be inserted.
|
||||
|
||||
### `path`
|
||||
|
||||
**Optional** Path to file containing comment message
|
||||
**Optional** Path to file containing comment message. When `message` is also provided and contains `{{{content}}}`, the file content is embedded at that placeholder position.
|
||||
|
||||
### `number`
|
||||
|
||||
|
|
|
|||
|
|
@ -210,4 +210,61 @@ 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```")
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -52,10 +52,10 @@ inputs:
|
|||
default: "OUTDATED"
|
||||
required: false
|
||||
message:
|
||||
description: "comment message"
|
||||
description: "comment message. When used together with path, use `{{{content}}}` as a placeholder in the message where the file content should be inserted."
|
||||
required: false
|
||||
path:
|
||||
description: "glob path to file(s) containing comment message"
|
||||
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."
|
||||
required: false
|
||||
ignore_empty:
|
||||
description: "Indicates whether to ignore missing or empty messages"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"$schema": "https://biomejs.dev/schemas/2.4.10/schema.json",
|
||||
"$schema": "https://biomejs.dev/schemas/2.4.13/schema.json",
|
||||
"files": {
|
||||
"includes": ["src/**/*.ts"]
|
||||
},
|
||||
|
|
|
|||
18
dist/index.js
generated
vendored
18
dist/index.js
generated
vendored
|
|
@ -29150,6 +29150,19 @@ function getProxyFetch(destinationUrl) {
|
|||
function getApiBaseUrl() {
|
||||
return process.env['GITHUB_API_URL'] || 'https://api.github.com';
|
||||
}
|
||||
function getUserAgentWithOrchestrationId(baseUserAgent) {
|
||||
var _a;
|
||||
const orchId = (_a = process.env['ACTIONS_ORCHESTRATION_ID']) === null || _a === void 0 ? void 0 : _a.trim();
|
||||
if (orchId) {
|
||||
const sanitizedId = orchId.replace(/[^a-z0-9_.-]/gi, '_');
|
||||
const tag = `actions_orchestration_id/${sanitizedId}`;
|
||||
if (baseUserAgent === null || baseUserAgent === void 0 ? void 0 : baseUserAgent.includes(tag))
|
||||
return baseUserAgent;
|
||||
const ua = baseUserAgent ? `${baseUserAgent} ` : '';
|
||||
return `${ua}${tag}`;
|
||||
}
|
||||
return baseUserAgent;
|
||||
}
|
||||
|
||||
function getUserAgent() {
|
||||
if (typeof navigator === "object" && "userAgent" in navigator) {
|
||||
|
|
@ -33068,6 +33081,11 @@ function getOctokitOptions(token, options) {
|
|||
if (auth) {
|
||||
opts.auth = auth;
|
||||
}
|
||||
// Orchestration ID
|
||||
const userAgent = getUserAgentWithOrchestrationId(opts.userAgent);
|
||||
if (userAgent) {
|
||||
opts.userAgent = userAgent;
|
||||
}
|
||||
return opts;
|
||||
}
|
||||
|
||||
|
|
|
|||
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
719
package-lock.json
generated
719
package-lock.json
generated
File diff suppressed because it is too large
Load diff
18
package.json
18
package.json
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "sticky-pull-request-comment",
|
||||
"version": "3.0.3",
|
||||
"version": "3.0.4",
|
||||
"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.0",
|
||||
"@actions/github": "^9.0.0",
|
||||
"@actions/glob": "^0.6.1",
|
||||
"@actions/core": "^3.0.1",
|
||||
"@actions/github": "^9.1.1",
|
||||
"@actions/glob": "^0.7.0",
|
||||
"@octokit/graphql-schema": "^15.26.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "2.4.10",
|
||||
"@biomejs/biome": "2.4.13",
|
||||
"@rollup/plugin-commonjs": "^29.0.2",
|
||||
"@rollup/plugin-node-resolve": "^16.0.3",
|
||||
"@rollup/plugin-typescript": "^12.3.0",
|
||||
"@types/node": "^25.5.2",
|
||||
"@types/node": "^25.6.0",
|
||||
"js-yaml": "^4.1.0",
|
||||
"rimraf": "^6.1.3",
|
||||
"rollup": "^4.60.1",
|
||||
"typescript": "^6.0.2",
|
||||
"vitest": "^4.1.2"
|
||||
"rollup": "^4.60.2",
|
||||
"typescript": "^6.0.3",
|
||||
"vitest": "^4.1.5"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,20 +50,27 @@ 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,
|
||||
})
|
||||
return (await globber.glob()).map(path => readFileSync(path, "utf-8")).join("\n")
|
||||
const fileContent = (await globber.glob())
|
||||
.map(path => readFileSync(path, "utf-8"))
|
||||
.join("\n")
|
||||
if (messageInput) {
|
||||
return messageInput.replace("{{{content}}}", fileContent)
|
||||
}
|
||||
return fileContent
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
} else {
|
||||
return core.getInput("message", {required: false})
|
||||
}
|
||||
return messageInput
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue