Skip to content

Commit 55ccf5d

Browse files
committed
code cleanup
1 parent 0c342d6 commit 55ccf5d

File tree

8 files changed

+18
-30
lines changed

8 files changed

+18
-30
lines changed

lambdas/functions/webhook/src/ConfigLoader.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,11 @@ export class ConfigWebhookEventBridge extends BaseConfig {
125125
export class ConfigDispatcher extends BaseConfig {
126126
repositoryAllowList: string[] = [];
127127
matcherConfig: RunnerMatcherConfig[] = [];
128-
workflowJobEventSecondaryQueue: string = ''; // Deprecated, not loaded
128+
workflowJobEventSecondaryQueue: string = ''; // Deprecated
129129

130130
async loadConfig(): Promise<void> {
131131
this.loadEnvVar(process.env.REPOSITORY_ALLOW_LIST, 'repositoryAllowList', []);
132+
this.loadEnvVar(process.env.SQS_WORKFLOW_JOB_QUEUE, 'workflowJobEventSecondaryQueue', '');
132133
await this.loadParameter(process.env.PARAMETER_RUNNER_MATCHER_CONFIG_PATH, 'matcherConfig');
133134

134135
validateRunnerMatcherConfig(this);

lambdas/functions/webhook/src/eventbridge/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ beforeEach(() => {
1414
nock.disableNetConnect();
1515
});
1616

17-
describe('Test publish', () => {
17+
describe('Test EventBridge adapter', () => {
1818
test('Test publish without errors', async () => {
1919
// Arrange
2020
const output: PutEventsCommandOutput = {

lambdas/functions/webhook/src/lambda.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { mocked } from 'jest-mock';
44
import { WorkflowJobEvent } from '@octokit/webhooks-types';
55

66
import { dispatchToRunners, eventBridgeWebhook, directWebhook } from './lambda';
7-
import { handle, publishOnEventBridge } from './webhook';
7+
import { publishForRunners, publishOnEventBridge } from './webhook';
88
import ValidationError from './ValidationError';
99
import { getParameter } from '@aws-github-runner/aws-ssm-util';
1010
import { dispatch } from './runners/dispatch';
@@ -91,7 +91,7 @@ describe('Test webhook lambda wrapper.', () => {
9191

9292
describe('Test webhook lambda wrapper.', () => {
9393
it('Happy flow, resolve.', async () => {
94-
const mock = mocked(handle);
94+
const mock = mocked(publishForRunners);
9595
mock.mockImplementation(() => {
9696
return new Promise((resolve) => {
9797
resolve({ body: 'test', statusCode: 200 });
@@ -103,15 +103,15 @@ describe('Test webhook lambda wrapper.', () => {
103103
});
104104

105105
it('An expected error, resolve.', async () => {
106-
const mock = mocked(handle);
106+
const mock = mocked(publishForRunners);
107107
mock.mockRejectedValue(new ValidationError(400, 'some error'));
108108

109109
const result = await directWebhook(event, context);
110110
expect(result).toMatchObject({ body: 'some error', statusCode: 400 });
111111
});
112112

113113
it('Errors are not thrown.', async () => {
114-
const mock = mocked(handle);
114+
const mock = mocked(publishForRunners);
115115
const logSpy = jest.spyOn(logger, 'error');
116116
mock.mockRejectedValue(new Error('some error'));
117117
const result = await directWebhook(event, context);

lambdas/functions/webhook/src/lambda.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import middy from '@middy/core';
22
import { logger, setContext, captureLambdaHandler, tracer } from '@aws-github-runner/aws-powertools-util';
33
import { APIGatewayEvent, Context } from 'aws-lambda';
44

5-
import { handle, publishOnEventBridge } from './webhook';
5+
import { publishForRunners, publishOnEventBridge } from './webhook';
66
import { IncomingHttpHeaders } from 'http';
77
import ValidationError from './ValidationError';
88
import { EventWrapper } from './types';
@@ -24,7 +24,7 @@ export async function directWebhook(event: APIGatewayEvent, context: Context): P
2424
let result: Response;
2525
try {
2626
const config: ConfigWebhook = await ConfigWebhook.load();
27-
result = await handle(headersToLowerCase(event.headers), event.body as string, config);
27+
result = await publishForRunners(headersToLowerCase(event.headers), event.body as string, config);
2828
} catch (e) {
2929
logger.error(`Failed to handle webhook event`, { error: e });
3030
if (e instanceof ValidationError) {

lambdas/functions/webhook/src/local.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import bodyParser from 'body-parser';
22
import express from 'express';
33

4-
import { handle } from './webhook';
4+
import { publishForRunners } from './webhook';
55
import { ConfigWebhook } from './ConfigLoader';
66

77
const app = express();
@@ -10,7 +10,7 @@ app.use(bodyParser.json());
1010

1111
app.post('/event_handler', async (req, res) => {
1212
const config: ConfigWebhook = await ConfigWebhook.load();
13-
handle(req.headers, JSON.stringify(req.body), config)
13+
publishForRunners(req.headers, JSON.stringify(req.body), config)
1414
.then((c) => res.status(c.statusCode).end())
1515
.catch((e) => {
1616
console.log(e);

lambdas/functions/webhook/src/webhook/index.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import nock from 'nock';
55

66
import workFlowJobEvent from '../../test/resources/github_workflowjob_event.json';
77

8-
import { checkBodySize, handle, publishOnEventBridge } from '.';
8+
import { checkBodySize, publishForRunners, publishOnEventBridge } from '.';
99
import { dispatch } from '../runners/dispatch';
1010
import { IncomingHttpHeaders } from 'http';
1111
import { ConfigWebhook, ConfigWebhookEventBridge } from '../ConfigLoader';
@@ -43,7 +43,7 @@ describe('handle GitHub webhook events', () => {
4343
});
4444

4545
it('should return 500 if no signature available', async () => {
46-
await expect(handle({}, '', config)).rejects.toMatchObject({
46+
await expect(publishForRunners({}, '', config)).rejects.toMatchObject({
4747
statusCode: 500,
4848
});
4949
});
@@ -57,7 +57,7 @@ describe('handle GitHub webhook events', () => {
5757
const event = JSON.stringify(workFlowJobEvent);
5858

5959
// act and assert
60-
const result = handle(
60+
const result = publishForRunners(
6161
{
6262
'X-Hub-Signature-256': await webhooks.sign(event),
6363
'X-GitHub-Event': 'workflow_job',
@@ -76,7 +76,7 @@ describe('handle GitHub webhook events', () => {
7676
const other = JSON.stringify({ ...workFlowJobEvent, action: 'mutated' });
7777

7878
await expect(
79-
handle({ 'X-Hub-Signature-256': await webhooks.sign(other), 'X-GitHub-Event': 'workflow_job' }, event, config),
79+
publishForRunners({ 'X-Hub-Signature-256': await webhooks.sign(other), 'X-GitHub-Event': 'workflow_job' }, event, config),
8080
).rejects.toMatchObject({
8181
statusCode: 401,
8282
});
@@ -86,7 +86,7 @@ describe('handle GitHub webhook events', () => {
8686
const event = JSON.stringify(workFlowJobEvent);
8787

8888
await expect(
89-
handle({ 'X-Hub-Signature-256': await webhooks.sign(event), 'X-GitHub-Event': 'invalid' }, event, config),
89+
publishForRunners({ 'X-Hub-Signature-256': await webhooks.sign(event), 'X-GitHub-Event': 'invalid' }, event, config),
9090
).rejects.toMatchObject({
9191
statusCode: 202,
9292
});
@@ -100,7 +100,7 @@ describe('handle GitHub webhook events', () => {
100100
});
101101

102102
await expect(
103-
handle({ 'X-Hub-Signature-256': await webhooks.sign(event), 'X-GitHub-Event': 'workflow_job' }, event, config),
103+
publishForRunners({ 'X-Hub-Signature-256': await webhooks.sign(event), 'X-GitHub-Event': 'workflow_job' }, event, config),
104104
).resolves.toMatchObject({
105105
statusCode: 201,
106106
});

lambdas/functions/webhook/src/webhook/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { publish } from '../eventbridge';
1010
import { ConfigWebhook, ConfigWebhookEventBridge } from '../ConfigLoader';
1111
const logger = createChildLogger('handler');
1212

13-
export async function handle(headers: IncomingHttpHeaders, body: string, config: ConfigWebhook): Promise<Response> {
13+
export async function publishForRunners(headers: IncomingHttpHeaders, body: string, config: ConfigWebhook): Promise<Response> {
1414
init(headers);
1515

1616
await verifySignature(headers, body, config.webhookSecret);

lambdas/functions/webhook/src/webhook/modules.d.ts

-13
This file was deleted.

0 commit comments

Comments
 (0)