mirror of
https://github.com/mshick/add-pr-comment.git
synced 2025-12-31 14:20:32 +11:00
parent
d26bdc4f91
commit
2fe3ecef03
5 changed files with 45 additions and 35 deletions
47
.github/workflows/integration.yml
vendored
47
.github/workflows/integration.yml
vendored
|
|
@ -32,31 +32,30 @@ jobs:
|
|||
run: |
|
||||
npm test
|
||||
|
||||
# dogfood:
|
||||
# name: Dogfood
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - name: Checkout repo
|
||||
# uses: actions/checkout@v3
|
||||
dogfood:
|
||||
name: Dogfood
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# - name: Setup node.js
|
||||
# uses: actions/setup-node@v3
|
||||
# with:
|
||||
# node-version: 16
|
||||
- name: Setup node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16
|
||||
|
||||
# - name: Install dependencies
|
||||
# run: |
|
||||
# npm ci
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
npm ci
|
||||
|
||||
# - name: Build action
|
||||
# run: |
|
||||
# npm run build
|
||||
- name: Build action
|
||||
run: |
|
||||
npm run build
|
||||
|
||||
# - name: Add Comment
|
||||
# uses: ./
|
||||
# with:
|
||||
# message: |
|
||||
# **It works!**
|
||||
# proxy-url: https://add-pr-comment-proxy-73luvmwygq-uc.a.run.app
|
||||
# repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
# repo-token-user-login: "github-actions[bot]"
|
||||
- uses: mshick/add-pr-comment@v2
|
||||
with:
|
||||
message: |
|
||||
**Hello**
|
||||
🌏
|
||||
!
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,9 @@ const inputs = {
|
|||
let issueNumber = 1
|
||||
let getCommitPullsResponse
|
||||
let getIssueCommentsResponse
|
||||
const postIssueCommentsResponse = {
|
||||
id: 42,
|
||||
}
|
||||
|
||||
vi.mock('@actions/core')
|
||||
|
||||
|
|
@ -38,12 +41,7 @@ export const handlers = [
|
|||
rest.post(
|
||||
`https://api.github.com/repos/${repoFullName}/issues/:issueNumber/comments`,
|
||||
(req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
url: 'https://github.com/#example',
|
||||
}),
|
||||
)
|
||||
return res(ctx.status(200), ctx.json(postIssueCommentsResponse))
|
||||
},
|
||||
),
|
||||
rest.get(
|
||||
|
|
@ -112,6 +110,7 @@ describe('add-pr-comment action', () => {
|
|||
|
||||
await expect(run()).resolves.not.toThrow()
|
||||
expect(core.setOutput).toHaveBeenCalledWith('comment-created', 'true')
|
||||
expect(core.setOutput).toHaveBeenCalledWith('comment-id', postIssueCommentsResponse.id)
|
||||
})
|
||||
|
||||
it('creates a comment in an existing PR', async () => {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,13 @@ inputs:
|
|||
proxy-url:
|
||||
description: "Proxy URL for comment creation"
|
||||
required: false
|
||||
outputs:
|
||||
comment-created:
|
||||
description: "Whether a comment was created."
|
||||
required: true
|
||||
comment-id:
|
||||
description: "If a comment was created, the id of it."
|
||||
required: true
|
||||
branding:
|
||||
icon: message-circle
|
||||
color: purple
|
||||
|
|
|
|||
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@mshick/add-pr-comment",
|
||||
"version": "1.0.0",
|
||||
"version": "2.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@mshick/add-pr-comment",
|
||||
"version": "1.0.0",
|
||||
"version": "2.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
|
|
|
|||
11
src/main.ts
11
src/main.ts
|
|
@ -9,7 +9,6 @@ type CreateIssueCommentResponseData =
|
|||
Endpoints['POST /repos/{owner}/{repo}/issues/{issue_number}/comments']['response']['data']
|
||||
type IssuesListCommentsResponseData =
|
||||
Endpoints['GET /repos/{owner}/{repo}/issues/comments']['response']['data']
|
||||
|
||||
interface ListCommitPullsParams {
|
||||
repoToken: string
|
||||
owner: string
|
||||
|
|
@ -174,9 +173,11 @@ const run = async (): Promise<void> => {
|
|||
}
|
||||
}
|
||||
|
||||
let createdCommentData: CreateIssueCommentResponseData | null | undefined
|
||||
|
||||
if (shouldCreateComment) {
|
||||
if (proxyUrl) {
|
||||
await createCommentProxy({
|
||||
createdCommentData = await createCommentProxy({
|
||||
owner,
|
||||
repo,
|
||||
issueNumber,
|
||||
|
|
@ -185,15 +186,19 @@ const run = async (): Promise<void> => {
|
|||
proxyUrl,
|
||||
})
|
||||
} else {
|
||||
await octokit.rest.issues.createComment({
|
||||
const createdComment = await octokit.rest.issues.createComment({
|
||||
owner,
|
||||
repo,
|
||||
issue_number: issueNumber,
|
||||
body: message,
|
||||
})
|
||||
createdCommentData = createdComment.data
|
||||
}
|
||||
}
|
||||
|
||||
if (createdCommentData) {
|
||||
core.setOutput('comment-created', 'true')
|
||||
core.setOutput('comment-id', createdCommentData.id)
|
||||
} else {
|
||||
core.setOutput('comment-created', 'false')
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue