mirror of
https://github.com/mshick/add-pr-comment.git
synced 2025-12-31 14:20:32 +11:00
project clean up and update
This commit is contained in:
parent
07f690343c
commit
94fd7ef52f
14 changed files with 12140 additions and 6559 deletions
|
|
@ -1,14 +0,0 @@
|
||||||
# editorconfig.org
|
|
||||||
|
|
||||||
root = true
|
|
||||||
|
|
||||||
[*]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 2
|
|
||||||
end_of_line = lf
|
|
||||||
charset = utf-8
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
insert_final_newline = true
|
|
||||||
|
|
||||||
[*.md]
|
|
||||||
trim_trailing_whitespace = false
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
*.js
|
|
||||||
*.txt
|
|
||||||
!/.github
|
|
||||||
45
.eslintrc.js
45
.eslintrc.js
|
|
@ -1,45 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
root: true,
|
|
||||||
extends: ['eslint:recommended', 'plugin:prettier/recommended', 'plugin:import/errors', 'plugin:import/warnings'],
|
|
||||||
plugins: ['prettier'],
|
|
||||||
env: {
|
|
||||||
node: true,
|
|
||||||
es6: true,
|
|
||||||
},
|
|
||||||
parserOptions: {
|
|
||||||
ecmaVersion: 2018,
|
|
||||||
},
|
|
||||||
settings: {
|
|
||||||
'import/parsers': {
|
|
||||||
'@typescript-eslint/parser': ['.ts', '.tsx'],
|
|
||||||
},
|
|
||||||
'import/resolver': {
|
|
||||||
typescript: {
|
|
||||||
alwaysTryTypes: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
overrides: [
|
|
||||||
{
|
|
||||||
files: ['**/*.ts'],
|
|
||||||
parser: '@typescript-eslint/parser',
|
|
||||||
plugins: ['@typescript-eslint'],
|
|
||||||
extends: [
|
|
||||||
'plugin:import/typescript',
|
|
||||||
'plugin:@typescript-eslint/recommended',
|
|
||||||
'prettier/@typescript-eslint',
|
|
||||||
'plugin:prettier/recommended',
|
|
||||||
],
|
|
||||||
parserOptions: {
|
|
||||||
ecmaVersion: 2018,
|
|
||||||
project: ['tsconfig.json'],
|
|
||||||
sourceType: 'module',
|
|
||||||
tsconfigRootDir: __dirname,
|
|
||||||
},
|
|
||||||
env: {
|
|
||||||
node: true,
|
|
||||||
es6: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
12
.github/workflows/integration.yml
vendored
12
.github/workflows/integration.yml
vendored
|
|
@ -9,12 +9,12 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Setup node.js
|
- name: Setup node.js
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: "12.x"
|
node-version: 16
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
|
|
@ -37,12 +37,12 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Setup node.js
|
- name: Setup node.js
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: "12.x"
|
node-version: 16
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
1
.node-version
Normal file
1
.node-version
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
v16
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
arrowParens: 'avoid',
|
|
||||||
bracketSpacing: false,
|
|
||||||
printWidth: 100,
|
|
||||||
semi: false,
|
|
||||||
singleQuote: true,
|
|
||||||
tabWidth: 2,
|
|
||||||
trailingComma: 'es5',
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import * as fs from 'fs'
|
|
||||||
import * as path from 'path'
|
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as github from '@actions/github'
|
import * as github from '@actions/github'
|
||||||
import { WebhookPayload } from '@actions/github/lib/interfaces'
|
import { WebhookPayload } from '@actions/github/lib/interfaces'
|
||||||
|
import * as fs from 'fs'
|
||||||
import nock from 'nock'
|
import nock from 'nock'
|
||||||
|
import * as path from 'path'
|
||||||
import run from '../src/main'
|
import run from '../src/main'
|
||||||
import apiResponse from './sample-pulls-api-response.json'
|
import apiResponse from './sample-pulls-api-response.json'
|
||||||
|
|
||||||
|
|
@ -12,8 +12,12 @@ const repoToken = '12345'
|
||||||
const userLogin = 'github-actions[bot]'
|
const userLogin = 'github-actions[bot]'
|
||||||
const commitSha = 'abc123'
|
const commitSha = 'abc123'
|
||||||
const simpleMessage = 'hello world'
|
const simpleMessage = 'hello world'
|
||||||
const multilineMessage = fs.readFileSync(path.resolve(__dirname, './message-windows.txt')).toString()
|
const multilineMessage = fs
|
||||||
const multilineMessageWindows = fs.readFileSync(path.resolve(__dirname, './message-windows.txt')).toString()
|
.readFileSync(path.resolve(__dirname, './message-windows.txt'))
|
||||||
|
.toString()
|
||||||
|
const multilineMessageWindows = fs
|
||||||
|
.readFileSync(path.resolve(__dirname, './message-windows.txt'))
|
||||||
|
.toString()
|
||||||
|
|
||||||
let issueNumber = 1
|
let issueNumber = 1
|
||||||
|
|
||||||
|
|
@ -81,7 +85,10 @@ describe('add-pr-comment action', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
nock('https://api.github.com')
|
nock('https://api.github.com')
|
||||||
.post(`/repos/${repoFullName}/issues/${issueNumber}/comments`, ({body}) => body === simpleMessage)
|
.post(
|
||||||
|
`/repos/${repoFullName}/issues/${issueNumber}/comments`,
|
||||||
|
({ body }) => body === simpleMessage,
|
||||||
|
)
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
url: 'https://github.com/#example',
|
url: 'https://github.com/#example',
|
||||||
})
|
})
|
||||||
|
|
@ -119,7 +126,10 @@ describe('add-pr-comment action', () => {
|
||||||
.reply(200, apiResponse.result)
|
.reply(200, apiResponse.result)
|
||||||
|
|
||||||
nock('https://api.github.com')
|
nock('https://api.github.com')
|
||||||
.post(`/repos/${repoFullName}/issues/${issueNumber}/comments`, ({body}) => body === simpleMessage)
|
.post(
|
||||||
|
`/repos/${repoFullName}/issues/${issueNumber}/comments`,
|
||||||
|
({ body }) => body === simpleMessage,
|
||||||
|
)
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
url: 'https://github.com/#example',
|
url: 'https://github.com/#example',
|
||||||
})
|
})
|
||||||
|
|
@ -150,7 +160,9 @@ describe('add-pr-comment action', () => {
|
||||||
return originalSetOutput(key, value)
|
return originalSetOutput(key, value)
|
||||||
})
|
})
|
||||||
|
|
||||||
nock('https://api.github.com').get(`/repos/${repoFullName}/commits/${commitSha}/pulls`).reply(200, [])
|
nock('https://api.github.com')
|
||||||
|
.get(`/repos/${repoFullName}/commits/${commitSha}/pulls`)
|
||||||
|
.reply(200, [])
|
||||||
|
|
||||||
await run()
|
await run()
|
||||||
})
|
})
|
||||||
|
|
@ -180,7 +192,9 @@ describe('add-pr-comment action', () => {
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
nock('https://api.github.com').get(`/repos/${repoFullName}/issues/1/comments`).reply(200, replyBody)
|
nock('https://api.github.com')
|
||||||
|
.get(`/repos/${repoFullName}/issues/1/comments`)
|
||||||
|
.reply(200, replyBody)
|
||||||
|
|
||||||
await run()
|
await run()
|
||||||
})
|
})
|
||||||
|
|
@ -209,7 +223,9 @@ describe('add-pr-comment action', () => {
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
nock('https://api.github.com').get(`/repos/${repoFullName}/issues/1/comments`).reply(200, replyBody)
|
nock('https://api.github.com')
|
||||||
|
.get(`/repos/${repoFullName}/issues/1/comments`)
|
||||||
|
.reply(200, replyBody)
|
||||||
|
|
||||||
await run()
|
await run()
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,10 @@
|
||||||
"tree_id": "055d2e982d249db10b8dd73fc1745ff97576ecc9",
|
"tree_id": "055d2e982d249db10b8dd73fc1745ff97576ecc9",
|
||||||
"url": "https://github.com/mshick/add-pr-comment/commit/566e30ed2c7a061fa9e14117c14eb385a197e750"
|
"url": "https://github.com/mshick/add-pr-comment/commit/566e30ed2c7a061fa9e14117c14eb385a197e750"
|
||||||
},
|
},
|
||||||
"pusher": { "email": "m@shick.us", "name": "mshick" },
|
"pusher": {
|
||||||
|
"email": "m@shick.us",
|
||||||
|
"name": "mshick"
|
||||||
|
},
|
||||||
"ref": "refs/heads/master",
|
"ref": "refs/heads/master",
|
||||||
"repository": {
|
"repository": {
|
||||||
"archive_url": "https://api.github.com/repos/mshick/add-pr-comment/{archive_format}{/ref}",
|
"archive_url": "https://api.github.com/repos/mshick/add-pr-comment/{archive_format}{/ref}",
|
||||||
|
|
|
||||||
|
|
@ -305,7 +305,9 @@
|
||||||
"self": {
|
"self": {
|
||||||
"href": "https://api.github.com/repos/mshick/add-pr-comment/pulls/6"
|
"href": "https://api.github.com/repos/mshick/add-pr-comment/pulls/6"
|
||||||
},
|
},
|
||||||
"html": { "href": "https://github.com/mshick/add-pr-comment/pull/6" },
|
"html": {
|
||||||
|
"href": "https://github.com/mshick/add-pr-comment/pull/6"
|
||||||
|
},
|
||||||
"issue": {
|
"issue": {
|
||||||
"href": "https://api.github.com/repos/mshick/add-pr-comment/issues/6"
|
"href": "https://api.github.com/repos/mshick/add-pr-comment/issues/6"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -21,5 +21,5 @@ branding:
|
||||||
icon: message-circle
|
icon: message-circle
|
||||||
color: purple
|
color: purple
|
||||||
runs:
|
runs:
|
||||||
using: "node12"
|
using: "node16"
|
||||||
main: "dist/index.js"
|
main: "dist/index.js"
|
||||||
|
|
|
||||||
27
lib/main.js
27
lib/main.js
|
|
@ -1,7 +1,11 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
if (k2 === undefined) k2 = k;
|
if (k2 === undefined) k2 = k;
|
||||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||||
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||||
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||||
|
}
|
||||||
|
Object.defineProperty(o, k2, desc);
|
||||||
}) : (function(o, m, k, k2) {
|
}) : (function(o, m, k, k2) {
|
||||||
if (k2 === undefined) k2 = k;
|
if (k2 === undefined) k2 = k;
|
||||||
o[k2] = m[k];
|
o[k2] = m[k];
|
||||||
|
|
@ -14,7 +18,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
if (mod && mod.__esModule) return mod;
|
if (mod && mod.__esModule) return mod;
|
||||||
var result = {};
|
var result = {};
|
||||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||||
__setModuleDefault(result, mod);
|
__setModuleDefault(result, mod);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
@ -46,10 +50,10 @@ const isMessagePresent = (message, comments, login) => {
|
||||||
const messageClean = message.replace(cleanRe, '');
|
const messageClean = message.replace(cleanRe, '');
|
||||||
return comments.some(({ user, body }) => {
|
return comments.some(({ user, body }) => {
|
||||||
// If a username is provided we can save on a bit of processing
|
// If a username is provided we can save on a bit of processing
|
||||||
if (login && user.login !== login) {
|
if (login && (user === null || user === void 0 ? void 0 : user.login) !== login) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return body.replace(cleanRe, '') === messageClean;
|
return (body === null || body === void 0 ? void 0 : body.replace(cleanRe, '')) === messageClean;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const getInputs = () => {
|
const getInputs = () => {
|
||||||
|
|
@ -74,6 +78,11 @@ const run = async () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { full_name: repoFullName } = repository;
|
const { full_name: repoFullName } = repository;
|
||||||
|
if (!repoFullName) {
|
||||||
|
core.info('repository is missing a full_name property... weird');
|
||||||
|
core.setOutput('comment-created', 'false');
|
||||||
|
return;
|
||||||
|
}
|
||||||
const [owner, repo] = repoFullName.split('/');
|
const [owner, repo] = repoFullName.split('/');
|
||||||
let issueNumber;
|
let issueNumber;
|
||||||
if (issue && issue.number) {
|
if (issue && issue.number) {
|
||||||
|
|
@ -96,7 +105,7 @@ const run = async () => {
|
||||||
let shouldCreateComment = true;
|
let shouldCreateComment = true;
|
||||||
if (!allowRepeats) {
|
if (!allowRepeats) {
|
||||||
core.debug('repeat comments are disallowed, checking for existing');
|
core.debug('repeat comments are disallowed, checking for existing');
|
||||||
const { data: comments } = await octokit.issues.listComments({
|
const { data: comments } = await octokit.rest.issues.listComments({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
issue_number: issueNumber,
|
issue_number: issueNumber,
|
||||||
|
|
@ -118,7 +127,7 @@ const run = async () => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
await octokit.issues.createComment({
|
await octokit.rest.issues.createComment({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
issue_number: issueNumber,
|
issue_number: issueNumber,
|
||||||
|
|
@ -131,8 +140,10 @@ const run = async () => {
|
||||||
core.setOutput('comment-created', 'false');
|
core.setOutput('comment-created', 'false');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (err) {
|
||||||
core.setFailed(error.message);
|
if (err instanceof Error) {
|
||||||
|
core.setFailed(err.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Don't auto-execute in the test environment
|
// Don't auto-execute in the test environment
|
||||||
|
|
|
||||||
18270
package-lock.json
generated
18270
package-lock.json
generated
File diff suppressed because it is too large
Load diff
142
package.json
142
package.json
|
|
@ -2,17 +2,6 @@
|
||||||
"name": "@mshick/add-pr-comment",
|
"name": "@mshick/add-pr-comment",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "A GitHub Action which adds a comment to a Pull Request Issue.",
|
"description": "A GitHub Action which adds a comment to a Pull Request Issue.",
|
||||||
"main": "lib/main.js",
|
|
||||||
"scripts": {
|
|
||||||
"build": "tsc && ncc build lib/main.js",
|
|
||||||
"lint": "eslint . --ext .ts",
|
|
||||||
"test": "jest",
|
|
||||||
"clean": "rm -rf node_modules dist package-lock.json __tests__/runner/**/*"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/mshick/add-pr-comment.git"
|
|
||||||
},
|
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"GitHub",
|
"GitHub",
|
||||||
"Actions",
|
"Actions",
|
||||||
|
|
@ -21,32 +10,123 @@
|
||||||
"comments",
|
"comments",
|
||||||
"pr"
|
"pr"
|
||||||
],
|
],
|
||||||
"author": "Michael Shick <m@shick.us>",
|
"homepage": "https://github.com/mshick/add-pr-comment#readme",
|
||||||
"license": "MIT",
|
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/mshick/add-pr-comment/issues"
|
"url": "https://github.com/mshick/add-pr-comment/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/mshick/add-pr-comment#readme",
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/mshick/add-pr-comment.git"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"author": "Michael Shick <m@shick.us>",
|
||||||
|
"main": "lib/main.js",
|
||||||
|
"scripts": {
|
||||||
|
"build": "tsc",
|
||||||
|
"clean": "rm -rf node_modules dist package-lock.json __tests__/runner/**/*",
|
||||||
|
"lint": "eslint src/**/*.ts",
|
||||||
|
"package": "ncc build --source-map --license licenses.txt",
|
||||||
|
"test": "jest"
|
||||||
|
},
|
||||||
|
"prettier": {
|
||||||
|
"bracketSpacing": true,
|
||||||
|
"jsxSingleQuote": true,
|
||||||
|
"printWidth": 100,
|
||||||
|
"semi": false,
|
||||||
|
"singleQuote": true,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"trailingComma": "all"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"env": {
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"import/resolver": {
|
||||||
|
"typescript": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"extends": [
|
||||||
|
"eslint:recommended",
|
||||||
|
"plugin:prettier/recommended"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"capitalized-comments": "off",
|
||||||
|
"no-console": "error",
|
||||||
|
"no-unreachable": "error"
|
||||||
|
},
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": [
|
||||||
|
"**/*.ts"
|
||||||
|
],
|
||||||
|
"parser": "@typescript-eslint/parser",
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": "latest",
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
|
"extends": [
|
||||||
|
"plugin:@typescript-eslint/recommended"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"@typescript-eslint/no-explicit-any": "off"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"files": [
|
||||||
|
"*.json"
|
||||||
|
],
|
||||||
|
"plugins": [
|
||||||
|
"json-format"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"files": [
|
||||||
|
"*.mdx",
|
||||||
|
"*.md"
|
||||||
|
],
|
||||||
|
"settings": {
|
||||||
|
"mdx/code-blocks": false,
|
||||||
|
"mdx/language-mapper": {}
|
||||||
|
},
|
||||||
|
"extends": "plugin:mdx/recommended",
|
||||||
|
"rules": {
|
||||||
|
"indent": "off"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"eslintIgnore": [
|
||||||
|
"tsconfig.json",
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.4",
|
"@actions/core": "^1.10.0",
|
||||||
"@actions/github": "^4.0.0",
|
"@actions/github": "^5.1.1",
|
||||||
"@actions/http-client": "^1.0.8"
|
"@actions/http-client": "^2.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@octokit/types": "^5.4.0",
|
"@octokit/types": "^8.0.0",
|
||||||
"@types/jest": "^26.0.9",
|
"@types/jest": "^29.2.2",
|
||||||
"@types/node": "^12.12.42",
|
"@types/node": "^18.11.9",
|
||||||
"@typescript-eslint/eslint-plugin": "^3.9.0",
|
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
||||||
"@typescript-eslint/parser": "^3.9.0",
|
"@typescript-eslint/parser": "^5.42.0",
|
||||||
"@zeit/ncc": "^0.22.3",
|
"@zeit/ncc": "^0.22.3",
|
||||||
"eslint": "^7.6.0",
|
"eslint": "^8.26.0",
|
||||||
"eslint-config-prettier": "^6.11.0",
|
"eslint-config-prettier": "^8.5.0",
|
||||||
"eslint-plugin-prettier": "^3.1.4",
|
"eslint-import-resolver-typescript": "^3.5.2",
|
||||||
"jest": "^26.3.0",
|
"eslint-plugin-import": "^2.26.0",
|
||||||
"jest-circus": "^26.3.0",
|
"eslint-plugin-json-format": "^2.0.1",
|
||||||
"nock": "^13.0.4",
|
"eslint-plugin-mdx": "^2.0.5",
|
||||||
"prettier": "^2.0.5",
|
"eslint-plugin-prettier": "^4.2.1",
|
||||||
"ts-jest": "^26.2.0",
|
"jest": "^29.2.2",
|
||||||
"typescript": "^3.9.7"
|
"jest-circus": "^29.2.2",
|
||||||
|
"nock": "^13.2.9",
|
||||||
|
"prettier": "^2.7.1",
|
||||||
|
"ts-jest": "^29.0.3",
|
||||||
|
"typescript": "^4.8.4"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^14.15.0 || ^16.13.0 || ^18.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
49
src/main.ts
49
src/main.ts
|
|
@ -1,10 +1,14 @@
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as github from '@actions/github'
|
import * as github from '@actions/github'
|
||||||
import { HttpClient } from '@actions/http-client'
|
import { HttpClient } from '@actions/http-client'
|
||||||
import {Endpoints, RequestHeaders, IssuesListCommentsResponseData} from '@octokit/types'
|
import { Endpoints, RequestHeaders } from '@octokit/types'
|
||||||
|
|
||||||
type ListCommitPullsResponseData = Endpoints['GET /repos/:owner/:repo/commits/:commit_sha/pulls']['response']['data']
|
type ListCommitPullsResponseData =
|
||||||
type CreateIssueCommentResponseData = Endpoints['POST /repos/:owner/:repo/issues/:issue_number/comments']['response']['data']
|
Endpoints['GET /repos/{owner}/{repo}/commits/{commit_sha}/pulls']['response']['data']
|
||||||
|
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 {
|
interface ListCommitPullsParams {
|
||||||
repoToken: string
|
repoToken: string
|
||||||
|
|
@ -14,7 +18,7 @@ interface ListCommitPullsParams {
|
||||||
}
|
}
|
||||||
|
|
||||||
const listCommitPulls = async (
|
const listCommitPulls = async (
|
||||||
params: ListCommitPullsParams
|
params: ListCommitPullsParams,
|
||||||
): Promise<ListCommitPullsResponseData | null> => {
|
): Promise<ListCommitPullsResponseData | null> => {
|
||||||
const { repoToken, owner, repo, commitSha } = params
|
const { repoToken, owner, repo, commitSha } = params
|
||||||
|
|
||||||
|
|
@ -27,14 +31,14 @@ const listCommitPulls = async (
|
||||||
|
|
||||||
const body = await http.getJson<ListCommitPullsResponseData>(
|
const body = await http.getJson<ListCommitPullsResponseData>(
|
||||||
`https://api.github.com/repos/${owner}/${repo}/commits/${commitSha}/pulls`,
|
`https://api.github.com/repos/${owner}/${repo}/commits/${commitSha}/pulls`,
|
||||||
additionalHeaders
|
additionalHeaders,
|
||||||
)
|
)
|
||||||
|
|
||||||
return body.result
|
return body.result
|
||||||
}
|
}
|
||||||
|
|
||||||
const getIssueNumberFromCommitPullsList = (
|
const getIssueNumberFromCommitPullsList = (
|
||||||
commitPullsList: ListCommitPullsResponseData
|
commitPullsList: ListCommitPullsResponseData,
|
||||||
): number | null => (commitPullsList.length ? commitPullsList[0].number : null)
|
): number | null => (commitPullsList.length ? commitPullsList[0].number : null)
|
||||||
|
|
||||||
interface CreateCommentProxyParams {
|
interface CreateCommentProxyParams {
|
||||||
|
|
@ -47,7 +51,7 @@ interface CreateCommentProxyParams {
|
||||||
}
|
}
|
||||||
|
|
||||||
const createCommentProxy = async (
|
const createCommentProxy = async (
|
||||||
params: CreateCommentProxyParams
|
params: CreateCommentProxyParams,
|
||||||
): Promise<CreateIssueCommentResponseData | null> => {
|
): Promise<CreateIssueCommentResponseData | null> => {
|
||||||
const { repoToken, owner, repo, issueNumber, body, proxyUrl } = params
|
const { repoToken, owner, repo, issueNumber, body, proxyUrl } = params
|
||||||
|
|
||||||
|
|
@ -58,7 +62,7 @@ const createCommentProxy = async (
|
||||||
{ body },
|
{ body },
|
||||||
{
|
{
|
||||||
['temporary-github-token']: repoToken,
|
['temporary-github-token']: repoToken,
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
return response.result
|
return response.result
|
||||||
|
|
@ -67,18 +71,18 @@ const createCommentProxy = async (
|
||||||
const isMessagePresent = (
|
const isMessagePresent = (
|
||||||
message: AddPrCommentInputs['message'],
|
message: AddPrCommentInputs['message'],
|
||||||
comments: IssuesListCommentsResponseData,
|
comments: IssuesListCommentsResponseData,
|
||||||
login?: string
|
login?: string,
|
||||||
): boolean => {
|
): boolean => {
|
||||||
const cleanRe = new RegExp('\\R|\\s', 'g')
|
const cleanRe = new RegExp('\\R|\\s', 'g')
|
||||||
const messageClean = message.replace(cleanRe, '')
|
const messageClean = message.replace(cleanRe, '')
|
||||||
|
|
||||||
return comments.some(({ user, body }) => {
|
return comments.some(({ user, body }) => {
|
||||||
// If a username is provided we can save on a bit of processing
|
// If a username is provided we can save on a bit of processing
|
||||||
if (login && user.login !== login) {
|
if (login && user?.login !== login) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return body.replace(cleanRe, '') === messageClean
|
return body?.replace(cleanRe, '') === messageClean
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,7 +110,7 @@ const run = async (): Promise<void> => {
|
||||||
|
|
||||||
if (!repoToken) {
|
if (!repoToken) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'no github token provided, set one with the repo-token input or GITHUB_TOKEN env variable'
|
'no github token provided, set one with the repo-token input or GITHUB_TOKEN env variable',
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,7 +126,14 @@ const run = async (): Promise<void> => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const { full_name: repoFullName } = repository
|
const { full_name: repoFullName } = repository
|
||||||
const [owner, repo] = repoFullName!.split('/')
|
|
||||||
|
if (!repoFullName) {
|
||||||
|
core.info('repository is missing a full_name property... weird')
|
||||||
|
core.setOutput('comment-created', 'false')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const [owner, repo] = repoFullName.split('/')
|
||||||
|
|
||||||
let issueNumber
|
let issueNumber
|
||||||
|
|
||||||
|
|
@ -138,7 +149,7 @@ const run = async (): Promise<void> => {
|
||||||
|
|
||||||
if (!issueNumber) {
|
if (!issueNumber) {
|
||||||
core.info(
|
core.info(
|
||||||
'this action only works on issues and pull_request events or other commits associated with a pull'
|
'this action only works on issues and pull_request events or other commits associated with a pull',
|
||||||
)
|
)
|
||||||
core.setOutput('comment-created', 'false')
|
core.setOutput('comment-created', 'false')
|
||||||
return
|
return
|
||||||
|
|
@ -151,7 +162,7 @@ const run = async (): Promise<void> => {
|
||||||
if (!allowRepeats) {
|
if (!allowRepeats) {
|
||||||
core.debug('repeat comments are disallowed, checking for existing')
|
core.debug('repeat comments are disallowed, checking for existing')
|
||||||
|
|
||||||
const {data: comments} = await octokit.issues.listComments({
|
const { data: comments } = await octokit.rest.issues.listComments({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
issue_number: issueNumber,
|
issue_number: issueNumber,
|
||||||
|
|
@ -174,7 +185,7 @@ const run = async (): Promise<void> => {
|
||||||
proxyUrl,
|
proxyUrl,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
await octokit.issues.createComment({
|
await octokit.rest.issues.createComment({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
issue_number: issueNumber,
|
issue_number: issueNumber,
|
||||||
|
|
@ -186,8 +197,10 @@ const run = async (): Promise<void> => {
|
||||||
} else {
|
} else {
|
||||||
core.setOutput('comment-created', 'false')
|
core.setOutput('comment-created', 'false')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (err) {
|
||||||
core.setFailed(error.message)
|
if (err instanceof Error) {
|
||||||
|
core.setFailed(err.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue