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