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)); }