@@ -12528,14 +12528,26 @@ function isEmptyObject(obj) {
1252812528/***/ }),
1252912529
1253012530/***/ 7037:
12531- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
12531+ /***/ (function (__unused_webpack_module, exports, __nccwpck_require__) {
1253212532
1253312533"use strict";
1253412534
12535+ var __importDefault = (this && this.__importDefault) || function (mod) {
12536+ return (mod && mod.__esModule) ? mod : { "default": mod };
12537+ };
1253512538Object.defineProperty(exports, "__esModule", ({ value: true }));
12539+ exports.GIT_ERRORS = void 0;
12540+ const github_1 = __nccwpck_require__(5438);
1253612541const child_process_1 = __nccwpck_require__(2081);
1253712542const util_1 = __nccwpck_require__(3837);
12543+ const GithubUtils_1 = __importDefault(__nccwpck_require__(9296));
12544+ const Logger_1 = __nccwpck_require__(8891);
1253812545const exec = (0, util_1.promisify)(child_process_1.exec);
12546+ const IS_CI = process.env.CI === 'true';
12547+ const GIT_ERRORS = {
12548+ FAILED_TO_FETCH_FROM_REMOTE: 'Failed to fetch from remote',
12549+ };
12550+ exports.GIT_ERRORS = GIT_ERRORS;
1253912551/**
1254012552 * Utility class for git operations.
1254112553 */
@@ -12774,10 +12786,146 @@ class Git {
1277412786 throw new Error(`Failed to fetch git reference ${ref}: ${error instanceof Error ? error.message : String(error)}`);
1277512787 }
1277612788 }
12789+ static getMainBaseCommitHash(remote) {
12790+ // Fetch the main branch from the specified remote to ensure it's available
12791+ try {
12792+ (0, child_process_1.execSync)(`git fetch ${remote} main --no-tags --depth=1 -q`, { encoding: 'utf8' });
12793+ }
12794+ catch (error) {
12795+ throw new Error(GIT_ERRORS.FAILED_TO_FETCH_FROM_REMOTE);
12796+ }
12797+ // In CI, use a simpler approach - just use the remote main branch directly
12798+ // This avoids issues with shallow clones and merge-base calculations
12799+ if (IS_CI) {
12800+ try {
12801+ const mergeBaseHash = (0, child_process_1.execSync)(`git rev-parse ${remote}/main`, { encoding: 'utf8' }).trim();
12802+ // Validate the output is a proper SHA hash
12803+ if (!mergeBaseHash || !/^[a-fA-F0-9]{40}$/.test(mergeBaseHash)) {
12804+ throw new Error(`git rev-parse returned unexpected output: ${mergeBaseHash}`);
12805+ }
12806+ return mergeBaseHash;
12807+ }
12808+ catch (error) {
12809+ (0, Logger_1.error)(`Failed to get commit hash for ${remote}/main:`, error);
12810+ throw new Error(`Could not get commit hash for ${remote}/main`);
12811+ }
12812+ }
12813+ // For local development, try to find the actual merge base
12814+ let mergeBaseHash;
12815+ try {
12816+ mergeBaseHash = (0, child_process_1.execSync)(`git merge-base ${remote}/main HEAD`, { encoding: 'utf8' }).trim();
12817+ }
12818+ catch (error) {
12819+ // If merge-base fails locally, fall back to using the remote main branch
12820+ try {
12821+ mergeBaseHash = (0, child_process_1.execSync)(`git rev-parse ${remote}/main`, { encoding: 'utf8' }).trim();
12822+ (0, Logger_1.error)(`Warning: Could not find merge base between ${remote}/main and HEAD. Using ${remote}/main as base.`);
12823+ }
12824+ catch (fallbackError) {
12825+ (0, Logger_1.error)(`Failed to find merge base with ${remote}/main:`, error);
12826+ (0, Logger_1.error)(`Fallback also failed:`, fallbackError);
12827+ throw new Error(`Could not determine merge base with ${remote}/main`);
12828+ }
12829+ }
12830+ // Validate the output is a proper SHA hash
12831+ if (!mergeBaseHash || !/^[a-fA-F0-9]{40}$/.test(mergeBaseHash)) {
12832+ throw new Error(`git merge-base returned unexpected output: ${mergeBaseHash}`);
12833+ }
12834+ return mergeBaseHash;
12835+ }
12836+ static async getChangedFiles(remote) {
12837+ if (IS_CI) {
12838+ const { data: changedFiles } = await GithubUtils_1.default.octokit.pulls.listFiles({
12839+ owner: 'Expensify',
12840+ repo: 'App',
12841+ // eslint-disable-next-line @typescript-eslint/naming-convention
12842+ pull_number: github_1.context.payload.pull_request?.number ?? 0,
12843+ });
12844+ return changedFiles.map((file) => file.filename);
12845+ }
12846+ try {
12847+ // Get files changed in the current branch/commit
12848+ const mainBaseCommitHash = this.getMainBaseCommitHash(remote);
12849+ // Get the diff output and check status
12850+ const gitDiffOutput = (0, child_process_1.execSync)(`git diff --diff-filter=AMR --name-only ${mainBaseCommitHash} HEAD`, {
12851+ encoding: 'utf8',
12852+ });
12853+ const files = gitDiffOutput.trim().split('\n');
12854+ return files;
12855+ }
12856+ catch (error) {
12857+ if (error instanceof Error && error.message === GIT_ERRORS.FAILED_TO_FETCH_FROM_REMOTE) {
12858+ throw error;
12859+ }
12860+ (0, Logger_1.error)('Could not determine changed files:', error);
12861+ throw error;
12862+ }
12863+ }
1277712864}
1277812865exports["default"] = Git;
1277912866
1278012867
12868+ /***/ }),
12869+
12870+ /***/ 8891:
12871+ /***/ ((__unused_webpack_module, exports) => {
12872+
12873+ "use strict";
12874+
12875+ Object.defineProperty(exports, "__esModule", ({ value: true }));
12876+ exports.bold = exports.formatLink = exports.success = exports.error = exports.note = exports.warn = exports.info = exports.log = void 0;
12877+ const COLOR_DIM = '\x1b[2m';
12878+ const COLOR_RESET = '\x1b[0m';
12879+ const COLOR_YELLOW = '\x1b[33m';
12880+ const COLOR_RED = '\x1b[31m';
12881+ const COLOR_GREEN = '\x1b[32m';
12882+ const COLOR_BOLD = '\x1b[1m';
12883+ const EMOJIS = {
12884+ // One column emojis need to be rendered with an extra space after to align with two column emojis
12885+ INFO: '▶️ ',
12886+ // Two column emojis can be rendered as-is
12887+ SUCCESS: '✅',
12888+ WARN: '⚠️',
12889+ ERROR: '🔴',
12890+ };
12891+ const log = (...args) => {
12892+ console.debug(...args);
12893+ };
12894+ exports.log = log;
12895+ const info = (...args) => {
12896+ const lines = [EMOJIS.INFO, ...args];
12897+ log(...lines);
12898+ };
12899+ exports.info = info;
12900+ const bold = (...args) => {
12901+ const lines = [COLOR_BOLD, ...args, COLOR_RESET];
12902+ log(...lines);
12903+ };
12904+ exports.bold = bold;
12905+ const success = (...args) => {
12906+ const lines = [`${EMOJIS.SUCCESS}${COLOR_GREEN}`, ...args, COLOR_RESET];
12907+ log(...lines);
12908+ };
12909+ exports.success = success;
12910+ const warn = (...args) => {
12911+ const lines = [`${EMOJIS.WARN}${COLOR_YELLOW}`, ...args, COLOR_RESET];
12912+ log(...lines);
12913+ };
12914+ exports.warn = warn;
12915+ const note = (...args) => {
12916+ const lines = [COLOR_DIM, ...args, COLOR_RESET];
12917+ log(...lines);
12918+ };
12919+ exports.note = note;
12920+ const error = (...args) => {
12921+ const lines = [`${EMOJIS.ERROR}${COLOR_RED}`, ...args, COLOR_RESET];
12922+ log(...lines);
12923+ };
12924+ exports.error = error;
12925+ const formatLink = (name, url) => `\x1b]8;;${url}\x1b\\${name}\x1b]8;;\x1b\\`;
12926+ exports.formatLink = formatLink;
12927+
12928+
1278112929/***/ }),
1278212930
1278312931/***/ 9491:
0 commit comments