Skip to content

Commit

Permalink
Update idChangeValidator.ts
Browse files Browse the repository at this point in the history
Added condition to handle missing branch issue.
  • Loading branch information
rahul0216 committed Jan 23, 2025
1 parent 031a9af commit 3a35c10
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion .script/idChangeValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,29 @@ export async function IsIdHasChanged(filePath: string): Promise<ExitCode> {
console.log(filePath);

if (typeof pr === "undefined") {
console.log("Azure DevOps CI for a Pull Request wasn't found. If issue persists - please open an issue");
console.log("Pull Request couldn't be fetched. If issue persists - please open an issue");
return ExitCode.ERROR;
}

// Fetch the base and head branches before running the diff
const branches = await git.branch();
if (!branches.all.includes(pr.base.ref)) {
try {
await git.fetch(['origin', pr.base.ref + ':' + pr.base.ref]);
} catch (e) {
console.error(`Error fetching branch ${pr.base.ref} from git:`, e);
return ExitCode.ERROR;
}
}
if (!branches.all.includes(pr.head.ref)) {
try {
await git.fetch(['origin', pr.head.ref + ':' + pr.head.ref]);
} catch (e) {
console.error(`Error fetching branch ${pr.head.ref} from git:`, e);
return ExitCode.ERROR;
}
}

const options = [pr.base.ref, pr.head.ref, filePath];
const diffSummary = await git.diff(options);
const idPosition = diffSummary.search(templateIdRegex);
Expand Down

0 comments on commit 3a35c10

Please sign in to comment.