|
1 | 1 | import { createAppAuth } from '@octokit/auth-app'; |
2 | 2 | import { Octokit } from '@octokit/rest'; |
3 | 3 | import { AppAuth } from '@octokit/auth-app/dist-types/types'; |
4 | | -import { listRunners } from './runners'; |
| 4 | +import { listRunners, createRunner } from './runners'; |
5 | 5 | import yn from 'yn'; |
6 | 6 |
|
7 | 7 | export interface ActionRequestMessage { |
@@ -34,8 +34,9 @@ async function createInstallationClient(githubAppAuth: AppAuth): Promise<Octokit |
34 | 34 |
|
35 | 35 | export const handle = async (eventSource: string, payload: ActionRequestMessage): Promise<void> => { |
36 | 36 | if (eventSource !== 'aws:sqs') throw Error('Cannot handle non-SQS events!'); |
37 | | - const enableOrgLevel = yn(process.env.ENABLE_ORGANIZATION_RUNNERS); |
| 37 | + const enableOrgLevel = yn(process.env.ENABLE_ORGANIZATION_RUNNERS, { default: true }); |
38 | 38 | const maximumRunners = parseInt(process.env.RUNNERS_MAXIMUM_COUNT || '3'); |
| 39 | + const environment = process.env.ENVIRONMENT as string; |
39 | 40 | const githubAppAuth = createGithubAppAuth(payload.installationId); |
40 | 41 | const githubInstallationClient = await createInstallationClient(githubAppAuth); |
41 | 42 | const queuedWorkflows = await githubInstallationClient.actions.listRepoWorkflowRuns({ |
@@ -70,7 +71,17 @@ export const handle = async (eventSource: string, payload: ActionRequestMessage) |
70 | 71 | repo: payload.repositoryName, |
71 | 72 | }); |
72 | 73 | const token = registrationToken.data.token; |
73 | | - // create runner |
| 74 | + |
| 75 | + await createRunner({ |
| 76 | + environment: environment, |
| 77 | + runnerConfig: enableOrgLevel |
| 78 | + ? `--url https://github.com/${payload.repositoryOwner} --token ${token}` |
| 79 | + : `--url https://github.com/${payload.repositoryOwner}/${payload.repositoryName} --token ${token}`, |
| 80 | + orgName: enableOrgLevel ? payload.repositoryOwner : undefined, |
| 81 | + repoName: enableOrgLevel ? undefined : `${payload.repositoryOwner}/${payload.repositoryName}`, |
| 82 | + }); |
| 83 | + } else { |
| 84 | + console.info('No runner will be created, maximum number of runners reached.'); |
74 | 85 | } |
75 | 86 | } |
76 | 87 | }; |
0 commit comments