Skip to content

Commit

Permalink
DOP-4945 reconfigure app to display in groups
Browse files Browse the repository at this point in the history
  • Loading branch information
anabellabuckvar committed Apr 16, 2024
1 parent 81f946d commit df7b195
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 29 deletions.
9 changes: 6 additions & 3 deletions api/controllers/v1/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { SlackConnector } from '../../../src/services/slack';
import { APIGatewayEvent, APIGatewayProxyResult } from 'aws-lambda';
import { JobRepository } from '../../../src/repositories/jobRepository';
import {
buildEntitledBranchList,
// buildEntitledBranchList,
buildEntitledGroupsList,
getQSString,
isRestrictedToDeploy,
isUserEntitled,
Expand Down Expand Up @@ -50,7 +51,8 @@ export const DisplayRepoOptions = async (event: APIGatewayEvent): Promise<APIGat

const isAdmin = await repoEntitlementRepository.getIsAdmin(key_val['user_id']);

const entitledBranches = await buildEntitledBranchList(entitlement, repoBranchesRepository);
const entitledBranches = await buildEntitledGroupsList(entitlement, repoBranchesRepository);
console.log('repo groups', entitledBranches);
const resp = await slackConnector.displayRepoOptions(entitledBranches, key_val['trigger_id'], isAdmin);
if (resp?.status == 200 && resp?.data) {
return {
Expand Down Expand Up @@ -207,7 +209,8 @@ export const DeployRepo = async (event: any = {}): Promise<any> => {
const decoded = decodeURIComponent(event.body).split('=')[1];
const parsed = JSON.parse(decoded);
const stateValues = parsed.view.state.values;
consoleLogger.info('payload view', JSON.stringify(parsed.view));
consoleLogger.info('parsed view', JSON.stringify(parsed.view));
consoleLogger.info('payload', JSON.stringify(parsed.payload));

//TODO: create an interface for slack view_submission payloads
if (parsed.type !== 'view_submission') {
Expand Down
49 changes: 41 additions & 8 deletions api/handlers/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,60 @@ export function prepResponse(statusCode, contentType, body) {
};
}

export async function buildEntitledBranchList(entitlement: any, repoBranchesRepository: RepoBranchesRepository) {
const entitledBranches: string[] = [];
// export async function buildEntitledBranchList(entitlement: any, repoBranchesRepository: RepoBranchesRepository) {
// const entitledBranches: string[] = [];
// for (const repo of entitlement.repos) {
// const [repoOwner, repoName, directoryPath] = repo.split('/');
// const branches = await repoBranchesRepository.getRepoBranches(repoName, directoryPath);
// for (const branch of branches) {
// const buildWithSnooty = branch['buildsWithSnooty'];
// if (buildWithSnooty) {
// const active = branch['active'];
// const repoPath = `${repoOwner}/${repoName}${directoryPath ? '/' + directoryPath : ''}/${
// branch['gitBranchName']
// }`;
// if (!active) {
// entitledBranches.push(`(!inactive) ${repoPath}`);
// } else {
// entitledBranches.push(repoPath);
// }
// }
// }
// }
// return entitledBranches.sort();
// }

//if person is admin, get all prod deployable repos
export async function buildEntitledGroupsList(entitlement: any, repoBranchesRepository: RepoBranchesRepository) {
const repoOptions: any[] = [];
for (const repo of entitlement.repos) {
const [repoOwner, repoName, directoryPath] = repo.split('/');

const branches = await repoBranchesRepository.getRepoBranches(repoName, directoryPath);
const options: string[] = [];
for (const branch of branches) {
const buildWithSnooty = branch['buildsWithSnooty'];
if (buildWithSnooty) {
const active = branch['active'];
const repoPath = `${repoOwner}/${repoName}${directoryPath ? '/' + directoryPath : ''}/${
branch['gitBranchName']
}`;
const repoPath = `${repoName}${directoryPath ? '/' + directoryPath : ''}/${branch['gitBranchName']}`;
if (!active) {
entitledBranches.push(`(!inactive) ${repoPath}`);
options.push(`(!inactive) ${repoPath}`);
} else {
entitledBranches.push(repoPath);
options.push(repoPath);
}
}
}

const repoOption = {
label: {
type: 'plain_text',
text: repoOwner,
},
options: options.sort(),
};
repoOptions.push(repoOption);
}
return entitledBranches.sort();
return repoOptions;
}

export function getQSString(qs: string) {
Expand Down
38 changes: 20 additions & 18 deletions src/services/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ export class SlackConnector implements ISlackConnector {
}

async displayRepoOptions(repos: string[], triggerId: string, isAdmin: boolean): Promise<any> {
const reposToShow = this._buildDropdown(repos);
const repoOptView = this._getDropDownView(triggerId, reposToShow, isAdmin);
// const reposToShow = this._buildDropdown(repos);
const repoOptView = this._getDropDownView(triggerId, repos, isAdmin);
const slackToken = this._config.get<string>('slackAuthToken');
const slackUrl = this._config.get<string>('slackViewOpenUrl');
return await axiosApi.post(slackUrl, repoOptView, {
Expand Down Expand Up @@ -204,24 +204,26 @@ export class SlackConnector implements ISlackConnector {
},
accessory: {
type: 'static_select',
option_groups: [
{
label: {
type: 'plain_text',
text: `${repos.length}`,
},
options: repos.slice(0, 50),
},
{
label: {
type: 'plain_text',
text: `${repos[-1]}`,
},
options: repos.slice(50, repos.length),
},
],
option_groups: repos,
// [
// {
// label: {
// type: 'plain_text',
// text: `${repos.length}`,
// },
// options: repos.slice(0, 50),
// },
// {
// label: {
// type: 'plain_text',
// text: `${repos[-1]}`,
// },
// options: repos.slice(50, repos.length),
// },
// ],
},
},

// {
// type: 'input',
// dispatch_action: true,
Expand Down

0 comments on commit df7b195

Please sign in to comment.