Skip to content

Commit

Permalink
DOP-4549 (hotfix) (#1044)
Browse files Browse the repository at this point in the history
* DOP-4549-c hotfix check for empty group

* DOP-4549-c add extra error check
  • Loading branch information
anabellabuckvar authored May 9, 2024
1 parent 51032f4 commit 01223b9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
2 changes: 1 addition & 1 deletion api/controllers/v1/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const DisplayRepoOptions = async (event: APIGatewayEvent): Promise<APIGat

const entitledBranches = await buildEntitledGroupsList(entitlement, repoBranchesRepository);
const resp = await slackConnector.displayRepoOptions(entitledBranches, key_val['trigger_id'], isAdmin);
if (resp?.status == 200 && resp?.data) {
if (resp?.status == 200 && resp?.data?.ok) {
return {
statusCode: 200,
body: 'Model requested',
Expand Down
72 changes: 37 additions & 35 deletions api/handlers/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit 01223b9

Please sign in to comment.