From 28e4ce75742bd433d90a72904c52eee676ab24bf Mon Sep 17 00:00:00 2001 From: anabellabuckvar <41971124+anabellabuckvar@users.noreply.github.com> Date: Thu, 9 May 2024 16:40:04 -0400 Subject: [PATCH] DOP-4549-c hotfix check for empty group --- api/handlers/slack.ts | 72 ++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/api/handlers/slack.ts b/api/handlers/slack.ts index 83d42c086..51dc4e686 100644 --- a/api/handlers/slack.ts +++ b/api/handlers/slack.ts @@ -23,45 +23,47 @@ export async function buildEntitledGroupsList(entitlement: any, repoBranchesRepo const repoOptions: any[] = []; for (const repo of entitlement.repos) { const [repoOwner, repoName, directoryPath] = repo.split('/'); - const branches = await repoBranchesRepository.getRepoBranches(repoName, directoryPath); - const options: any[] = []; - for (const branch of branches) { - const buildWithSnooty = branch['buildsWithSnooty']; - if (buildWithSnooty) { - const active = branch['active']; - const branchName = `${directoryPath ? `${directoryPath}/` : ''}${branch['gitBranchName']}`; - const repoPath = `${repoOwner}/${repoName}/${branchName}`; - let txt: string; - if (!active) { - txt = `(!inactive) ${repoPath}`; - } else { - txt = repoPath; + + if (branches.length) { + const options: any[] = []; + for (const branch of branches) { + const buildWithSnooty = branch['buildsWithSnooty']; + if (buildWithSnooty) { + const active = branch['active']; + const branchName = `${directoryPath ? `${directoryPath}/` : ''}${branch['gitBranchName']}`; + const repoPath = `${repoOwner}/${repoName}/${branchName}`; + let txt: string; + if (!active) { + txt = `(!inactive) ${repoPath}`; + } else { + txt = repoPath; + } + options.push({ + text: { + type: 'plain_text', + text: txt, + }, + value: repoPath, + }); } - options.push({ - text: { - type: 'plain_text', - text: txt, - }, - value: repoPath, - }); } - } - const repoOption = { - label: { - type: 'plain_text', - text: repoName, - }, - //sort the options by version number - options: options.sort((branchOne, branchTwo) => - branchTwo.text.text - .toString() - .replace(/\d+/g, (n) => +n + 100000) - .localeCompare(branchOne.text.text.toString().replace(/\d+/g, (n) => +n + 100000)) - ), - }; - repoOptions.push(repoOption); + const repoOption = { + label: { + type: 'plain_text', + text: repoName, + }, + //sort the options by version number + options: options.sort((branchOne, branchTwo) => + branchTwo.text.text + .toString() + .replace(/\d+/g, (n) => +n + 100000) + .localeCompare(branchOne.text.text.toString().replace(/\d+/g, (n) => +n + 100000)) + ), + }; + repoOptions.push(repoOption); + } } return repoOptions.sort((repoOne, repoTwo) => repoOne.label.text.localeCompare(repoTwo.label.text)); }