refactor: avoid using env variables in action
Signed-off-by: @pawelmitka <pawel.mitka@brainly.com>
This commit is contained in:
+9
-17
@@ -39,7 +39,7 @@ describe('github:repository:webhook:create', () => {
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repo&owner=owner',
|
||||
webhookUrl: 'https://example.com/payload',
|
||||
webhookSecretEnv: 'SUPER_SECRET',
|
||||
webhookSecret: 'aafdfdivierernfdk23f',
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
@@ -90,20 +90,12 @@ describe('github:repository:webhook:create', () => {
|
||||
).rejects.toThrow(/No token available for host/);
|
||||
});
|
||||
|
||||
it('should throw if environment variable in secret is invalid', async () => {
|
||||
await expect(action.handler(mockContext)).rejects.toThrow(
|
||||
/Environment variable: SUPER_SECRET does not exist./,
|
||||
);
|
||||
});
|
||||
|
||||
it('should call the githubApi for creating repository Webhook', async () => {
|
||||
const repoUrl = 'github.com?repo=repo&owner=owner';
|
||||
const webhookUrl = 'https://example.com/payload';
|
||||
const webhookSecretEnv = 'SUPER_SECRET';
|
||||
const secret = 'aafdfdivierernfdk23f';
|
||||
process.env[webhookSecretEnv] = secret;
|
||||
const webhookSecret = 'aafdfdivierernfdk23f';
|
||||
const ctx = Object.assign({}, mockContext, {
|
||||
input: { repoUrl, webhookUrl, webhookSecretEnv },
|
||||
input: { repoUrl, webhookUrl, webhookSecret },
|
||||
});
|
||||
await action.handler(ctx);
|
||||
|
||||
@@ -115,7 +107,7 @@ describe('github:repository:webhook:create', () => {
|
||||
config: {
|
||||
url: webhookUrl,
|
||||
content_type: 'form',
|
||||
secret,
|
||||
secret: webhookSecret,
|
||||
insecure_ssl: '0',
|
||||
},
|
||||
});
|
||||
@@ -136,7 +128,7 @@ describe('github:repository:webhook:create', () => {
|
||||
config: {
|
||||
url: webhookUrl,
|
||||
content_type: 'form',
|
||||
secret,
|
||||
secret: webhookSecret,
|
||||
insecure_ssl: '0',
|
||||
},
|
||||
});
|
||||
@@ -157,7 +149,7 @@ describe('github:repository:webhook:create', () => {
|
||||
config: {
|
||||
url: webhookUrl,
|
||||
content_type: 'json',
|
||||
secret,
|
||||
secret: webhookSecret,
|
||||
insecure_ssl: '0',
|
||||
},
|
||||
});
|
||||
@@ -178,7 +170,7 @@ describe('github:repository:webhook:create', () => {
|
||||
config: {
|
||||
url: webhookUrl,
|
||||
content_type: 'form',
|
||||
secret,
|
||||
secret: webhookSecret,
|
||||
insecure_ssl: '1',
|
||||
},
|
||||
});
|
||||
@@ -199,7 +191,7 @@ describe('github:repository:webhook:create', () => {
|
||||
config: {
|
||||
url: webhookUrl,
|
||||
content_type: 'form',
|
||||
secret,
|
||||
secret: webhookSecret,
|
||||
insecure_ssl: '1',
|
||||
},
|
||||
});
|
||||
@@ -220,7 +212,7 @@ describe('github:repository:webhook:create', () => {
|
||||
config: {
|
||||
url: webhookUrl,
|
||||
content_type: 'form',
|
||||
secret,
|
||||
secret: webhookSecret,
|
||||
insecure_ssl: '0',
|
||||
},
|
||||
});
|
||||
|
||||
+6
-16
@@ -39,7 +39,7 @@ export function createGithubCreateRepositoryWebhookAction(options: {
|
||||
return createTemplateAction<{
|
||||
repoUrl: string;
|
||||
webhookUrl: string;
|
||||
webhookSecretEnv?: string;
|
||||
webhookSecret?: string;
|
||||
events?: string[];
|
||||
active?: boolean;
|
||||
contentType?: ContentType;
|
||||
@@ -62,9 +62,9 @@ export function createGithubCreateRepositoryWebhookAction(options: {
|
||||
description: 'The URL to which the payloads will be delivered',
|
||||
type: 'string',
|
||||
},
|
||||
webhookSecretEnv: {
|
||||
title: 'Environment variable containing Webhook Secret',
|
||||
description: 'Name of the environment variable containing secret',
|
||||
webhookSecret: {
|
||||
title: 'Webhook Secret',
|
||||
description: 'Webhook secret value',
|
||||
type: 'string',
|
||||
},
|
||||
events: {
|
||||
@@ -99,7 +99,7 @@ export function createGithubCreateRepositoryWebhookAction(options: {
|
||||
const {
|
||||
repoUrl,
|
||||
webhookUrl,
|
||||
webhookSecretEnv,
|
||||
webhookSecret,
|
||||
events = ['push'],
|
||||
active = true,
|
||||
contentType = 'form',
|
||||
@@ -112,16 +112,6 @@ export function createGithubCreateRepositoryWebhookAction(options: {
|
||||
throw new InputError(`No owner provided for repo ${repoUrl}`);
|
||||
}
|
||||
|
||||
let secret;
|
||||
if (webhookSecretEnv) {
|
||||
secret = process.env[webhookSecretEnv];
|
||||
if (!secret) {
|
||||
throw new InputError(
|
||||
`Environment variable: ${webhookSecretEnv} does not exist.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ctx.logger.info(`Creating webhook ${webhookUrl} for repo ${repoUrl}`);
|
||||
|
||||
const credentialsProvider = credentialsProviders.get(host);
|
||||
@@ -159,7 +149,7 @@ export function createGithubCreateRepositoryWebhookAction(options: {
|
||||
config: {
|
||||
url: webhookUrl,
|
||||
content_type: contentType,
|
||||
secret,
|
||||
secret: webhookSecret,
|
||||
insecure_ssl,
|
||||
},
|
||||
events,
|
||||
|
||||
Reference in New Issue
Block a user