@@ -7,6 +7,8 @@ import * as path from "path";
77import * as events from "events";
88import "child_process";
99import "timers";
10+ import { resolve } from "node:path";
11+ import { readFile } from "node:fs/promises";
1012//#region \0rolldown/runtime.js
1113var __create = Object.create;
1214var __defProp = Object.defineProperty;
@@ -16846,6 +16848,11 @@ var __awaiter = function(thisArg, _arguments, P, generator) {
1684616848 step((generator = generator.apply(thisArg, _arguments || [])).next());
1684716849 });
1684816850};
16851+ function getAuthString(token, options) {
16852+ if (!token && !options.auth) throw new Error("Parameter token or opts.auth is required");
16853+ else if (token && options.auth) throw new Error("Parameters token and opts.auth may not both be specified");
16854+ return typeof options.auth === "string" ? options.auth : `token ${token}`;
16855+ }
1684916856function getProxyAgent(destinationUrl) {
1685016857 return new import_lib.HttpClient().getAgent(destinationUrl);
1685116858}
@@ -16862,6 +16869,16 @@ function getProxyFetch(destinationUrl) {
1686216869function getApiBaseUrl() {
1686316870 return process.env["GITHUB_API_URL"] || "https://api.github.com";
1686416871}
16872+ function getUserAgentWithOrchestrationId(baseUserAgent) {
16873+ var _a;
16874+ const orchId = (_a = process.env["ACTIONS_ORCHESTRATION_ID"]) === null || _a === void 0 ? void 0 : _a.trim();
16875+ if (orchId) {
16876+ const tag = `actions_orchestration_id/${orchId.replace(/[^a-z0-9_.-]/gi, "_")}`;
16877+ if (baseUserAgent === null || baseUserAgent === void 0 ? void 0 : baseUserAgent.includes(tag)) return baseUserAgent;
16878+ return `${baseUserAgent ? `${baseUserAgent} ` : ""}${tag}`;
16879+ }
16880+ return baseUserAgent;
16881+ }
1686516882//#endregion
1686616883//#region node_modules/universal-user-agent/index.js
1686716884function getUserAgent() {
@@ -19292,18 +19309,67 @@ const defaults = {
1929219309 fetch: getProxyFetch(baseUrl)
1929319310 }
1929419311};
19295- Octokit.plugin(restEndpointMethods, paginateRest).defaults(defaults);
19312+ const GitHub = Octokit.plugin(restEndpointMethods, paginateRest).defaults(defaults);
19313+ /**
19314+ * Convience function to correctly format Octokit Options to pass into the constructor.
19315+ *
19316+ * @param token the repo PAT or GITHUB_TOKEN
19317+ * @param options other options to set
19318+ */
19319+ function getOctokitOptions(token, options) {
19320+ const opts = Object.assign({}, options || {});
19321+ const auth = getAuthString(token, opts);
19322+ if (auth) opts.auth = auth;
19323+ const userAgent = getUserAgentWithOrchestrationId(opts.userAgent);
19324+ if (userAgent) opts.userAgent = userAgent;
19325+ return opts;
19326+ }
1929619327//#endregion
1929719328//#region node_modules/@actions/github/lib/github.js
1929819329const context = new Context();
19330+ /**
19331+ * Returns a hydrated octokit ready to use for GitHub Actions
19332+ *
19333+ * @param token the repo PAT or GITHUB_TOKEN
19334+ * @param options other options to set
19335+ */
19336+ function getOctokit(token, options, ...additionalPlugins) {
19337+ return new (GitHub.plugin(...additionalPlugins))(getOctokitOptions(token, options));
19338+ }
1929919339//#endregion
1930019340//#region src/index.ts
19341+ const TITLE = "### Vercel Deployments";
1930119342(async () => {
19302- context.payload.pull_request?.number;
19303- const projectLoc = getInput("project-json-location");
19304- process.env.GH_TOKEN;
19305- console.log(projectLoc);
19306- console.log(JSON.stringify(context, null, 4));
19343+ const projectDirectory = getInput("project-directory");
19344+ const ghToken = process.env.GH_TOKEN;
19345+ const prId = context.issue.number;
19346+ const repo = context.repo;
19347+ const [pjBuff, urlBuff] = await Promise.all([readFile(resolve(projectDirectory, ".vercel/project.json")), readFile(resolve(projectDirectory, "./url.txt"))]);
19348+ const projectName = JSON.parse(pjBuff.toString()).projectName;
19349+ const url = urlBuff.toString();
19350+ if (typeof ghToken !== "string") throw new Error("GH_TOKEN missing");
19351+ const octokit = getOctokit(ghToken);
19352+ const existingComment = (await octokit.rest.issues.listComments({
19353+ ...repo,
19354+ issue_number: prId
19355+ })).data.find((comment) => comment.body?.startsWith(TITLE));
19356+ const body = existingComment?.body ?? TITLE;
19357+ const lines = body.split("\n");
19358+ const linkText = `- [${projectName}](${url})`;
19359+ const linkIndex = lines.findIndex((line) => line.startsWith(`- [${projectName}]`));
19360+ if (linkIndex >= 0) lines[linkIndex] = linkText;
19361+ else lines.push("\n", linkText);
19362+ console.log(body, lines);
19363+ if (existingComment) await octokit.rest.issues.updateComment({
19364+ ...repo,
19365+ comment_id: existingComment.id,
19366+ body: lines.join("\n")
19367+ });
19368+ else await octokit.rest.issues.createComment({
19369+ ...repo,
19370+ issue_number: prId,
19371+ body: lines.join("\n")
19372+ });
1930719373})();
1930819374//#endregion
1930919375export {};
0 commit comments