mirror of
https://github.com/mshick/add-pr-comment.git
synced 2025-12-31 22:29:45 +11:00
trigger test
This commit is contained in:
parent
526bb87116
commit
f1386bdbd2
15 changed files with 11219 additions and 537 deletions
7
.github/workflows/test.yml
vendored
7
.github/workflows/test.yml
vendored
|
|
@ -9,13 +9,12 @@ jobs:
|
|||
- uses: actions/checkout@v1
|
||||
|
||||
- run: npm ci
|
||||
# - run: npm test
|
||||
|
||||
- uses: ./
|
||||
with:
|
||||
msg: |
|
||||
Hello!
|
||||
message: |
|
||||
**Hello!**
|
||||
🌏
|
||||
**bold**
|
||||
!
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
allow-repeats: false
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
name: "Add PR Comment"
|
||||
description: "Add a comment to a PR"
|
||||
inputs:
|
||||
msg:
|
||||
message:
|
||||
description: "the message to print"
|
||||
required: true
|
||||
repo-token:
|
||||
|
|
@ -13,4 +13,4 @@ inputs:
|
|||
default: false
|
||||
runs:
|
||||
using: "node12"
|
||||
main: "index.js"
|
||||
main: "dist/index.js"
|
||||
|
|
|
|||
11
add-pr-comment/.github/main.workflow
vendored
11
add-pr-comment/.github/main.workflow
vendored
|
|
@ -1,11 +0,0 @@
|
|||
workflow "Run Add PR Comment" {
|
||||
on = "pull_request"
|
||||
resolves = ["AddPrCommentActions"]
|
||||
}
|
||||
|
||||
action "AddPrCommentActions" {
|
||||
uses = "./"
|
||||
secrets = [
|
||||
"GITHUB_TOKEN"
|
||||
]
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
on: pull_request
|
||||
name: Run Add PR Comment
|
||||
jobs:
|
||||
add-pr-comment-actions:
|
||||
name: Add PR Comment Actions
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
|
||||
- name: Add PR Comment Actions
|
||||
uses: ./
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
61
add-pr-comment/.gitignore
vendored
61
add-pr-comment/.gitignore
vendored
|
|
@ -1,61 +0,0 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"semi": true
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
FROM node:slim
|
||||
|
||||
LABEL "com.github.actions.name"="Add PR Comment"
|
||||
LABEL "com.github.actions.description"="Add a comment to the PR triggering this action"
|
||||
LABEL "com.github.actions.icon"="send"
|
||||
LABEL "com.github.actions.color"="gray-dark"
|
||||
|
||||
COPY package*.json ./
|
||||
|
||||
RUN npm ci
|
||||
|
||||
COPY . .
|
||||
|
||||
ENTRYPOINT ["node", "/entrypoint.js"]
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2019 Michael Shick
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
|
@ -1 +0,0 @@
|
|||
# Add PR Comment GitHub Action
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
// entrypoint.js
|
||||
const { Toolkit } = require("actions-toolkit");
|
||||
const tools = new Toolkit();
|
||||
const webPageTest = require("webpagetest");
|
||||
const argv = tools.arguments;
|
||||
|
||||
const { event, payload, sha } = tools.context;
|
||||
|
||||
// check pre-requirements
|
||||
if (!checkForMissingEnv) tools.exit.failure("Failed!");
|
||||
|
||||
// run the script
|
||||
runAudit();
|
||||
|
||||
async function runAudit() {
|
||||
try {
|
||||
if (event === "push") {
|
||||
tools.log("### Action triggered! ###");
|
||||
|
||||
// 1. An authenticated instance of `@octokit/rest`, a GitHub API SDK
|
||||
const octokit = tools.github;
|
||||
|
||||
// initialize webPagetest
|
||||
const wpt = new webPageTest(
|
||||
process.env.WEBPAGETEST_SERVER_URL || "www.webpagetest.org",
|
||||
process.env.WEBPAGETEST_API_KEY
|
||||
);
|
||||
|
||||
// 2. run tests and save results
|
||||
const webpagetestResults = await runWebPagetest(wpt);
|
||||
|
||||
// 3. convert results to markdown
|
||||
const finalResultsAsMarkdown = convertToMarkdown(webpagetestResults);
|
||||
|
||||
// 4. print results to as commit comment
|
||||
const { owner, repo } = {
|
||||
...tools.context.repo,
|
||||
ref: `${payload.ref}`
|
||||
};
|
||||
|
||||
await octokit.repos.createCommitComment({
|
||||
owner,
|
||||
repo,
|
||||
sha,
|
||||
body: finalResultsAsMarkdown
|
||||
});
|
||||
|
||||
tools.exit.success("Succesfully run!");
|
||||
}
|
||||
} catch (error) {
|
||||
tools.log.error(`Something went wrong ${error}!`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log warnings to the console for missing environment variables
|
||||
*/
|
||||
function checkForMissingEnv() {
|
||||
const requiredEnvVars = [
|
||||
"HOME",
|
||||
"GITHUB_WORKFLOW",
|
||||
"GITHUB_ACTION",
|
||||
"GITHUB_ACTOR",
|
||||
"GITHUB_REPOSITORY",
|
||||
"GITHUB_EVENT_NAME",
|
||||
"GITHUB_EVENT_PATH",
|
||||
"GITHUB_WORKSPACE",
|
||||
"GITHUB_SHA",
|
||||
"GITHUB_REF",
|
||||
"GITHUB_TOKEN"
|
||||
];
|
||||
|
||||
const requiredButMissing = requiredEnvVars.filter(
|
||||
key => !process.env.hasOwnProperty(key)
|
||||
);
|
||||
if (requiredButMissing.length > 0) {
|
||||
// This isn't being run inside of a GitHub Action environment!
|
||||
const list = requiredButMissing.map(key => `- ${key}`).join("\n");
|
||||
const warning = `There are environment variables missing from this runtime.\n${list}`;
|
||||
tools.log.warn(warning);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
{
|
||||
"name": "add-pr-comment-action",
|
||||
"version": "0.0.1",
|
||||
"description": "github action which adds a comment to a PR",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/mshick/add-pr-comment.git"
|
||||
},
|
||||
"keywords": [
|
||||
"github",
|
||||
"actions",
|
||||
"pr"
|
||||
],
|
||||
"author": "Michael Shick <m@shick.us>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/mshick/add-pr-comment/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mshick/add-pr-comment#readme",
|
||||
"dependencies": {
|
||||
"actions-toolkit": "^2.1.0"
|
||||
}
|
||||
}
|
||||
11465
dist/index.js
vendored
11465
dist/index.js
vendored
File diff suppressed because one or more lines are too long
16
index.js
16
index.js
|
|
@ -3,11 +3,11 @@ const github = require("@actions/github");
|
|||
|
||||
async function run() {
|
||||
try {
|
||||
const msg = core.getInput("msg");
|
||||
const message = core.getInput("message");
|
||||
const repoToken = core.getInput("repo-token");
|
||||
const allowRepeats = Boolean(core.getInput("allow-repeats") === "true");
|
||||
|
||||
core.debug(`input msg: ${msg}`);
|
||||
core.debug(`input message: ${message}`);
|
||||
core.debug(`input allow-repeats: ${allowRepeats}`);
|
||||
|
||||
const {
|
||||
|
|
@ -22,7 +22,7 @@ async function run() {
|
|||
const octokit = new github.GitHub(repoToken);
|
||||
|
||||
if (allowRepeats === false) {
|
||||
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({
|
||||
owner,
|
||||
|
|
@ -31,12 +31,12 @@ async function run() {
|
|||
});
|
||||
|
||||
const filteredComments = comments.filter(
|
||||
c => c.body === msg && c.user.login === "github-actions[bot]"
|
||||
c => c.body === message && c.user.login === "github-actions[bot]"
|
||||
);
|
||||
|
||||
if (filteredComments.length) {
|
||||
core.warning(`the issue already contains this message`);
|
||||
core.setOutput("commented-created", "false");
|
||||
core.warning("the issue already contains this message");
|
||||
core.setOutput("comment-created", "false");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -45,10 +45,10 @@ async function run() {
|
|||
owner,
|
||||
repo,
|
||||
issue_number: issueNumber,
|
||||
body: msg
|
||||
body: message
|
||||
});
|
||||
|
||||
core.setOutput("commented-created", "true");
|
||||
core.setOutput("comment-created", "true");
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
// const wait = require("./wait");
|
||||
const process = require("process");
|
||||
const cp = require("child_process");
|
||||
const path = require("path");
|
||||
|
||||
// test("throws invalid number", async () => {
|
||||
// await expect(wait("foo")).rejects.toThrow("milleseconds not a number");
|
||||
// });
|
||||
|
||||
// test("wait 500 ms", async () => {
|
||||
// const start = new Date();
|
||||
// await wait(500);
|
||||
// const end = new Date();
|
||||
// var delta = Math.abs(end - start);
|
||||
// expect(delta).toBeGreaterThan(450);
|
||||
// });
|
||||
|
||||
// shows how the runner will run a javascript action with env / stdout protocol
|
||||
test("test runs", () => {
|
||||
const env = { INPUT_MSG: "Hello world!", INPUT_GITHUB_TOKEN: "abc123" };
|
||||
const ip = path.join(__dirname, "index.js");
|
||||
console.log(cp.execSync(`node ${ip}`, { env }).toString());
|
||||
});
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
"scripts": {
|
||||
"lint": "eslint index.js",
|
||||
"package": "ncc build index.js -o dist",
|
||||
"test": "eslint index.js && jest"
|
||||
"test": "eslint index.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
@ -29,7 +29,6 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@zeit/ncc": "^0.20.5",
|
||||
"eslint": "^6.3.0",
|
||||
"jest": "^24.9.0"
|
||||
"eslint": "^6.3.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue