diff --git a/api/controllers/v1/slack.ts b/api/controllers/v1/slack.ts index 80c9dc484..906ebfa78 100644 --- a/api/controllers/v1/slack.ts +++ b/api/controllers/v1/slack.ts @@ -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, @@ -50,7 +51,8 @@ export const DisplayRepoOptions = async (event: APIGatewayEvent): Promise => { 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') { diff --git a/api/handlers/slack.ts b/api/handlers/slack.ts index 4b8d534cd..5d02e6340 100644 --- a/api/handlers/slack.ts +++ b/api/handlers/slack.ts @@ -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) { diff --git a/src/services/slack.ts b/src/services/slack.ts index c6d81c8b3..d0e9868fc 100644 --- a/src/services/slack.ts +++ b/src/services/slack.ts @@ -120,8 +120,8 @@ export class SlackConnector implements ISlackConnector { } async displayRepoOptions(repos: string[], triggerId: string, isAdmin: boolean): Promise { - 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('slackAuthToken'); const slackUrl = this._config.get('slackViewOpenUrl'); return await axiosApi.post(slackUrl, repoOptView, { @@ -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,