@@ -38,9 +38,11 @@
|
||||
"dependencies": {
|
||||
"@backstage/backend-common": "workspace:^",
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/plugin-scaffolder-common": "workspace:^",
|
||||
"@backstage/plugin-scaffolder-node": "workspace:^",
|
||||
"@backstage/test-utils": "workspace:^",
|
||||
"@backstage/types": "workspace:^"
|
||||
"@backstage/types": "workspace:^",
|
||||
"winston": "^3.2.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/jest": "*"
|
||||
|
||||
@@ -20,32 +20,50 @@ import { createMockDirectory } from '@backstage/backend-test-utils';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { ActionContext } from '@backstage/plugin-scaffolder-node';
|
||||
import * as winston from 'winston';
|
||||
import { TemplateInfo } from '@backstage/plugin-scaffolder-common';
|
||||
|
||||
/**
|
||||
* A utility method to create a mock action context for scaffolder actions.
|
||||
*
|
||||
* @param input - a schema for user input parameters
|
||||
*
|
||||
* @param workspacePath
|
||||
* @param logger
|
||||
*
|
||||
* @public
|
||||
* @param options
|
||||
*/
|
||||
export const createMockActionContext = <
|
||||
TActionInput extends JsonObject = JsonObject,
|
||||
TActionOutput extends JsonObject = JsonObject,
|
||||
>(
|
||||
input?: TActionInput,
|
||||
workspacePath?: string,
|
||||
logger?: winston.Logger,
|
||||
): ActionContext<TActionInput, TActionOutput> => {
|
||||
return {
|
||||
workspacePath: workspacePath
|
||||
? workspacePath
|
||||
: createMockDirectory().resolve('workspace'),
|
||||
logger: logger ? logger : getVoidLogger(),
|
||||
>(options?: {
|
||||
input?: TActionInput;
|
||||
workspacePath?: string;
|
||||
logger?: winston.Logger;
|
||||
templateInfo?: TemplateInfo;
|
||||
}): ActionContext<TActionInput, TActionOutput> => {
|
||||
const defaultContext = {
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
input: (input ? input : {}) as TActionInput,
|
||||
input: {} as TActionInput,
|
||||
};
|
||||
|
||||
const createDefaultWorkspace = () => ({
|
||||
workspacePath: createMockDirectory().resolve('workspace'),
|
||||
});
|
||||
|
||||
if (!options) {
|
||||
return {
|
||||
...defaultContext,
|
||||
...createDefaultWorkspace(),
|
||||
};
|
||||
}
|
||||
|
||||
const { input, workspacePath, logger, templateInfo } = options;
|
||||
return {
|
||||
...defaultContext,
|
||||
...(workspacePath ? { workspacePath } : createDefaultWorkspace()),
|
||||
...(logger && { logger }),
|
||||
...(input && { input }),
|
||||
templateInfo,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -55,7 +55,7 @@ describe('publish:azure', () => {
|
||||
const action = createPublishAzureAction({ integrations, config });
|
||||
|
||||
const mockContext = createMockActionContext({
|
||||
repoUrl: 'dev.azure.com?repo=repo&owner=owner&organization=org',
|
||||
input: { repoUrl: 'dev.azure.com?repo=repo&owner=owner&organization=org' },
|
||||
});
|
||||
|
||||
const mockGitClient = {
|
||||
|
||||
+4
-2
@@ -50,8 +50,10 @@ describe('publish:bitbucketCloud', () => {
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
const action = createPublishBitbucketCloudAction({ integrations, config });
|
||||
const mockContext = createMockActionContext({
|
||||
repoUrl: 'bitbucket.org?workspace=workspace&project=project&repo=repo',
|
||||
repoVisibility: 'private' as const,
|
||||
input: {
|
||||
repoUrl: 'bitbucket.org?workspace=workspace&project=project&repo=repo',
|
||||
repoVisibility: 'private' as const,
|
||||
},
|
||||
});
|
||||
const server = setupServer();
|
||||
setupRequestMockHandlers(server);
|
||||
|
||||
+8
-6
@@ -62,12 +62,14 @@ describe('publish:bitbucketServer:pull-request', () => {
|
||||
config,
|
||||
});
|
||||
const mockContext = createMockActionContext({
|
||||
repoUrl: 'hosted.bitbucket.com?project=project&repo=repo',
|
||||
title: 'Add Scaffolder actions for Bitbucket Server',
|
||||
description:
|
||||
'I just made a Pull Request that Add Scaffolder actions for Bitbucket Server',
|
||||
targetBranch: 'master',
|
||||
sourceBranch: 'develop',
|
||||
input: {
|
||||
repoUrl: 'hosted.bitbucket.com?project=project&repo=repo',
|
||||
title: 'Add Scaffolder actions for Bitbucket Server',
|
||||
description:
|
||||
'I just made a Pull Request that Add Scaffolder actions for Bitbucket Server',
|
||||
targetBranch: 'master',
|
||||
sourceBranch: 'develop',
|
||||
},
|
||||
});
|
||||
const responseOfBranches = {
|
||||
size: 3,
|
||||
|
||||
@@ -61,8 +61,10 @@ describe('publish:bitbucket', () => {
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
const action = createPublishBitbucketAction({ integrations, config });
|
||||
const mockContext = createMockActionContext({
|
||||
repoUrl: 'bitbucket.org?workspace=workspace&project=project&repo=repo',
|
||||
repoVisibility: 'private' as const,
|
||||
input: {
|
||||
repoUrl: 'bitbucket.org?workspace=workspace&project=project&repo=repo',
|
||||
repoVisibility: 'private' as const,
|
||||
},
|
||||
});
|
||||
const server = setupServer();
|
||||
setupRequestMockHandlers(server);
|
||||
|
||||
@@ -57,8 +57,10 @@ describe('publish:bitbucket', () => {
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
const action = createPublishBitbucketAction({ integrations, config });
|
||||
const mockContext = createMockActionContext({
|
||||
repoUrl: 'bitbucket.org?workspace=workspace&project=project&repo=repo',
|
||||
repoVisibility: 'private' as const,
|
||||
input: {
|
||||
repoUrl: 'bitbucket.org?workspace=workspace&project=project&repo=repo',
|
||||
repoVisibility: 'private' as const,
|
||||
},
|
||||
});
|
||||
const server = setupServer();
|
||||
setupRequestMockHandlers(server);
|
||||
|
||||
+3
-3
@@ -71,11 +71,11 @@ describe('confluence:transform:markdown examples', () => {
|
||||
}),
|
||||
search: jest.fn(),
|
||||
};
|
||||
mockContext = createMockActionContext(
|
||||
yaml.parse(examples[0].example).steps[0].input,
|
||||
mockContext = createMockActionContext({
|
||||
input: yaml.parse(examples[0].example).steps[0].input,
|
||||
workspacePath,
|
||||
logger,
|
||||
);
|
||||
});
|
||||
|
||||
mockDir.setContent({ 'workspace/mkdocs.yml': 'File contents' });
|
||||
});
|
||||
|
||||
+4
-6
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { PassThrough } from 'stream';
|
||||
|
||||
import { createConfluenceToMarkdownAction } from './confluenceToMarkdown';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { UrlReader } from '@backstage/backend-common';
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
import type { ActionContext } from '@backstage/plugin-scaffolder-node';
|
||||
import { rest } from 'msw';
|
||||
import { setupServer } from 'msw/node';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
|
||||
describe('confluence:transform:markdown', () => {
|
||||
const baseUrl = `https://nodomain.confluence.com`;
|
||||
@@ -69,7 +70,7 @@ describe('confluence:transform:markdown', () => {
|
||||
}),
|
||||
search: jest.fn(),
|
||||
};
|
||||
mockContext = {
|
||||
mockContext = createMockActionContext({
|
||||
input: {
|
||||
confluenceUrls: [
|
||||
'https://nodomain.confluence.com/display/testing/mkdocs',
|
||||
@@ -79,10 +80,7 @@ describe('confluence:transform:markdown', () => {
|
||||
},
|
||||
workspacePath,
|
||||
logger,
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
mockDir.setContent({ 'workspace/mkdocs.yml': 'File contents' });
|
||||
});
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
"devDependencies": {
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@backstage/scaffolder-test-utils": "workspace:^",
|
||||
"@types/command-exists": "^1.2.0",
|
||||
"@types/fs-extra": "^11.0.0"
|
||||
},
|
||||
|
||||
+4
-17
@@ -14,19 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
getVoidLogger,
|
||||
UrlReader,
|
||||
ContainerRunner,
|
||||
} from '@backstage/backend-common';
|
||||
import { UrlReader, ContainerRunner } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { createMockDirectory } from '@backstage/backend-test-utils';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createFetchCookiecutterAction } from './cookiecutter';
|
||||
import { join } from 'path';
|
||||
import type { ActionContext } from '@backstage/plugin-scaffolder-node';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
|
||||
const executeShellCommand = jest.fn();
|
||||
const commandExists = jest.fn();
|
||||
@@ -88,7 +84,7 @@ describe('fetch:cookiecutter', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
|
||||
mockContext = {
|
||||
mockContext = createMockActionContext({
|
||||
input: {
|
||||
url: 'https://google.com/cookie/cutter',
|
||||
targetPath: 'something',
|
||||
@@ -96,16 +92,7 @@ describe('fetch:cookiecutter', () => {
|
||||
help: 'me',
|
||||
},
|
||||
},
|
||||
templateInfo: {
|
||||
entityRef: 'template:default/cookiecutter',
|
||||
baseUrl: 'somebase',
|
||||
},
|
||||
workspacePath: mockTmpDir,
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn().mockResolvedValue(mockTmpDir),
|
||||
};
|
||||
});
|
||||
mockDir.setContent({ template: {} });
|
||||
|
||||
commandExists.mockResolvedValue(null);
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
"@backstage/backend-common": "workspace:^",
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@backstage/scaffolder-test-utils": "workspace:^",
|
||||
"msw": "^1.0.0"
|
||||
},
|
||||
"files": [
|
||||
|
||||
@@ -33,9 +33,8 @@ import { setupServer } from 'msw/node';
|
||||
import { setupRequestMockHandlers } from '@backstage/backend-test-utils';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { PassThrough } from 'stream';
|
||||
import { initRepoAndPush } from '@backstage/plugin-scaffolder-node';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
|
||||
describe('publish:gerrit', () => {
|
||||
const config = new ConfigReader({
|
||||
@@ -53,18 +52,13 @@ describe('publish:gerrit', () => {
|
||||
const description = 'for the lols';
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
const action = createPublishGerritAction({ integrations, config });
|
||||
const mockContext = {
|
||||
const mockContext = createMockActionContext({
|
||||
input: {
|
||||
repoUrl:
|
||||
'gerrithost.org?owner=owner&workspace=parent&project=project&repo=repo',
|
||||
description,
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
});
|
||||
const server = setupServer();
|
||||
setupRequestMockHandlers(server);
|
||||
|
||||
|
||||
@@ -24,9 +24,8 @@ jest.mock('@backstage/plugin-scaffolder-node', () => {
|
||||
import { createPublishGerritReviewAction } from './gerritReview';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { PassThrough } from 'stream';
|
||||
import { commitAndPushRepo } from '@backstage/plugin-scaffolder-node';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
|
||||
describe('publish:gerrit:review', () => {
|
||||
const config = new ConfigReader({
|
||||
@@ -43,18 +42,13 @@ describe('publish:gerrit:review', () => {
|
||||
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
const action = createPublishGerritReviewAction({ integrations, config });
|
||||
const mockContext = {
|
||||
const mockContext = createMockActionContext({
|
||||
input: {
|
||||
repoUrl:
|
||||
'gerrithost.org?owner=owner&workspace=parent&project=project&repo=repo',
|
||||
gitCommitMessage: 'Review from backstage',
|
||||
},
|
||||
workspacePath: 'workspace',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
"@backstage/backend-common": "workspace:^",
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@backstage/scaffolder-test-utils": "workspace:^",
|
||||
"msw": "^1.0.0"
|
||||
},
|
||||
"files": [
|
||||
|
||||
@@ -13,14 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { PassThrough } from 'stream';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { createPublishGiteaAction } from './gitea';
|
||||
import { initRepoAndPush } from '@backstage/plugin-scaffolder-node';
|
||||
import { rest } from 'msw';
|
||||
import { setupRequestMockHandlers } from '@backstage/backend-test-utils';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import { setupServer } from 'msw/node';
|
||||
|
||||
jest.mock('@backstage/plugin-scaffolder-node', () => {
|
||||
@@ -48,17 +47,12 @@ describe('publish:gitea', () => {
|
||||
const description = 'for the lols';
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
const action = createPublishGiteaAction({ integrations, config });
|
||||
const mockContext = {
|
||||
const mockContext = createMockActionContext({
|
||||
input: {
|
||||
repoUrl: 'gitea.com?repo=repo&owner=owner',
|
||||
description,
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
const server = setupServer();
|
||||
setupRequestMockHandlers(server);
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
"devDependencies": {
|
||||
"@backstage/backend-test-utils": "workspace:^",
|
||||
"@backstage/cli": "workspace:^",
|
||||
"@backstage/scaffolder-test-utils": "workspace:^",
|
||||
"@types/libsodium-wrappers": "^0.7.10",
|
||||
"fs-extra": "^11.2.0",
|
||||
"jest-when": "^3.1.0",
|
||||
|
||||
@@ -36,14 +36,13 @@ import {
|
||||
TemplateAction,
|
||||
initRepoAndPush,
|
||||
} from '@backstage/plugin-scaffolder-node';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import {
|
||||
DefaultGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createPublishGithubAction } from './github';
|
||||
import { examples } from './github.examples';
|
||||
import yaml from 'yaml';
|
||||
@@ -101,19 +100,14 @@ describe('publish:github', () => {
|
||||
let githubCredentialsProvider: GithubCredentialsProvider;
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
const mockContext = createMockActionContext({
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repo&owner=owner',
|
||||
description: 'description',
|
||||
repoVisibility: 'private' as const,
|
||||
access: 'owner/blam',
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
initRepoAndPushMocked.mockResolvedValue({
|
||||
|
||||
@@ -34,15 +34,14 @@ jest.mock('@backstage/plugin-scaffolder-node', () => {
|
||||
});
|
||||
|
||||
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import {
|
||||
DefaultGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { when } from 'jest-when';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createPublishGithubAction } from './github';
|
||||
import { initRepoAndPush } from '@backstage/plugin-scaffolder-node';
|
||||
import {
|
||||
@@ -103,19 +102,14 @@ describe('publish:github', () => {
|
||||
let githubCredentialsProvider: GithubCredentialsProvider;
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
const mockContext = createMockActionContext({
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repo&owner=owner',
|
||||
description: 'description',
|
||||
repoVisibility: 'private' as const,
|
||||
access: 'owner/blam',
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
initRepoAndPushMocked.mockResolvedValue({
|
||||
|
||||
+3
-9
@@ -20,10 +20,9 @@ import {
|
||||
GithubCredentialsProvider,
|
||||
} from '@backstage/integration';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createGithubActionsDispatchAction } from './githubActionsDispatch';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import yaml from 'yaml';
|
||||
import { examples } from './githubActionsDispatch.examples';
|
||||
|
||||
@@ -56,18 +55,13 @@ describe('github:actions:dispatch', () => {
|
||||
let githubCredentialsProvider: GithubCredentialsProvider;
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
const mockContext = createMockActionContext({
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repo&owner=owner',
|
||||
workflowId: 'a-workflow-id',
|
||||
branchOrTagName: 'main',
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
|
||||
@@ -20,9 +20,8 @@ import {
|
||||
GithubCredentialsProvider,
|
||||
} from '@backstage/integration';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import { createGithubActionsDispatchAction } from './githubActionsDispatch';
|
||||
|
||||
const mockOctokit = {
|
||||
@@ -54,18 +53,13 @@ describe('github:actions:dispatch', () => {
|
||||
let githubCredentialsProvider: GithubCredentialsProvider;
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
const mockContext = createMockActionContext({
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repo&owner=owner',
|
||||
workflowId: 'a-workflow-id',
|
||||
branchOrTagName: 'main',
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
|
||||
+6
-10
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
DefaultGithubCredentialsProvider,
|
||||
@@ -22,8 +21,8 @@ import {
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createGithubAutolinksAction } from './githubAutolinks';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import { examples } from './githubAutolinks.examples';
|
||||
import yaml from 'yaml';
|
||||
|
||||
@@ -70,14 +69,11 @@ describe('github:autolinks:create', () => {
|
||||
id: '1',
|
||||
},
|
||||
});
|
||||
await action.handler({
|
||||
input,
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
});
|
||||
await action.handler(
|
||||
createMockActionContext({
|
||||
input,
|
||||
}),
|
||||
);
|
||||
|
||||
expect(mockOctokit.rest.repos.createAutolink).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
|
||||
@@ -14,15 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
DefaultGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { createMockDirectory } from '@backstage/backend-test-utils';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createGithubAutolinksAction } from './githubAutolinks';
|
||||
|
||||
const mockOctokit = {
|
||||
@@ -53,13 +53,7 @@ describe('github:autolinks:create', () => {
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
let githubCredentialsProvider: GithubCredentialsProvider;
|
||||
let action: TemplateAction<any, any>;
|
||||
const mockContext = {
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
const workspacePath = createMockDirectory().resolve('workspace');
|
||||
|
||||
it('should call the githubApis for creating alphanumeric autolink reference', async () => {
|
||||
githubCredentialsProvider =
|
||||
@@ -74,14 +68,16 @@ describe('github:autolinks:create', () => {
|
||||
id: '1',
|
||||
},
|
||||
});
|
||||
await action.handler({
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repo&owner=owner',
|
||||
keyPrefix: 'TICKET-',
|
||||
urlTemplate: 'https://example.com/TICKET?query=<num>',
|
||||
},
|
||||
...mockContext,
|
||||
});
|
||||
await action.handler(
|
||||
createMockActionContext({
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repo&owner=owner',
|
||||
keyPrefix: 'TICKET-',
|
||||
urlTemplate: 'https://example.com/TICKET?query=<num>',
|
||||
},
|
||||
workspacePath,
|
||||
}),
|
||||
);
|
||||
|
||||
expect(mockOctokit.rest.repos.createAutolink).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
@@ -104,15 +100,17 @@ describe('github:autolinks:create', () => {
|
||||
id: '1',
|
||||
},
|
||||
});
|
||||
await action.handler({
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repo&owner=owner',
|
||||
keyPrefix: 'TICKET-',
|
||||
urlTemplate: 'https://example.com/TICKET?query=<num>',
|
||||
isAlphanumeric: false,
|
||||
},
|
||||
...mockContext,
|
||||
});
|
||||
await action.handler(
|
||||
createMockActionContext({
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repo&owner=owner',
|
||||
keyPrefix: 'TICKET-',
|
||||
urlTemplate: 'https://example.com/TICKET?query=<num>',
|
||||
isAlphanumeric: false,
|
||||
},
|
||||
workspacePath,
|
||||
}),
|
||||
);
|
||||
|
||||
expect(mockOctokit.rest.repos.createAutolink).toHaveBeenCalledWith({
|
||||
owner: 'owner',
|
||||
|
||||
+2
-9
@@ -14,11 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import { createGithubDeployKeyAction } from './githubDeployKey';
|
||||
import yaml from 'yaml';
|
||||
import { examples } from './githubDeployKey.examples';
|
||||
import { PassThrough } from 'stream';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
|
||||
@@ -55,13 +54,7 @@ describe('Usage examples', () => {
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
const mockContext = createMockActionContext();
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { PassThrough } from 'stream';
|
||||
import { createGithubDeployKeyAction } from './githubDeployKey';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
|
||||
@@ -55,19 +54,14 @@ describe('github:deployKey:create', () => {
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
const mockContext = createMockActionContext({
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repository&owner=owner',
|
||||
publicKey: 'pubkey',
|
||||
privateKey: 'privkey',
|
||||
deployKeyName: 'Push Tags',
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
|
||||
+2
-9
@@ -13,9 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { PassThrough } from 'stream';
|
||||
import { createGithubEnvironmentAction } from './githubEnvironment';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
@@ -59,13 +58,7 @@ describe('github:environment:create examples', () => {
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
const mockContext = createMockActionContext();
|
||||
|
||||
beforeEach(() => {
|
||||
mockOctokit.rest.actions.getEnvironmentPublicKey.mockResolvedValue({
|
||||
|
||||
@@ -14,9 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { PassThrough } from 'stream';
|
||||
import { createGithubEnvironmentAction } from './githubEnvironment';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
@@ -58,17 +57,12 @@ describe('github:environment:create', () => {
|
||||
const integrations = ScmIntegrations.fromConfig(config);
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
const mockContext = createMockActionContext({
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repository&owner=owner',
|
||||
name: 'envname',
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
mockOctokit.rest.actions.getEnvironmentPublicKey.mockResolvedValue({
|
||||
|
||||
+2
-9
@@ -15,14 +15,13 @@
|
||||
*/
|
||||
|
||||
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
DefaultGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createGithubIssuesLabelAction } from './githubIssuesLabel';
|
||||
import yaml from 'yaml';
|
||||
import { examples } from './githubIssuesLabel.examples';
|
||||
@@ -64,13 +63,7 @@ describe('github:issues:label examples', () => {
|
||||
let githubCredentialsProvider: GithubCredentialsProvider;
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
const mockContext = createMockActionContext();
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
|
||||
@@ -20,10 +20,9 @@ import {
|
||||
DefaultGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
} from '@backstage/integration';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import { PassThrough } from 'stream';
|
||||
import { getOctokitOptions } from './helpers';
|
||||
|
||||
jest.mock('./helpers', () => {
|
||||
@@ -62,18 +61,13 @@ describe('github:issues:label', () => {
|
||||
let githubCredentialsProvider: GithubCredentialsProvider;
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
const mockContext = createMockActionContext({
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repo&owner=owner',
|
||||
number: '1',
|
||||
labels: ['label1', 'label2'],
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
|
||||
+2
-9
@@ -15,14 +15,13 @@
|
||||
*/
|
||||
|
||||
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
DefaultGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import { createPublishGithubPullRequestAction } from './githubPullRequest';
|
||||
import yaml from 'yaml';
|
||||
import { examples } from './githubPullRequest.examples';
|
||||
@@ -57,13 +56,7 @@ describe('publish:github:pull-request examples', () => {
|
||||
let githubCredentialsProvider: GithubCredentialsProvider;
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
const mockContext = createMockActionContext();
|
||||
let fakeClient: {
|
||||
createPullRequest: jest.Mock;
|
||||
rest: {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createRootLogger, getRootLogger } from '@backstage/backend-common';
|
||||
import { createRootLogger } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
GithubCredentialsProvider,
|
||||
@@ -25,9 +25,9 @@ import {
|
||||
TemplateAction,
|
||||
} from '@backstage/plugin-scaffolder-node';
|
||||
import fs from 'fs-extra';
|
||||
import { Writable } from 'stream';
|
||||
import { createPublishGithubPullRequestAction } from './githubPullRequest';
|
||||
import { createMockDirectory } from '@backstage/backend-test-utils';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
|
||||
// Make sure root logger is initialized ahead of FS mock
|
||||
createRootLogger();
|
||||
@@ -131,14 +131,7 @@ describe('createPublishGithubPullRequestAction', () => {
|
||||
[workspacePath]: { 'file.txt': 'Hello there!' },
|
||||
});
|
||||
|
||||
ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
ctx = createMockActionContext({ input, workspacePath });
|
||||
});
|
||||
|
||||
it('creates a pull request', async () => {
|
||||
@@ -196,14 +189,7 @@ describe('createPublishGithubPullRequestAction', () => {
|
||||
[workspacePath]: { 'file.txt': 'Hello there!' },
|
||||
});
|
||||
|
||||
ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
ctx = createMockActionContext({ input, workspacePath });
|
||||
});
|
||||
|
||||
it('creates a pull request', async () => {
|
||||
@@ -263,14 +249,7 @@ describe('createPublishGithubPullRequestAction', () => {
|
||||
},
|
||||
});
|
||||
|
||||
ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
ctx = createMockActionContext({ input, workspacePath });
|
||||
});
|
||||
|
||||
it('creates a pull request with only relevant files', async () => {
|
||||
@@ -322,14 +301,7 @@ describe('createPublishGithubPullRequestAction', () => {
|
||||
[workspacePath]: { 'file.txt': 'Hello there!' },
|
||||
});
|
||||
|
||||
ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
ctx = createMockActionContext({ input, workspacePath });
|
||||
});
|
||||
it('creates a pull request', async () => {
|
||||
await instance.handler(ctx);
|
||||
@@ -382,14 +354,7 @@ describe('createPublishGithubPullRequestAction', () => {
|
||||
|
||||
mockDir.setContent({ [workspacePath]: {} });
|
||||
|
||||
ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
ctx = createMockActionContext({ input, workspacePath });
|
||||
});
|
||||
|
||||
it('creates a pull request and requests a review from the given reviewers', async () => {
|
||||
@@ -434,14 +399,7 @@ describe('createPublishGithubPullRequestAction', () => {
|
||||
|
||||
mockDir.setContent({ [workspacePath]: {} });
|
||||
|
||||
ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
ctx = createMockActionContext({ input, workspacePath });
|
||||
});
|
||||
|
||||
it('does not call the API endpoint for requesting reviewers', async () => {
|
||||
@@ -470,14 +428,7 @@ describe('createPublishGithubPullRequestAction', () => {
|
||||
},
|
||||
});
|
||||
|
||||
ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
ctx = createMockActionContext({ input, workspacePath });
|
||||
});
|
||||
it('creates a pull request', async () => {
|
||||
await instance.handler(ctx);
|
||||
@@ -526,14 +477,7 @@ describe('createPublishGithubPullRequestAction', () => {
|
||||
},
|
||||
});
|
||||
|
||||
ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
ctx = createMockActionContext({ input, workspacePath });
|
||||
});
|
||||
it('creates a pull request', async () => {
|
||||
await instance.handler(ctx);
|
||||
@@ -592,14 +536,7 @@ describe('createPublishGithubPullRequestAction', () => {
|
||||
},
|
||||
});
|
||||
|
||||
ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
ctx = createMockActionContext({ input, workspacePath });
|
||||
});
|
||||
it('creates a pull request', async () => {
|
||||
await instance.handler(ctx);
|
||||
@@ -653,14 +590,7 @@ describe('createPublishGithubPullRequestAction', () => {
|
||||
[workspacePath]: { 'file.txt': 'Hello there!' },
|
||||
});
|
||||
|
||||
ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
ctx = createMockActionContext({ input, workspacePath });
|
||||
});
|
||||
|
||||
it('creates a pull request', async () => {
|
||||
@@ -705,14 +635,7 @@ describe('createPublishGithubPullRequestAction', () => {
|
||||
[workspacePath]: { 'file.txt': 'Hello there!' },
|
||||
});
|
||||
|
||||
ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
ctx = createMockActionContext({ input, workspacePath });
|
||||
});
|
||||
|
||||
it('creates a pull request', async () => {
|
||||
|
||||
+3
-9
@@ -23,14 +23,13 @@ jest.mock('./gitHelpers', () => {
|
||||
};
|
||||
});
|
||||
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
DefaultGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import { createGithubRepoCreateAction } from './githubRepoCreate';
|
||||
import { entityRefToName } from './gitHelpers';
|
||||
import yaml from 'yaml';
|
||||
@@ -82,16 +81,11 @@ describe('github:repo:create examples', () => {
|
||||
let githubCredentialsProvider: GithubCredentialsProvider;
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
const mockContext = createMockActionContext({
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repo&owner=owner',
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
githubCredentialsProvider =
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
|
||||
jest.mock('./gitHelpers', () => {
|
||||
return {
|
||||
@@ -23,7 +24,6 @@ jest.mock('./gitHelpers', () => {
|
||||
};
|
||||
});
|
||||
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
DefaultGithubCredentialsProvider,
|
||||
@@ -31,7 +31,6 @@ import {
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { when } from 'jest-when';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createGithubRepoCreateAction } from './githubRepoCreate';
|
||||
import { entityRefToName } from './gitHelpers';
|
||||
|
||||
@@ -82,19 +81,14 @@ describe('github:repo:create', () => {
|
||||
let githubCredentialsProvider: GithubCredentialsProvider;
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
const mockContext = createMockActionContext({
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repo&owner=owner',
|
||||
description: 'description',
|
||||
repoVisibility: 'private' as const,
|
||||
access: 'owner/blam',
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
githubCredentialsProvider =
|
||||
|
||||
+2
-9
@@ -29,14 +29,13 @@ import {
|
||||
TemplateAction,
|
||||
initRepoAndPush,
|
||||
} from '@backstage/plugin-scaffolder-node';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
DefaultGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createGithubRepoPushAction } from './githubRepoPush';
|
||||
import { examples } from './githubRepoPush.examples';
|
||||
import yaml from 'yaml';
|
||||
@@ -102,13 +101,7 @@ describe('github:repo:push examples', () => {
|
||||
let githubCredentialsProvider: GithubCredentialsProvider;
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
const mockContext = createMockActionContext();
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
|
||||
@@ -59,14 +59,13 @@ import {
|
||||
TemplateAction,
|
||||
initRepoAndPush,
|
||||
} from '@backstage/plugin-scaffolder-node';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import {
|
||||
DefaultGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { PassThrough } from 'stream';
|
||||
import { enableBranchProtectionOnDefaultRepoBranch } from './gitHelpers';
|
||||
import { createGithubRepoPushAction } from './githubRepoPush';
|
||||
|
||||
@@ -103,19 +102,14 @@ describe('github:repo:push', () => {
|
||||
let githubCredentialsProvider: GithubCredentialsProvider;
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
const mockContext = createMockActionContext({
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repository&owner=owner',
|
||||
description: 'description',
|
||||
repoVisibility: 'private' as const,
|
||||
access: 'owner/blam',
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
|
||||
@@ -14,14 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
DefaultGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { PassThrough } from 'stream';
|
||||
import { createGithubWebhookAction } from './githubWebhook';
|
||||
import yaml from 'yaml';
|
||||
import { examples } from './githubWebhook.examples';
|
||||
@@ -56,13 +55,7 @@ describe('github:webhook examples', () => {
|
||||
let githubCredentialsProvider: GithubCredentialsProvider;
|
||||
let action: TemplateAction<any>;
|
||||
|
||||
const mockContext = {
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
const mockContext = createMockActionContext();
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
|
||||
@@ -20,10 +20,9 @@ import {
|
||||
DefaultGithubCredentialsProvider,
|
||||
GithubCredentialsProvider,
|
||||
} from '@backstage/integration';
|
||||
import { createMockActionContext } from '@backstage/scaffolder-test-utils';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import { PassThrough } from 'stream';
|
||||
|
||||
const mockOctokit = {
|
||||
rest: {
|
||||
@@ -66,17 +65,12 @@ describe('github:repository:webhook:create', () => {
|
||||
});
|
||||
});
|
||||
|
||||
const mockContext = {
|
||||
const mockContext = createMockActionContext({
|
||||
input: {
|
||||
repoUrl: 'github.com?repo=repo&owner=owner',
|
||||
webhookUrl: 'https://example.com/payload',
|
||||
},
|
||||
workspacePath: 'lol',
|
||||
logger: getVoidLogger(),
|
||||
logStream: new PassThrough(),
|
||||
output: jest.fn(),
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
it('should call the githubApi for creating repository Webhook', async () => {
|
||||
const repoUrl = 'github.com?repo=repo&owner=owner';
|
||||
|
||||
@@ -8311,6 +8311,7 @@ __metadata:
|
||||
"@backstage/errors": "workspace:^"
|
||||
"@backstage/integration": "workspace:^"
|
||||
"@backstage/plugin-scaffolder-node": "workspace:^"
|
||||
"@backstage/scaffolder-test-utils": "workspace:^"
|
||||
"@backstage/types": "workspace:^"
|
||||
"@types/command-exists": ^1.2.0
|
||||
"@types/fs-extra": ^11.0.0
|
||||
@@ -8333,6 +8334,7 @@ __metadata:
|
||||
"@backstage/errors": "workspace:^"
|
||||
"@backstage/integration": "workspace:^"
|
||||
"@backstage/plugin-scaffolder-node": "workspace:^"
|
||||
"@backstage/scaffolder-test-utils": "workspace:^"
|
||||
msw: ^1.0.0
|
||||
node-fetch: ^2.6.7
|
||||
yaml: ^2.0.0
|
||||
@@ -8351,6 +8353,7 @@ __metadata:
|
||||
"@backstage/errors": "workspace:^"
|
||||
"@backstage/integration": "workspace:^"
|
||||
"@backstage/plugin-scaffolder-node": "workspace:^"
|
||||
"@backstage/scaffolder-test-utils": "workspace:^"
|
||||
msw: ^1.0.0
|
||||
node-fetch: ^2.6.7
|
||||
yaml: ^2.0.0
|
||||
@@ -8369,6 +8372,7 @@ __metadata:
|
||||
"@backstage/errors": "workspace:^"
|
||||
"@backstage/integration": "workspace:^"
|
||||
"@backstage/plugin-scaffolder-node": "workspace:^"
|
||||
"@backstage/scaffolder-test-utils": "workspace:^"
|
||||
"@octokit/webhooks": ^10.0.0
|
||||
"@types/libsodium-wrappers": ^0.7.10
|
||||
fs-extra: ^11.2.0
|
||||
@@ -9876,6 +9880,7 @@ __metadata:
|
||||
"@backstage/backend-common": "workspace:^"
|
||||
"@backstage/backend-test-utils": "workspace:^"
|
||||
"@backstage/cli": "workspace:^"
|
||||
"@backstage/plugin-scaffolder-common": "workspace:^"
|
||||
"@backstage/plugin-scaffolder-node": "workspace:^"
|
||||
"@backstage/test-utils": "workspace:^"
|
||||
"@backstage/types": "workspace:^"
|
||||
|
||||
Reference in New Issue
Block a user