Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(dependencyDashboard): split parseDashboardIssue function #16782

26 changes: 16 additions & 10 deletions lib/workers/repository/dependency-dashboard.ts
Expand Up @@ -15,25 +15,31 @@ interface DependencyDashboard {
dependencyDashboardRebaseAllOpen: boolean;
}

function checkRebaseAll(issueBody: string): boolean {
return issueBody.includes(' - [x] <!-- rebase-all-open-prs -->');
}

function getCheckedBranches(issueBody: string): RegExpMatchArray | null {
const checkMatch = ' - \\[[x]\\] <!-- ([a-zA-Z]+)-branch=([^\\s]+) -->';
MaronHatoum marked this conversation as resolved.
Show resolved Hide resolved
return issueBody.match(regEx(checkMatch, 'g'));
}

function parseDashboardIssue(issueBody: string): DependencyDashboard {
const checkMatch = ' - \\[x\\] <!-- ([a-zA-Z]+)-branch=([^\\s]+) -->';
const checked = issueBody.match(regEx(checkMatch, 'g'));
const checked = getCheckedBranches(issueBody);
const dependencyDashboardChecks: Record<string, string> = {};
if (checked?.length) {
const checkMatch = ' - \\[[ x]\\] <!-- ([a-zA-Z]+)-branch=([^\\s]+) -->';
MaronHatoum marked this conversation as resolved.
Show resolved Hide resolved
const re = regEx(checkMatch);
checked.forEach((check) => {
const [, type, branchName] = re.exec(check)!;
dependencyDashboardChecks[branchName] = type;
});
}
const checkedRebaseAll = issueBody.includes(
' - [x] <!-- rebase-all-open-prs -->'
);
let dependencyDashboardRebaseAllOpen = false;
if (checkedRebaseAll) {
dependencyDashboardRebaseAllOpen = true;
}
return { dependencyDashboardChecks, dependencyDashboardRebaseAllOpen };
const rebaseAll = checkRebaseAll(issueBody);
return {
dependencyDashboardChecks,
dependencyDashboardRebaseAllOpen: rebaseAll,
MaronHatoum marked this conversation as resolved.
Show resolved Hide resolved
};
}

export async function readDashboardBody(
Expand Down