Skip to content

Commit

Permalink
Merge pull request #26 from gruntwork-io/fix-imports
Browse files Browse the repository at this point in the history
Fix imports to use 'import * as xyz from xyz'
  • Loading branch information
marinalimeira authored Sep 5, 2023
2 parents 8747100 + a24363c commit 3dd5920
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 97 deletions.
191 changes: 100 additions & 91 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ exports.prepareKeyValueMessage = exports.issueFileCommand = void 0;
/* eslint-disable @typescript-eslint/no-explicit-any */
const fs = __importStar(__nccwpck_require__(7147));
const os = __importStar(__nccwpck_require__(2037));
const uuid_1 = __nccwpck_require__(8974);
const uuid_1 = __nccwpck_require__(1866);
const utils_1 = __nccwpck_require__(5278);
function issueFileCommand(command, message) {
const filePath = process.env[`GITHUB_${command}`];
Expand Down Expand Up @@ -994,7 +994,7 @@ exports.toCommandProperties = toCommandProperties;

/***/ }),

/***/ 8974:
/***/ 1866:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";
Expand Down Expand Up @@ -13501,17 +13501,37 @@ function wrappy (fn, cb) {

"use strict";

var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = 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) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.run = exports.pullRequestBody = void 0;
const os_1 = __importDefault(__nccwpck_require__(2037));
const yaml_1 = __importDefault(__nccwpck_require__(4083));
const github_1 = __importDefault(__nccwpck_require__(5438));
const tool_cache_1 = __importDefault(__nccwpck_require__(7784));
const core_1 = __importDefault(__nccwpck_require__(2186));
const exec_1 = __importDefault(__nccwpck_require__(1514));
const os = __importStar(__nccwpck_require__(2037));
const yaml = __importStar(__nccwpck_require__(4083));
const github = __importStar(__nccwpck_require__(5438));
const toolCache = __importStar(__nccwpck_require__(7784));
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
// Define constants
const GRUNTWORK_GITHUB_ORG = "gruntwork-io";
const PATCHER_GITHUB_REPO = "patcher-cli";
Expand All @@ -13526,7 +13546,7 @@ const SKIP_CONTAINER_FLAG = "--skip-container-runtime";
const UPDATE_STRATEGY_FLAG = "--update-strategy";
const TARGET_FLAG = "--target";
function osPlatform() {
const platform = os_1.default.platform();
const platform = os.platform();
switch (platform) {
case "linux":
case "darwin":
Expand Down Expand Up @@ -13583,7 +13603,7 @@ function pullRequestBodyReadmeToUpdate(manualSteps) {
return "";
}
function pullRequestBody(patcherRawOutput, dependency) {
const updateSummary = yaml_1.default.parse(patcherRawOutput);
const updateSummary = yaml.parse(patcherRawOutput);
return `:robot: This is an automated pull request opened by [Patcher](https://docs.gruntwork.io/patcher/).

## Description
Expand Down Expand Up @@ -13611,60 +13631,60 @@ ${patcherRawOutput}
}
exports.pullRequestBody = pullRequestBody;
async function wasCodeUpdated() {
const output = await exec_1.default.getExecOutput("git", ["status", "--porcelain"]);
const output = await exec.getExecOutput("git", ["status", "--porcelain"]);
// If there are changes, they will appear in the stdout. Otherwise, it returns blank.
return !!output.stdout;
}
async function commitAndPushChanges(gitCommiter, dependency, workingDir, token) {
const { owner, repo } = github_1.default.context.repo;
const { owner, repo } = github.context.repo;
const head = pullRequestBranch(dependency, workingDir);
// Setup https auth and https remote url
await exec_1.default.exec("git", ["remote", "set-url", "origin", `https://${token}@github.com/${owner}/${repo}.git`]);
await exec.exec("git", ["remote", "set-url", "origin", `https://${token}@github.com/${owner}/${repo}.git`]);
// Setup committer name and email
await exec_1.default.exec("git", ["config", "user.name", gitCommiter.name]);
await exec_1.default.exec("git", ["config", "user.email", gitCommiter.email]);
await exec.exec("git", ["config", "user.name", gitCommiter.name]);
await exec.exec("git", ["config", "user.email", gitCommiter.email]);
// Checkout to new branch and commit
await exec_1.default.exec("git", ["checkout", "-b", head]);
await exec_1.default.exec("git", ["add", "."]);
await exec.exec("git", ["checkout", "-b", head]);
await exec.exec("git", ["add", "."]);
const commitMessage = "Update dependencies using Patcher by Gruntwork";
await exec_1.default.exec("git", ["commit", "-m", commitMessage]);
await exec.exec("git", ["commit", "-m", commitMessage]);
// Push changes to head branch
await exec_1.default.exec("git", ["push", "--force", "origin", `${head}:refs/heads/${head}`]);
await exec.exec("git", ["push", "--force", "origin", `${head}:refs/heads/${head}`]);
}
async function openPullRequest(octokit, gitCommiter, patcherRawOutput, dependency, workingDir, token) {
var _a;
const { repo } = github_1.default.context;
const { repo } = github.context;
const head = pullRequestBranch(dependency, workingDir);
const title = pullRequestTitle(dependency, workingDir);
const body = pullRequestBody(patcherRawOutput, dependency);
const repoDetails = await octokit.rest.repos.get({ ...repo });
const base = repoDetails.data.default_branch;
core_1.default.debug(`Base branch is ${base}. Opening the PR against it.`);
core.debug(`Base branch is ${base}. Opening the PR against it.`);
try {
await octokit.rest.pulls.create({ ...repo, title, head, base, body });
}
catch (error) {
if ((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes(`A pull request already exists for`)) {
core_1.default.error(`A pull request for ${head} already exists. The branch was updated.`);
core.error(`A pull request for ${head} already exists. The branch was updated.`);
}
else {
throw error;
}
}
}
async function downloadPatcherBinary(octokit, owner, repo, tag, token) {
core_1.default.info(`Downloading Patcher version ${tag}`);
core.info(`Downloading Patcher version ${tag}`);
const getReleaseResponse = await octokit.rest.repos.getReleaseByTag({ owner, repo, tag });
const re = new RegExp(`${osPlatform()}.*amd64`);
const asset = getReleaseResponse.data.assets.find((obj) => (re.test(obj.name)));
if (!asset) {
throw new Error(`Can not find Patcher release for ${tag} in platform ${re}.`);
}
// Use @actions/tool-cache to download Patcher's binary from GitHub
const patcherBinaryPath = await tool_cache_1.default.downloadTool(asset.url, PATCHER_BINARY_PATH, `token ${token}`, {
const patcherBinaryPath = await toolCache.downloadTool(asset.url, PATCHER_BINARY_PATH, `token ${token}`, {
accept: "application/octet-stream"
});
core_1.default.debug(`Patcher version '${tag}' has been downloaded at ${patcherBinaryPath}`);
core.debug(`Patcher version '${tag}' has been downloaded at ${patcherBinaryPath}`);
return patcherBinaryPath;
}
function isPatcherCommandValid(command) {
Expand All @@ -13684,7 +13704,7 @@ function updateArgs(updateStrategy, dependency, workingDir) {
return args.concat([workingDir]);
}
function getPatcherEnvVars(token) {
const telemetryId = `GHAction-${github_1.default.context.repo.owner}/${github_1.default.context.repo.repo}`;
const telemetryId = `GHAction-${github.context.repo.owner}/${github.context.repo.repo}`;
return {
...process.env,
"GITHUB_OAUTH_TOKEN": token,
Expand All @@ -13694,39 +13714,39 @@ function getPatcherEnvVars(token) {
async function runPatcher(octokit, gitCommiter, binaryPath, command, { updateStrategy, dependency, workingDir, token }) {
switch (command) {
case REPORT_COMMAND:
core_1.default.startGroup("Running 'patcher report'");
const reportOutput = await exec_1.default.getExecOutput(binaryPath, [command, NON_INTERACTIVE_FLAG, workingDir], { env: getPatcherEnvVars(token) });
core_1.default.endGroup();
core_1.default.startGroup("Setting 'dependencies' output");
core_1.default.setOutput("dependencies", reportOutput.stdout);
core_1.default.endGroup();
core.startGroup("Running 'patcher report'");
const reportOutput = await exec.getExecOutput(binaryPath, [command, NON_INTERACTIVE_FLAG, workingDir], { env: getPatcherEnvVars(token) });
core.endGroup();
core.startGroup("Setting 'dependencies' output");
core.setOutput("dependencies", reportOutput.stdout);
core.endGroup();
return;
default:
core_1.default.startGroup("Running 'patcher update'");
const updateOutput = await exec_1.default.getExecOutput(binaryPath, updateArgs(updateStrategy, dependency, workingDir), { env: getPatcherEnvVars(token) });
core_1.default.endGroup();
core.startGroup("Running 'patcher update'");
const updateOutput = await exec.getExecOutput(binaryPath, updateArgs(updateStrategy, dependency, workingDir), { env: getPatcherEnvVars(token) });
core.endGroup();
if (await wasCodeUpdated()) {
core_1.default.startGroup("Commit and push changes");
core.startGroup("Commit and push changes");
await commitAndPushChanges(gitCommiter, dependency, workingDir, token);
core_1.default.endGroup();
core_1.default.startGroup("Opening pull request");
core.endGroup();
core.startGroup("Opening pull request");
await openPullRequest(octokit, gitCommiter, updateOutput.stdout, dependency, workingDir, token);
core_1.default.endGroup();
core.endGroup();
}
else {
core_1.default.info(`No changes in ${dependency} after running Patcher. No further action is necessary.`);
core.info(`No changes in ${dependency} after running Patcher. No further action is necessary.`);
}
return;
}
}
function parseCommitAuthor(commitAuthor) {
const pattern = new RegExp(/^([^<]+)\s+<([^>]+)>$/);
core_1.default.debug(`pattern test is ${pattern.test(commitAuthor)}`);
core.debug(`pattern test is ${pattern.test(commitAuthor)}`);
const match = commitAuthor.match(pattern);
if (match) {
const name = match[1];
const email = match[2];
core_1.default.debug(`Committer data is ${commitAuthor} -> '${name}' '${email}'`);
core.debug(`Committer data is ${commitAuthor} -> '${name}' '${email}'`);
return { name, email };
}
throw Error(`Invalid commit_author input: "${commitAuthor}". Should be in the format "Name <name@email.com>"`);
Expand All @@ -13748,58 +13768,35 @@ async function validateAccessToPatcherCli(octokit) {
}
}
async function run() {
const token = core_1.default.getInput("github_token");
const command = core_1.default.getInput("patcher_command");
const updateStrategy = core_1.default.getInput("update_strategy");
const dependency = core_1.default.getInput("dependency");
const workingDir = core_1.default.getInput("working_dir");
const commitAuthor = core_1.default.getInput("commit_author");
const token = core.getInput("github_token");
const command = core.getInput("patcher_command");
const updateStrategy = core.getInput("update_strategy");
const dependency = core.getInput("dependency");
const workingDir = core.getInput("working_dir");
const commitAuthor = core.getInput("commit_author");
// Always mask the `token` string in the logs.
core_1.default.setSecret(token);
core.setSecret(token);
// Only run the action if the user has access to Patcher. Otherwise, the download won't work.
const octokit = github_1.default.getOctokit(token);
const octokit = github.getOctokit(token);
await validateAccessToPatcherCli(octokit);
// Validate if the 'patcher_command' provided is valid.
if (!isPatcherCommandValid(command)) {
throw new Error(`Invalid Patcher command ${command}`);
}
core_1.default.info(`Patcher's ${command}' command will be executed.`);
core.info(`Patcher's ${command}' command will be executed.`);
// Validate if 'commit_author' has a valid format.
const gitCommiter = parseCommitAuthor(commitAuthor);
core_1.default.startGroup("Downloading Patcher");
core.startGroup("Downloading Patcher");
const patcherPath = await downloadPatcherBinary(octokit, GRUNTWORK_GITHUB_ORG, PATCHER_GITHUB_REPO, PATCHER_VERSION, token);
core_1.default.endGroup();
core_1.default.startGroup("Granting permissions to Patcher's binary");
await exec_1.default.exec("chmod", ["+x", patcherPath]);
core_1.default.endGroup();
core.endGroup();
core.startGroup("Granting permissions to Patcher's binary");
await exec.exec("chmod", ["+x", patcherPath]);
core.endGroup();
await runPatcher(octokit, gitCommiter, patcherPath, command, { updateStrategy, dependency, workingDir, token });
}
exports.run = run;


/***/ }),

/***/ 6144:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";

var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core_1 = __importDefault(__nccwpck_require__(2186));
const action_1 = __nccwpck_require__(7672);
(async () => {
try {
await (0, action_1.run)();
}
catch (e) {
core_1.default.setFailed(`Action failed with "${e}"`);
}
})();


/***/ }),

/***/ 2877:
Expand Down Expand Up @@ -20249,7 +20246,7 @@ var int = __nccwpck_require__(3019);
var schema = __nccwpck_require__(27);
var schema$1 = __nccwpck_require__(4545);
var binary = __nccwpck_require__(5724);
var omap = __nccwpck_require__(644);
var omap = __nccwpck_require__(8974);
var pairs = __nccwpck_require__(9841);
var schema$2 = __nccwpck_require__(5389);
var set = __nccwpck_require__(7847);
Expand Down Expand Up @@ -20582,7 +20579,7 @@ exports.intOct = intOct;

/***/ }),

/***/ 644:
/***/ 8974:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";
Expand Down Expand Up @@ -20770,7 +20767,7 @@ var binary = __nccwpck_require__(5724);
var bool = __nccwpck_require__(2631);
var float = __nccwpck_require__(8035);
var int = __nccwpck_require__(9503);
var omap = __nccwpck_require__(644);
var omap = __nccwpck_require__(8974);
var pairs = __nccwpck_require__(9841);
var set = __nccwpck_require__(7847);
var timestamp = __nccwpck_require__(1156);
Expand Down Expand Up @@ -22413,12 +22410,24 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module is referenced by other modules so it can't be inlined
/******/ var __webpack_exports__ = __nccwpck_require__(6144);
/******/ module.exports = __webpack_exports__;
/******/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
(() => {
"use strict";
var exports = __webpack_exports__;

Object.defineProperty(exports, "__esModule", ({ value: true }));
const action_1 = __nccwpck_require__(7672);
(async () => {
// try {
await (0, action_1.run)();
// } catch (e) {
// core.setFailed(`Action failed with "${e}"`);
// }
})();

})();

module.exports = __webpack_exports__;
/******/ })()
;
12 changes: 6 additions & 6 deletions src/action.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os from "os";
import yaml from "yaml";
import * as os from "os";
import * as yaml from "yaml";

import github from "@actions/github";
import toolCache from "@actions/tool-cache";
import core from "@actions/core";
import exec from "@actions/exec";
import * as github from "@actions/github";
import * as toolCache from "@actions/tool-cache";
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import { Api as GitHub } from "@octokit/plugin-rest-endpoint-methods/dist-types/types";

// Define constants
Expand Down

0 comments on commit 3dd5920

Please sign in to comment.