scaffolder-backend: fix GitHub Pull Request preparer on windows

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-04-13 13:29:46 +02:00
parent 4df36765e5
commit 423a514c3b
3 changed files with 25 additions and 13 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend': patch
---
Fix execution of the GitHub Pull Request publish action on Windows.
@@ -16,6 +16,8 @@
import mockFs from 'mock-fs';
import { Writable } from 'stream';
import os from 'os';
import { resolve as resolvePath } from 'path';
import {
PullRequestCreator,
GithubPullRequestActionInput,
@@ -28,7 +30,8 @@ import { getRootLogger } from '@backstage/backend-common';
import { ScmIntegrations } from '@backstage/integration';
import { ConfigReader } from '@backstage/config';
const id = 'createPublishGithubPullRequestAction';
const root = os.platform() === 'win32' ? 'C:\\root' : '/root';
const workspacePath = resolvePath(root, 'my-workspace');
describe('createPublishGithubPullRequestAction', () => {
let instance: TemplateAction<GithubPullRequestActionInput>;
@@ -72,7 +75,7 @@ describe('createPublishGithubPullRequestAction', () => {
};
mockFs({
[id]: { 'file.txt': 'Hello there!' },
[workspacePath]: { 'file.txt': 'Hello there!' },
});
ctx = {
@@ -81,7 +84,7 @@ describe('createPublishGithubPullRequestAction', () => {
logger: getRootLogger(),
logStream: new Writable(),
input,
workspacePath: id,
workspacePath,
};
});
it('creates a pull request', async () => {
@@ -133,7 +136,7 @@ describe('createPublishGithubPullRequestAction', () => {
};
mockFs({
[id]: {
[workspacePath]: {
source: { 'foo.txt': 'Hello there!' },
irrelevant: { 'bar.txt': 'Nothing to see here' },
},
@@ -145,7 +148,7 @@ describe('createPublishGithubPullRequestAction', () => {
logger: getRootLogger(),
logStream: new Writable(),
input,
workspacePath: id,
workspacePath,
};
});
@@ -188,7 +191,7 @@ describe('createPublishGithubPullRequestAction', () => {
};
mockFs({
[id]: { 'file.txt': 'Hello there!' },
[workspacePath]: { 'file.txt': 'Hello there!' },
});
ctx = {
@@ -197,7 +200,7 @@ describe('createPublishGithubPullRequestAction', () => {
logger: getRootLogger(),
logStream: new Writable(),
input,
workspacePath: id,
workspacePath,
};
});
it('creates a pull request', async () => {
@@ -197,17 +197,21 @@ export const createPublishGithubPullRequestAction = ({
const client = await clientFactory({ integrations, host, owner, repo });
const fileRoot = sourcePath
? path.join(ctx.workspacePath, sourcePath)
? path.resolve(ctx.workspacePath, sourcePath)
: ctx.workspacePath;
const localFilePaths = await globby(`${fileRoot}/**/*.*`);
const localFilePaths = await globby(['./**', './**/.*', '!.git'], {
cwd: fileRoot,
gitignore: true,
dot: true,
});
const fileContents = await Promise.all(
localFilePaths.map(p => readFile(p)),
localFilePaths.map(p => readFile(path.resolve(fileRoot, p))),
);
const repoFilePaths = localFilePaths.map(p => {
const relativePath = path.relative(fileRoot, p);
return targetPath ? `${targetPath}/${relativePath}` : relativePath;
const repoFilePaths = localFilePaths.map(repoFilePath => {
return targetPath ? `${targetPath}/${repoFilePath}` : repoFilePath;
});
const changes = [