mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-13 12:11:14 +00:00
Merge pull request #890 from WebFreak001/only_create-setting
add setting to only create, but not update comment
This commit is contained in:
commit
4608256f79
7 changed files with 40 additions and 193 deletions
|
|
@ -155,6 +155,10 @@ is explicitly passed, this problem can be solved by just removing it.
|
|||
|
||||
**Optional** Delete a previously created comment. Use `header` to point to which comment you want to delete. Only `true` is allowed (i.e. delete this option if you don't need it).
|
||||
|
||||
### `only_create`
|
||||
|
||||
**Optional** Only create a new comment if there is no existing one, otherwise do nothing. Only `true` is allowed. Just skip this item when you don't need it.
|
||||
|
||||
### `hide`
|
||||
|
||||
**Optional** Hide a previously created comment. Use `header` to point to which comment you want to delete. Only `true` is allowed (i.e. delete this option if you don't need it).
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ beforeEach(() => {
|
|||
process.env["INPUT_APPEND"] = "false"
|
||||
process.env["INPUT_RECREATE"] = "false"
|
||||
process.env["INPUT_DELETE"] = "false"
|
||||
process.env["INPUT_ONLY_CREATE"] = "false"
|
||||
process.env["INPUT_HIDE"] = "false"
|
||||
process.env["INPUT_HIDE_AND_RECREATE"] = "false"
|
||||
process.env["INPUT_HIDE_CLASSIFY"] = "OUTDATED"
|
||||
|
|
@ -23,6 +24,7 @@ afterEach(() => {
|
|||
delete process.env["INPUT_APPEND"]
|
||||
delete process.env["INPUT_RECREATE"]
|
||||
delete process.env["INPUT_DELETE"]
|
||||
delete process.env["INPUT_ONLY_CREATE"]
|
||||
delete process.env["INPUT_HIDE"]
|
||||
delete process.env["INPUT_HIDE_AND_RECREATE"]
|
||||
delete process.env["INPUT_HIDE_CLASSIFY"]
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@ inputs:
|
|||
description: "delete the previously created comment. Only `true` is allowed. Just skip this item when you don't need it."
|
||||
default: "false"
|
||||
required: false
|
||||
only_create:
|
||||
description: "only create a new comment if there is no existing one, otherwise do nothing. Only `true` is allowed. Just skip this item when you don't need it. This options has higher priority than hide_and_recreate, hide."
|
||||
default: "false"
|
||||
required: false
|
||||
hide_details:
|
||||
description: "hide summary tags in the previously created comment. Only `true` is allowed. Just skip this item when you don't need it."
|
||||
default: "false"
|
||||
|
|
|
|||
209
dist/index.js
generated
vendored
209
dist/index.js
generated
vendored
|
|
@ -207,7 +207,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
};
|
||||
var _a, _b;
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.getBody = exports.ignoreEmpty = exports.githubToken = exports.hideOldComment = exports.deleteOldComment = exports.hideClassify = exports.hideAndRecreate = exports.recreate = exports.hideDetails = exports.append = exports.header = exports.repo = exports.pullRequestNumber = void 0;
|
||||
exports.getBody = exports.ignoreEmpty = exports.githubToken = exports.hideOldComment = exports.onlyCreateComment = exports.deleteOldComment = exports.hideClassify = exports.hideAndRecreate = exports.recreate = exports.hideDetails = exports.append = exports.header = exports.repo = exports.pullRequestNumber = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const github_1 = __nccwpck_require__(5438);
|
||||
const fs_1 = __nccwpck_require__(7147);
|
||||
|
|
@ -228,6 +228,9 @@ exports.hideClassify = core.getInput("hide_classify", {
|
|||
required: true
|
||||
});
|
||||
exports.deleteOldComment = core.getBooleanInput("delete", { required: true });
|
||||
exports.onlyCreateComment = core.getBooleanInput("only_create", {
|
||||
required: true
|
||||
});
|
||||
exports.hideOldComment = core.getBooleanInput("hide", { required: true });
|
||||
exports.githubToken = core.getInput("GITHUB_TOKEN", { required: true });
|
||||
exports.ignoreEmpty = core.getBooleanInput("ignore_empty", {
|
||||
|
|
@ -347,6 +350,11 @@ function run() {
|
|||
yield (0, comment_1.createComment)(octokit, config_1.repo, config_1.pullRequestNumber, body, config_1.header);
|
||||
return;
|
||||
}
|
||||
if (config_1.onlyCreateComment) {
|
||||
// don't comment anything, user specified only_create and there is an
|
||||
// existing comment, so this is probably a placeholder / introduction one.
|
||||
return;
|
||||
}
|
||||
if (config_1.hideOldComment) {
|
||||
yield (0, comment_1.minimizeComment)(octokit, previous.id, config_1.hideClassify);
|
||||
return;
|
||||
|
|
@ -1619,16 +1627,18 @@ exports.create = create;
|
|||
* Computes the sha256 hash of a glob
|
||||
*
|
||||
* @param patterns Patterns separated by newlines
|
||||
* @param currentWorkspace Workspace used when matching files
|
||||
* @param options Glob options
|
||||
* @param verbose Enables verbose logging
|
||||
*/
|
||||
function hashFiles(patterns, options, verbose = false) {
|
||||
function hashFiles(patterns, currentWorkspace = '', options, verbose = false) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let followSymbolicLinks = true;
|
||||
if (options && typeof options.followSymbolicLinks === 'boolean') {
|
||||
followSymbolicLinks = options.followSymbolicLinks;
|
||||
}
|
||||
const globber = yield create(patterns, { followSymbolicLinks });
|
||||
return internal_hash_files_1.hashFiles(globber, verbose);
|
||||
return internal_hash_files_1.hashFiles(globber, currentWorkspace, verbose);
|
||||
});
|
||||
}
|
||||
exports.hashFiles = hashFiles;
|
||||
|
|
@ -1988,13 +1998,15 @@ const fs = __importStar(__nccwpck_require__(7147));
|
|||
const stream = __importStar(__nccwpck_require__(2781));
|
||||
const util = __importStar(__nccwpck_require__(3837));
|
||||
const path = __importStar(__nccwpck_require__(1017));
|
||||
function hashFiles(globber, verbose = false) {
|
||||
function hashFiles(globber, currentWorkspace, verbose = false) {
|
||||
var e_1, _a;
|
||||
var _b;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const writeDelegate = verbose ? core.info : core.debug;
|
||||
let hasMatch = false;
|
||||
const githubWorkspace = (_b = process.env['GITHUB_WORKSPACE']) !== null && _b !== void 0 ? _b : process.cwd();
|
||||
const githubWorkspace = currentWorkspace
|
||||
? currentWorkspace
|
||||
: (_b = process.env['GITHUB_WORKSPACE']) !== null && _b !== void 0 ? _b : process.cwd();
|
||||
const result = crypto.createHash('sha256');
|
||||
let count = 0;
|
||||
try {
|
||||
|
|
@ -4188,7 +4200,7 @@ exports.endpoint = endpoint;
|
|||
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
|
||||
var request = __nccwpck_require__(3758);
|
||||
var request = __nccwpck_require__(6234);
|
||||
var universalUserAgent = __nccwpck_require__(5030);
|
||||
|
||||
const VERSION = "4.8.0";
|
||||
|
|
@ -4304,191 +4316,6 @@ exports.withCustomRequest = withCustomRequest;
|
|||
//# sourceMappingURL=index.js.map
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3758:
|
||||
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
|
||||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
||||
|
||||
var endpoint = __nccwpck_require__(9440);
|
||||
var universalUserAgent = __nccwpck_require__(5030);
|
||||
var isPlainObject = __nccwpck_require__(3287);
|
||||
var nodeFetch = _interopDefault(__nccwpck_require__(467));
|
||||
var requestError = __nccwpck_require__(537);
|
||||
|
||||
const VERSION = "5.6.1";
|
||||
|
||||
function getBufferResponse(response) {
|
||||
return response.arrayBuffer();
|
||||
}
|
||||
|
||||
function fetchWrapper(requestOptions) {
|
||||
const log = requestOptions.request && requestOptions.request.log ? requestOptions.request.log : console;
|
||||
|
||||
if (isPlainObject.isPlainObject(requestOptions.body) || Array.isArray(requestOptions.body)) {
|
||||
requestOptions.body = JSON.stringify(requestOptions.body);
|
||||
}
|
||||
|
||||
let headers = {};
|
||||
let status;
|
||||
let url;
|
||||
const fetch = requestOptions.request && requestOptions.request.fetch || nodeFetch;
|
||||
return fetch(requestOptions.url, Object.assign({
|
||||
method: requestOptions.method,
|
||||
body: requestOptions.body,
|
||||
headers: requestOptions.headers,
|
||||
redirect: requestOptions.redirect
|
||||
}, // `requestOptions.request.agent` type is incompatible
|
||||
// see https://github.com/octokit/types.ts/pull/264
|
||||
requestOptions.request)).then(async response => {
|
||||
url = response.url;
|
||||
status = response.status;
|
||||
|
||||
for (const keyAndValue of response.headers) {
|
||||
headers[keyAndValue[0]] = keyAndValue[1];
|
||||
}
|
||||
|
||||
if ("deprecation" in headers) {
|
||||
const matches = headers.link && headers.link.match(/<([^>]+)>; rel="deprecation"/);
|
||||
const deprecationLink = matches && matches.pop();
|
||||
log.warn(`[@octokit/request] "${requestOptions.method} ${requestOptions.url}" is deprecated. It is scheduled to be removed on ${headers.sunset}${deprecationLink ? `. See ${deprecationLink}` : ""}`);
|
||||
}
|
||||
|
||||
if (status === 204 || status === 205) {
|
||||
return;
|
||||
} // GitHub API returns 200 for HEAD requests
|
||||
|
||||
|
||||
if (requestOptions.method === "HEAD") {
|
||||
if (status < 400) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new requestError.RequestError(response.statusText, status, {
|
||||
response: {
|
||||
url,
|
||||
status,
|
||||
headers,
|
||||
data: undefined
|
||||
},
|
||||
request: requestOptions
|
||||
});
|
||||
}
|
||||
|
||||
if (status === 304) {
|
||||
throw new requestError.RequestError("Not modified", status, {
|
||||
response: {
|
||||
url,
|
||||
status,
|
||||
headers,
|
||||
data: await getResponseData(response)
|
||||
},
|
||||
request: requestOptions
|
||||
});
|
||||
}
|
||||
|
||||
if (status >= 400) {
|
||||
const data = await getResponseData(response);
|
||||
const error = new requestError.RequestError(toErrorMessage(data), status, {
|
||||
response: {
|
||||
url,
|
||||
status,
|
||||
headers,
|
||||
data
|
||||
},
|
||||
request: requestOptions
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
|
||||
return getResponseData(response);
|
||||
}).then(data => {
|
||||
return {
|
||||
status,
|
||||
url,
|
||||
headers,
|
||||
data
|
||||
};
|
||||
}).catch(error => {
|
||||
if (error instanceof requestError.RequestError) throw error;
|
||||
throw new requestError.RequestError(error.message, 500, {
|
||||
request: requestOptions
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function getResponseData(response) {
|
||||
const contentType = response.headers.get("content-type");
|
||||
|
||||
if (/application\/json/.test(contentType)) {
|
||||
return response.json();
|
||||
}
|
||||
|
||||
if (!contentType || /^text\/|charset=utf-8$/.test(contentType)) {
|
||||
return response.text();
|
||||
}
|
||||
|
||||
return getBufferResponse(response);
|
||||
}
|
||||
|
||||
function toErrorMessage(data) {
|
||||
if (typeof data === "string") return data; // istanbul ignore else - just in case
|
||||
|
||||
if ("message" in data) {
|
||||
if (Array.isArray(data.errors)) {
|
||||
return `${data.message}: ${data.errors.map(JSON.stringify).join(", ")}`;
|
||||
}
|
||||
|
||||
return data.message;
|
||||
} // istanbul ignore next - just in case
|
||||
|
||||
|
||||
return `Unknown error: ${JSON.stringify(data)}`;
|
||||
}
|
||||
|
||||
function withDefaults(oldEndpoint, newDefaults) {
|
||||
const endpoint = oldEndpoint.defaults(newDefaults);
|
||||
|
||||
const newApi = function (route, parameters) {
|
||||
const endpointOptions = endpoint.merge(route, parameters);
|
||||
|
||||
if (!endpointOptions.request || !endpointOptions.request.hook) {
|
||||
return fetchWrapper(endpoint.parse(endpointOptions));
|
||||
}
|
||||
|
||||
const request = (route, parameters) => {
|
||||
return fetchWrapper(endpoint.parse(endpoint.merge(route, parameters)));
|
||||
};
|
||||
|
||||
Object.assign(request, {
|
||||
endpoint,
|
||||
defaults: withDefaults.bind(null, endpoint)
|
||||
});
|
||||
return endpointOptions.request.hook(request, endpointOptions);
|
||||
};
|
||||
|
||||
return Object.assign(newApi, {
|
||||
endpoint,
|
||||
defaults: withDefaults.bind(null, endpoint)
|
||||
});
|
||||
}
|
||||
|
||||
const request = withDefaults(endpoint.endpoint, {
|
||||
headers: {
|
||||
"user-agent": `octokit-request.js/${VERSION} ${universalUserAgent.getUserAgent()}`
|
||||
}
|
||||
});
|
||||
|
||||
exports.request = request;
|
||||
//# sourceMappingURL=index.js.map
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4193:
|
||||
|
|
|
|||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
|
|
@ -22,6 +22,9 @@ export const hideClassify = core.getInput("hide_classify", {
|
|||
required: true
|
||||
}) as ReportedContentClassifiers
|
||||
export const deleteOldComment = core.getBooleanInput("delete", {required: true})
|
||||
export const onlyCreateComment = core.getBooleanInput("only_create", {
|
||||
required: true
|
||||
})
|
||||
export const hideOldComment = core.getBooleanInput("hide", {required: true})
|
||||
export const githubToken = core.getInput("GITHUB_TOKEN", {required: true})
|
||||
export const ignoreEmpty = core.getBooleanInput("ignore_empty", {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ import {
|
|||
pullRequestNumber,
|
||||
recreate,
|
||||
repo,
|
||||
ignoreEmpty
|
||||
ignoreEmpty,
|
||||
onlyCreateComment
|
||||
} from "./config"
|
||||
import {
|
||||
createComment,
|
||||
|
|
@ -70,6 +71,12 @@ async function run(): Promise<undefined> {
|
|||
return
|
||||
}
|
||||
|
||||
if (onlyCreateComment) {
|
||||
// don't comment anything, user specified only_create and there is an
|
||||
// existing comment, so this is probably a placeholder / introduction one.
|
||||
return
|
||||
}
|
||||
|
||||
if (hideOldComment) {
|
||||
await minimizeComment(octokit, previous.id, hideClassify)
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in a new issue