From 34e3ca97a03285f53595ff1fbe7b6d64c6d22cfd Mon Sep 17 00:00:00 2001 From: anabellabuckvar <41971124+anabellabuckvar@users.noreply.github.com> Date: Wed, 17 Apr 2024 11:09:30 -0400 Subject: [PATCH] DOP-4549 sorting properly --- api/handlers/slack.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/api/handlers/slack.ts b/api/handlers/slack.ts index 1a6ad9211a..e7fbd4693a 100644 --- a/api/handlers/slack.ts +++ b/api/handlers/slack.ts @@ -53,7 +53,7 @@ export async function buildEntitledGroupsList(entitlement: any, repoBranchesRepo const buildWithSnooty = branch['buildsWithSnooty']; if (buildWithSnooty) { const active = branch['active']; - const branchName = `${directoryPath ? '/' + directoryPath : ''}/${branch['gitBranchName']}`; + const branchName = `${directoryPath ? directoryPath + '/' : ''}${branch['gitBranchName']}`; const repoPath = `${repoOwner}/${repoName}/${branchName}`; let txt: string; if (!active) { @@ -71,19 +71,26 @@ export async function buildEntitledGroupsList(entitlement: any, repoBranchesRepo } } - //create a sort function to sort the options by their text + //return the list of branches as a an array of objects for a given repo + //sorted by branch name const repoOption = { label: { type: 'plain_text', - text: repoOwner, + text: repoName, }, options: options.sort((branchOne, branchTwo) => { - return branchOne.text.text.localeCompare(branchTwo.text.text); + return 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; + //return repoOptions list sorted alphabetically by repo name + return repoOptions.sort((repoOne, repoTwo) => { + return repoOne.label.repoName.localeCompare(repoTwo.label.repoName); + }); } export function getQSString(qs: string) {