Skip to content

Commit

Permalink
DOP-4549 cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
anabellabuckvar committed May 1, 2024
1 parent a4da331 commit 207d1d7
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 71 deletions.
3 changes: 0 additions & 3 deletions api/controllers/v1/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ 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;
console.log(JSON.stringify(stateValues));

//TODO: create an interface for slack view_submission payloads
if (parsed.type !== 'view_submission') {
Expand All @@ -215,15 +214,13 @@ export const DeployRepo = async (event: any = {}): Promise<any> => {

let values = [];
const isAdmin = await repoEntitlementRepository.getIsAdmin(parsed.user.id);
console.log('ADMIN' + isAdmin);
try {
values = await slackConnector.parseSelection(stateValues, isAdmin, repoBranchesRepository);
} catch (e) {
console.log(`Error parsing selection: ${e}`);
return prepResponse(401, 'text/plain', e);
}
const deployable = await getDeployableJobs(values, entitlement, repoBranchesRepository, docsetsRepository);
console.log('DEPLOYABLE' + JSON.stringify(deployable));

if (deployable.length > 0) {
await deployRepo(deployable, consoleLogger, jobRepository, c.get('jobsQueueUrl'));
Expand Down
4 changes: 0 additions & 4 deletions api/controllers/v2/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { JobRepository } from '../../../src/repositories/jobRepository';
import { APIGatewayEvent, APIGatewayProxyResult } from 'aws-lambda';
import { EnhancedPayload, JobStatus } from '../../../src/entities/job';
import {
// buildEntitledBranchList,
buildEntitledGroupsList,
getQSString,
isRestrictedToDeploy,
Expand All @@ -21,8 +20,6 @@ export const DisplayRepoOptions = async (event: APIGatewayEvent): Promise<APIGat
const consoleLogger = new ConsoleLogger();
const slackConnector = new SlackConnector(consoleLogger, c);

consoleLogger.info('deployRepo', 'testing display repo options');

if (!slackConnector.validateSlackRequest(event)) {
return prepResponse(401, 'text/plain', 'Signature Mismatch, Authentication Failed!');
}
Expand Down Expand Up @@ -239,7 +236,6 @@ export const DeployRepo = async (event: APIGatewayEvent): Promise<APIGatewayProx
}

const deployable = await getDeployableJobs(values, entitlement, repoBranchesRepository, docsetsRepository);
consoleLogger.info('deployRepo', 'testing Deploy Repo');
if (deployable.length > 0) {
await deployRepo(deployable, consoleLogger, jobRepository, c.get('jobsQueueUrl'));
}
Expand Down
25 changes: 1 addition & 24 deletions api/handlers/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,6 @@ export function prepResponse(statusCode, contentType, body) {
};
}

// 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[] = [];
Expand Down Expand Up @@ -71,7 +48,7 @@ export async function buildEntitledGroupsList(entitlement: any, repoBranchesRepo
}
}

//create a sort function to sort the options by their text
//sort the options by version number
const repoOption = {
label: {
type: 'plain_text',
Expand Down
40 changes: 0 additions & 40 deletions src/services/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export class SlackConnector implements ISlackConnector {
block_hash_option: 'hash_option',
};

console.log('parsing');
// if deploy all was selected:
if (stateValues['block_deploy_option']?.deploy_option?.selected_option?.value == 'deploy_all') {
if (!isAdmin) {
Expand Down Expand Up @@ -120,7 +119,6 @@ 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, repos, isAdmin);
const slackToken = this._config.get<string>('slackAuthToken');
const slackUrl = this._config.get<string>('slackViewOpenUrl');
Expand Down Expand Up @@ -232,42 +230,4 @@ export class SlackConnector implements ISlackConnector {
},
};
}

private _buildDropdown(branches: Array<string>): Array<any> {
let reposToShow: Array<any> = [];
branches.forEach((fullPath) => {
const displayBranchPath = fullPath;
let valueBranchPath = fullPath;
const isInactive = fullPath.startsWith('(!inactive)');
if (isInactive == true) {
valueBranchPath = fullPath.slice(12);
}
const opt = {
text: {
type: 'plain_text',
text: displayBranchPath,
},
value: valueBranchPath,
};
reposToShow.push(opt);
});

// This is the limitation enforced by slack as no more 100 items are allowd in the dropdown
//Sort the list so that any inactive versions are at the end and will be truncated if any items must be truncated
//'[ERROR] no more than 100 items allowed [json-pointer:/view/blocks/0/element/options]'

if (reposToShow.length > 100) {
reposToShow = reposToShow.sort().reverse().splice(0, 150);
}

//sort versions like so: 4.1, 4.2, 4.11
reposToShow.sort((a, b) => {
return b.text.text
.toString()
.replace(/\d+/g, (n) => +n + 100000)
.localeCompare(a.text.text.toString().replace(/\d+/g, (n) => +n + 100000));
});

return reposToShow;
}
}

0 comments on commit 207d1d7

Please sign in to comment.