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

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

function parseDashboardIssue(issueBody: string): DependencyDashboard {
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]+) -->';
viceice marked this conversation as resolved.
Show resolved Hide resolved
const checked = issueBody.match(regEx(checkMatch, 'g'));
return issueBody.match(regEx(checkMatch, 'g'));
}

function parseDashboardIssue(issueBody: string): DependencyDashboard {
const checked = getCheckedBranches(issueBody);
const dependencyDashboardChecks: Record<string, string> = {};
if (checked?.length) {
// duplicate regex is temporary, will be changed in #15912
const checkMatch = ' - \\[x\\] <!-- ([a-zA-Z]+)-branch=([^\\s]+) -->';
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