-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate status and activity fragments
- Loading branch information
1 parent
10a13bf
commit 1db910b
Showing
20 changed files
with
212 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { AppState } from '../../environment/AppState' | ||
import { Route } from '../../internalHttpRouter/internalHttpRoute' | ||
import { CicadaAuthorizedAPIEvent } from '../../inboundInterfaces/lambdaTypes' | ||
import { isFailure } from '../../util/structuredResult' | ||
import { getRepository } from '../../domain/github/githubRepository' | ||
import { | ||
latestWorkflowRunEventsPerWorkflowForOwners, | ||
latestWorkflowRunEventsPerWorkflowForRepo | ||
} from '../../domain/github/githubLatestWorkflowRunEvents' | ||
import { invalidRequestResponse, notFoundHTMLResponse } from '../htmlResponses' | ||
import { createWorkflowRunEventTableResponse } from './views/activityAndStatusView' | ||
import { getAllAccountIdsForUser } from '../../domain/github/githubMembership' | ||
import { getOptionalRepoCoordinates } from './requestParsing/getOptionalRepoCoordinates' | ||
|
||
export const actionsStatusRoute: Route<CicadaAuthorizedAPIEvent> = { | ||
path: '/app/fragment/actionsStatus', | ||
target: actionsStatus | ||
} | ||
|
||
export async function actionsStatus(appState: AppState, event: CicadaAuthorizedAPIEvent) { | ||
const coordinatesResult = getOptionalRepoCoordinates(event) | ||
|
||
if (isFailure(coordinatesResult)) return coordinatesResult.failureResult | ||
const { ownerId, repoId } = coordinatesResult.result | ||
|
||
if (ownerId && repoId) return await actionsStatusForRepo(appState, ownerId, repoId) | ||
if (!ownerId && !repoId) return actionsStatusForHome(appState, event.userId) | ||
return invalidRequestResponse | ||
} | ||
|
||
async function actionsStatusForRepo(appState: AppState, ownerId: number, repoId: number) { | ||
// TODO eventually - make sure user has permission for this | ||
// TODO eventually - move repo check into domain logic | ||
if (!(await getRepository(appState, ownerId, repoId))) return notFoundHTMLResponse | ||
|
||
return createWorkflowRunEventTableResponse( | ||
'repoStatus', | ||
appState.clock, | ||
await latestWorkflowRunEventsPerWorkflowForRepo(appState, ownerId, repoId) | ||
) | ||
} | ||
|
||
async function actionsStatusForHome(appState: AppState, userId: number) { | ||
const accountIds = await getAllAccountIdsForUser(appState, userId) | ||
return createWorkflowRunEventTableResponse( | ||
'homeStatus', | ||
appState.clock, | ||
await latestWorkflowRunEventsPerWorkflowForOwners(appState, accountIds) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { AppState } from '../../environment/AppState' | ||
import { Route } from '../../internalHttpRouter/internalHttpRoute' | ||
import { CicadaAuthorizedAPIEvent } from '../../inboundInterfaces/lambdaTypes' | ||
import { isFailure } from '../../util/structuredResult' | ||
import { getRepository } from '../../domain/github/githubRepository' | ||
import { getRecentActivityForRepo } from '../../domain/github/githubActivity' | ||
import { invalidRequestResponse, notFoundHTMLResponse } from '../htmlResponses' | ||
import { | ||
createGithubActivityResponse, | ||
createGithubPushTableResponse, | ||
createWorkflowRunEventTableResponse | ||
} from './views/activityAndStatusView' | ||
import { getOptionalWorkflowCoordinates } from './requestParsing/getOptionalWorkflowCoordinates' | ||
import { getRunEventsForWorkflow } from '../../domain/github/githubWorkflowRunEvent' | ||
import { recentActiveBranchesForOwners } from '../../domain/github/githubLatestPushesPerRef' | ||
import { getAllAccountIdsForUser } from '../../domain/github/githubMembership' | ||
import { logger } from '../../util/logging' | ||
|
||
export const gitHubActivityRoute: Route<CicadaAuthorizedAPIEvent> = { | ||
path: '/app/fragment/gitHubActivity', | ||
target: gitHubActivity | ||
} | ||
|
||
export async function gitHubActivity(appState: AppState, event: CicadaAuthorizedAPIEvent) { | ||
const coordinatesResult = getOptionalWorkflowCoordinates(event) | ||
|
||
if (isFailure(coordinatesResult)) return coordinatesResult.failureResult | ||
const { ownerId, repoId, workflowId } = coordinatesResult.result | ||
|
||
if (ownerId && repoId) { | ||
return workflowId | ||
? await githubActivityForWorkflow(appState, ownerId, repoId, workflowId) | ||
: await githubActivityForRepo(appState, ownerId, repoId) | ||
} | ||
if (!ownerId && !repoId) return await githubActivityForHome(appState, event.userId) | ||
return invalidRequestResponse | ||
} | ||
|
||
async function githubActivityForWorkflow( | ||
appState: AppState, | ||
ownerId: number, | ||
repoId: number, | ||
workflowId: number | ||
) { | ||
logger.debug('githubActivityForWorkflow', { ownerId, repoId, workflowId }) | ||
// TODO eventually - make sure user has permission for this | ||
return createWorkflowRunEventTableResponse( | ||
'workflowActivity', | ||
appState.clock, | ||
await getRunEventsForWorkflow(appState, ownerId, repoId, workflowId) | ||
) | ||
} | ||
|
||
async function githubActivityForRepo(appState: AppState, ownerId: number, repoId: number) { | ||
logger.debug('githubActivityForRepo') | ||
if (!(await getRepository(appState, ownerId, repoId))) return notFoundHTMLResponse | ||
|
||
// TODO eventually - make sure user has permission for this | ||
// TODO eventually - move repo check into domain logic | ||
return createGithubActivityResponse( | ||
'repoActivity', | ||
appState.clock, | ||
await getRecentActivityForRepo(appState, ownerId, repoId) | ||
) | ||
} | ||
|
||
async function githubActivityForHome(appState: AppState, userId: number) { | ||
logger.debug('githubActivityForHome') | ||
return createGithubPushTableResponse( | ||
'homeActivity', | ||
appState.clock, | ||
await recentActiveBranchesForOwners(appState, await getAllAccountIdsForUser(appState, userId)) | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
src/app/web/fragments/requestParsing/getOptionalRepoCoordinates.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { CicadaAuthorizedAPIEvent } from '../../../inboundInterfaces/lambdaTypes' | ||
import { failedWithResult, isFailure, Result, successWith } from '../../../util/structuredResult' | ||
import { APIGatewayProxyResult } from 'aws-lambda/trigger/api-gateway-proxy' | ||
import { logger } from '../../../util/logging' | ||
import { invalidRequestResponse } from '../../htmlResponses' | ||
import { validatingQueryStringParser } from '../../../schema/urlPathParser' | ||
import { JTDSchemaType } from 'ajv/dist/jtd' | ||
import { RepoCoordinatesQueryStringParameters, repoCoordinatesSchema } from './getRepoCoordinates' | ||
|
||
export function getOptionalRepoCoordinates( | ||
event: CicadaAuthorizedAPIEvent | ||
): Result<{ ownerId?: number; repoId?: number }, APIGatewayProxyResult> { | ||
const parseResult = parser(event.queryStringParameters ?? {}) | ||
if (isFailure(parseResult)) { | ||
logger.warn('Invalid request in getOptionalRepoCoordinates', { reason: parseResult.reason }) | ||
return failedWithResult('Failed to parse', invalidRequestResponse) | ||
} | ||
|
||
// TODO - can we just define the schema with ints? | ||
const { ownerId, repoId } = parseResult.result | ||
return successWith({ | ||
...(ownerId ? { ownerId: parseInt(ownerId) } : {}), | ||
...(repoId ? { repoId: parseInt(repoId) } : {}) | ||
}) | ||
} | ||
|
||
export type OptionalRepoCoordinatesQueryStringParameters = Partial<RepoCoordinatesQueryStringParameters> | ||
|
||
export const optionalRepoCoordinatesSchema: JTDSchemaType<OptionalRepoCoordinatesQueryStringParameters> = { | ||
optionalProperties: repoCoordinatesSchema.properties | ||
} | ||
|
||
const parser = validatingQueryStringParser(optionalRepoCoordinatesSchema) |
36 changes: 36 additions & 0 deletions
36
src/app/web/fragments/requestParsing/getOptionalWorkflowCoordinates.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { CicadaAuthorizedAPIEvent } from '../../../inboundInterfaces/lambdaTypes' | ||
import { JTDSchemaType } from 'ajv/dist/jtd' | ||
import { validatingQueryStringParser } from '../../../schema/urlPathParser' | ||
import { failedWithResult, isFailure, Result, successWith } from '../../../util/structuredResult' | ||
import { logger } from '../../../util/logging' | ||
import { APIGatewayProxyResult } from 'aws-lambda/trigger/api-gateway-proxy' | ||
import { invalidRequestResponse } from '../../htmlResponses' | ||
import { WorkflowCoordinatesQueryStringParameters, workflowCoordinatesSchema } from './getWorkflowCoordinates' | ||
|
||
export function getOptionalWorkflowCoordinates( | ||
event: CicadaAuthorizedAPIEvent | ||
): Result<{ ownerId?: number; repoId?: number; workflowId?: number }, APIGatewayProxyResult> { | ||
const parseResult = parser(event.queryStringParameters ?? {}) | ||
if (isFailure(parseResult)) { | ||
logger.warn('Invalid request in getOptionalWorkflowCoordinates', { reason: parseResult.reason }) | ||
return failedWithResult('Failed to parse', invalidRequestResponse) | ||
} | ||
|
||
// TODO - can we just define the schema with ints? | ||
const { ownerId, repoId, workflowId } = parseResult.result | ||
return successWith({ | ||
...(ownerId ? { ownerId: parseInt(ownerId) } : {}), | ||
...(repoId ? { repoId: parseInt(repoId) } : {}), | ||
...(workflowId ? { workflowId: parseInt(workflowId) } : {}) | ||
}) | ||
} | ||
|
||
export type OptionalWorkflowCoordinatesQueryStringParameters = | ||
Partial<WorkflowCoordinatesQueryStringParameters> | ||
|
||
export const optionalWorkflowCoordinatesSchema: JTDSchemaType<OptionalWorkflowCoordinatesQueryStringParameters> = | ||
{ | ||
optionalProperties: workflowCoordinatesSchema.properties | ||
} | ||
|
||
const parser = validatingQueryStringParser(optionalWorkflowCoordinatesSchema) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.