mirror of
https://github.com/mshick/add-pr-comment.git
synced 2025-12-31 22:29:45 +11:00
adds support for message-path (#58)
This commit is contained in:
parent
841d232c5a
commit
cd100c8b09
8 changed files with 110 additions and 19 deletions
20
src/main.ts
20
src/main.ts
|
|
@ -2,6 +2,7 @@ import * as core from '@actions/core'
|
|||
import * as github from '@actions/github'
|
||||
import { HttpClient } from '@actions/http-client'
|
||||
import { Endpoints, RequestHeaders } from '@octokit/types'
|
||||
import fs from 'node:fs/promises'
|
||||
|
||||
type ListCommitPullsResponseData =
|
||||
Endpoints['GET /repos/{owner}/{repo}/commits/{commit_sha}/pulls']['response']['data']
|
||||
|
|
@ -88,6 +89,7 @@ const isMessagePresent = (
|
|||
interface AddPrCommentInputs {
|
||||
allowRepeats: boolean
|
||||
message: string
|
||||
messagePath: string
|
||||
proxyUrl?: string
|
||||
repoToken?: string
|
||||
repoTokenUserLogin?: string
|
||||
|
|
@ -97,6 +99,7 @@ const getInputs = (): AddPrCommentInputs => {
|
|||
return {
|
||||
allowRepeats: Boolean(core.getInput('allow-repeats') === 'true'),
|
||||
message: core.getInput('message'),
|
||||
messagePath: core.getInput('message-path'),
|
||||
proxyUrl: core.getInput('proxy-url').replace(/\/$/, ''),
|
||||
repoToken: core.getInput('repo-token') || process.env['GITHUB_TOKEN'],
|
||||
repoTokenUserLogin: core.getInput('repo-token-user-login'),
|
||||
|
|
@ -105,7 +108,8 @@ const getInputs = (): AddPrCommentInputs => {
|
|||
|
||||
const run = async (): Promise<void> => {
|
||||
try {
|
||||
const { allowRepeats, message, repoToken, repoTokenUserLogin, proxyUrl } = getInputs()
|
||||
const { allowRepeats, message, messagePath, repoToken, repoTokenUserLogin, proxyUrl } =
|
||||
getInputs()
|
||||
|
||||
if (!repoToken) {
|
||||
throw new Error(
|
||||
|
|
@ -113,6 +117,20 @@ const run = async (): Promise<void> => {
|
|||
)
|
||||
}
|
||||
|
||||
if (message && messagePath) {
|
||||
throw new Error('must specify only one, message or message-path')
|
||||
}
|
||||
|
||||
let messageText = message
|
||||
|
||||
if (messagePath) {
|
||||
messageText = await fs.readFile(messagePath, { encoding: 'utf8' })
|
||||
}
|
||||
|
||||
if (!messageText) {
|
||||
throw new Error('could not get message text, check your message-path')
|
||||
}
|
||||
|
||||
const {
|
||||
payload: { pull_request: pullRequest, issue, repository },
|
||||
sha: commitSha,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue