mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-05-23 19:35:54 +00:00
Some checks failed
Test / test (push) Has been cancelled
* Initial plan
* Add prefix and suffix inputs to wrap comment body
Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com>
* feat: support combining path and message inputs using $path placeholder
Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com>
* feat: use {path} placeholder and remove prefix/suffix inputs
Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com>
* feat: rename placeholder from {path} to {{{content}}}
Agent-Logs-Url: https://github.com/marocchino/sticky-pull-request-comment/sessions/72744cd4-264e-4c06-95d4-6fdec3446f90
Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com>
* fix: when message has no {{{content}}} placeholder, return message as-is
Agent-Logs-Url: https://github.com/marocchino/sticky-pull-request-comment/sessions/b6492aa3-c55c-41f7-b43e-12cc3f2c3002
Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com>
* refactor: simplify {{{content}}} replacement — drop includes guard and regex
Agent-Logs-Url: https://github.com/marocchino/sticky-pull-request-comment/sessions/81112a7b-0e6d-4f21-ad36-530af7c0259f
Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com>
* chore: remove accidentally committed dist/src/* and add to .gitignore
Agent-Logs-Url: https://github.com/marocchino/sticky-pull-request-comment/sessions/7ced80dd-92a9-46ad-b667-bf5ceaa129ea
Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: marocchino <128431+marocchino@users.noreply.github.com>
76 lines
2.6 KiB
TypeScript
76 lines
2.6 KiB
TypeScript
import {readFileSync} from "node:fs"
|
|
import * as core from "@actions/core"
|
|
import {context} from "@actions/github"
|
|
import {create} from "@actions/glob"
|
|
import type {ReportedContentClassifiers} from "@octokit/graphql-schema"
|
|
|
|
export const pullRequestNumber =
|
|
+core.getInput("number_force", {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,
|
|
})
|
|
export const recreate = core.getBooleanInput("recreate", {required: true})
|
|
export const hideAndRecreate = core.getBooleanInput("hide_and_recreate", {
|
|
required: true,
|
|
})
|
|
export const hideClassify = core.getInput("hide_classify", {
|
|
required: true,
|
|
}) as ReportedContentClassifiers
|
|
export const deleteOldComment = core.getBooleanInput("delete", {required: true})
|
|
export const onlyCreateComment = core.getBooleanInput("only_create", {
|
|
required: true,
|
|
})
|
|
export const onlyUpdateComment = core.getBooleanInput("only_update", {
|
|
required: true,
|
|
})
|
|
export const skipUnchanged = core.getBooleanInput("skip_unchanged", {
|
|
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,
|
|
})
|
|
|
|
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,
|
|
}
|
|
}
|
|
|
|
export async function getBody(): Promise<string> {
|
|
const pathInput = core.getMultilineInput("path", {required: false})
|
|
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
|
|
} catch (error) {
|
|
if (error instanceof Error) {
|
|
core.setFailed(error.message)
|
|
}
|
|
return ""
|
|
}
|
|
}
|
|
return messageInput
|
|
}
|