Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/runners lambdas add env to filter #10

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ describe('handler', () => {

it('gets the current org level runners', async () => {
await handle('aws:sqs', TEST_DATA);
expect(listRunners).toBeCalledWith({ repoName: undefined });
expect(listRunners).toBeCalledWith({
environment: 'unit-test-environment',
repoName: undefined,
});
});

it('does not create a token when maximum runners has been reached', async () => {
Expand Down Expand Up @@ -126,7 +129,10 @@ describe('handler', () => {

it('gets the current repo level runners', async () => {
await handle('aws:sqs', TEST_DATA);
expect(listRunners).toBeCalledWith({ repoName: `${TEST_DATA.repositoryOwner}/${TEST_DATA.repositoryName}` });
expect(listRunners).toBeCalledWith({
environment: 'unit-test-environment',
repoName: `${TEST_DATA.repositoryOwner}/${TEST_DATA.repositoryName}`,
});
});

it('does not create a token when maximum runners has been reached', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const handle = async (eventSource: string, payload: ActionRequestMessage)

if (queuedWorkflows.data.total_count > 0) {
const currentRunners = await listRunners({
environment: environment,
repoName: enableOrgLevel ? undefined : `${payload.repositoryOwner}/${payload.repositoryName}`,
});
console.info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface RunnerInfo {
export interface ListRunnerFilters {
repoName?: string;
orgName?: string;
environment?: string;
}

export async function listRunners(filters: ListRunnerFilters | undefined = undefined): Promise<RunnerInfo[]> {
Expand All @@ -19,6 +20,9 @@ export async function listRunners(filters: ListRunnerFilters | undefined = undef
{ Name: 'instance-state-name', Values: ['running', 'pending'] },
];
if (filters) {
if (filters.environment !== undefined) {
ec2Filters.push({ Name: 'tag:Environment', Values: [filters.environment] });
}
if (filters.repoName !== undefined) {
ec2Filters.push({ Name: 'tag:Repo', Values: [filters.repoName] });
}
Expand Down