Skip to content

Commit 844aa25

Browse files
committed
Fixup: Global for Git, Blog and Tests
1 parent f933729 commit 844aa25

File tree

4 files changed

+51
-30
lines changed

4 files changed

+51
-30
lines changed

__tests__/git.test.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ describe('Git CLI', () => {
1515
})
1616

1717
describe('git checkout', () => {
18+
beforeEach(() => {
19+
jest.spyOn(cwd, 'getWorkspace').mockReturnValue('/test-workspace')
20+
})
21+
1822
it('should create new branch', async () => {
1923
const execMock = jest.spyOn(exec, 'exec').mockResolvedValue(0)
20-
2124
await switchBranch('new-branch')
2225
expect(execMock).toHaveBeenCalledWith(
2326
'git',
24-
['checkout', '-b', 'new-branch'],
27+
['-C', '/test-workspace', 'checkout', '-b', 'new-branch'],
2528
expect.objectContaining({
2629
listeners: { stdline: expect.anything(), errline: expect.anything() },
2730
})
@@ -89,6 +92,10 @@ describe('Git CLI', () => {
8992
})
9093

9194
describe('git push', () => {
95+
beforeEach(() => {
96+
jest.spyOn(cwd, 'getWorkspace').mockReturnValue('/test-workspace')
97+
})
98+
9299
it('should push new branch', async () => {
93100
const execMock = jest.spyOn(exec, 'exec').mockResolvedValue(0)
94101
const getInput = jest
@@ -98,7 +105,15 @@ describe('Git CLI', () => {
98105
await pushCurrentBranch()
99106
expect(execMock).toHaveBeenCalledWith(
100107
'git',
101-
['push', '--porcelain', '--set-upstream', 'origin', 'HEAD'],
108+
[
109+
'-C',
110+
'/test-workspace',
111+
'push',
112+
'--porcelain',
113+
'--set-upstream',
114+
'origin',
115+
'HEAD',
116+
],
102117
expect.objectContaining({
103118
listeners: { stdline: expect.anything(), errline: expect.anything() },
104119
})
@@ -113,7 +128,16 @@ describe('Git CLI', () => {
113128
expect(execMock).toHaveBeenCalled()
114129
expect(execMock).toHaveBeenCalledWith(
115130
'git',
116-
['push', '--force', '--porcelain', '--set-upstream', 'origin', 'HEAD'],
131+
[
132+
'-C',
133+
'/test-workspace',
134+
'push',
135+
'--force',
136+
'--porcelain',
137+
'--set-upstream',
138+
'origin',
139+
'HEAD',
140+
],
117141
expect.objectContaining({
118142
listeners: { stdline: expect.anything(), errline: expect.anything() },
119143
})
@@ -184,7 +208,7 @@ describe('Git CLI', () => {
184208
jest.spyOn(cwd, 'getWorkspace').mockReturnValue('/test-workspace')
185209
})
186210

187-
it('should ensure file paths are within curent working directory', async () => {
211+
it('should ensure file paths are within current working directory', async () => {
188212
const execMock = jest.spyOn(exec, 'exec').mockResolvedValue(0)
189213

190214
await addFileChanges(['*.ts', '~/.bashrc'])
@@ -269,6 +293,10 @@ describe('Git CLI', () => {
269293
'A tests/run.test.ts',
270294
]
271295

296+
beforeEach(() => {
297+
jest.spyOn(cwd, 'getWorkspace').mockReturnValue('/test-workspace')
298+
})
299+
272300
it('should parse ouput into file changes', async () => {
273301
const execMock = jest
274302
.spyOn(exec, 'exec')

dist/index.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29857,15 +29857,15 @@ const base64_encoder_1 = __importDefault(__nccwpck_require__(5564));
2985729857
class Blob {
2985829858
constructor(path) {
2985929859
const cwd = (0, cwd_1.getCwd)();
29860-
const workspace = (0, cwd_1.getWorkspace)();
29861-
core.debug('Blob.constructor() - Add workspace directory to filepath');
29862-
const tmpPath = (0, node_path_1.join)(workspace, path);
2986329860
// Add GHA cwd
29864-
this.absolutePath = tmpPath.startsWith(cwd) ? tmpPath : (0, node_path_1.join)(cwd, tmpPath);
29861+
this.absolutePath = path.startsWith(cwd) ? path : (0, node_path_1.join)(cwd, path);
29862+
core.debug('Blob.constructor() - this.absolutePath: ' +
29863+
JSON.stringify(this.absolutePath));
2986529864
// Remove GHA cwd
2986629865
this.path = path.startsWith(cwd)
2986729866
? path.replace(new RegExp(cwd, 'g'), '')
2986829867
: path;
29868+
core.debug('Blob.constructor() - this.path: ' + JSON.stringify(this.path));
2986929869
}
2987029870
get streamable() {
2987129871
if (!fs.existsSync(this.absolutePath)) {
@@ -29884,8 +29884,9 @@ class Blob {
2988429884
chunks.push(chunk);
2988529885
else if (typeof chunk === 'string')
2988629886
chunks.push(node_buffer_1.Buffer.from(chunk));
29887+
core.debug(
2988729888
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
29888-
core.debug(`Blob.load() - filepath ${this.absolutePath}, received blob: ${chunk}`);
29889+
`Blob.load() - filepath ${this.absolutePath}, received blob: ${chunk}`);
2988929890
});
2989029891
stream.on('error', (err) => {
2989129892
throw new Error(`Read file failed, error: ${err.message}, path: ${this.absolutePath}`);
@@ -29993,14 +29994,10 @@ function execGit(args) {
2999329994
const debugOutput = [];
2999429995
const warningOutput = [];
2999529996
const errorOutput = [];
29996-
const defaultArgs = [];
2999729997
// Handle workspace
2999829998
const workspace = (0, cwd_1.getWorkspace)();
29999-
if (workspace !== '') {
30000-
defaultArgs.push('-C');
30001-
defaultArgs.push(workspace);
30002-
core.debug('execGit() - Adding GHA parameter "workspace" to git cli args');
30003-
}
29999+
const defaultArgs = ['-C', workspace];
30000+
core.debug('execGit() - Adding GHA parameter "workspace" to git cli args');
3000430001
core.debug('execGit() - defaultArgs: ' + JSON.stringify(defaultArgs));
3000530002
core.debug('execGit() - args parameter: ' + JSON.stringify(args));
3000630003
const mergedArgs = defaultArgs.concat(args);

src/blob.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Readable } from 'node:stream'
66
import { finished } from 'node:stream/promises'
77
import { FileAddition } from '@octokit/graphql-schema'
88

9-
import { getCwd, getWorkspace } from './utils/cwd'
9+
import { getCwd } from './utils/cwd'
1010
import Base64Encoder from './stream/base64-encoder'
1111

1212
export class Blob {
@@ -17,18 +17,19 @@ export class Blob {
1717

1818
constructor(path: string) {
1919
const cwd = getCwd()
20-
const workspace = getWorkspace()
21-
22-
core.debug('Blob.constructor() - Add workspace directory to filepath')
23-
const tmpPath = join(workspace, path)
2420

2521
// Add GHA cwd
26-
this.absolutePath = tmpPath.startsWith(cwd) ? tmpPath : join(cwd, tmpPath)
22+
this.absolutePath = path.startsWith(cwd) ? path : join(cwd, path)
23+
core.debug(
24+
'Blob.constructor() - this.absolutePath: ' +
25+
JSON.stringify(this.absolutePath)
26+
)
2727

2828
// Remove GHA cwd
2929
this.path = path.startsWith(cwd)
3030
? path.replace(new RegExp(cwd, 'g'), '')
3131
: path
32+
core.debug('Blob.constructor() - this.path: ' + JSON.stringify(this.path))
3233
}
3334

3435
get streamable(): Readable {
@@ -49,8 +50,8 @@ export class Blob {
4950
if (Buffer.isBuffer(chunk)) chunks.push(chunk)
5051
else if (typeof chunk === 'string') chunks.push(Buffer.from(chunk))
5152

52-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
5353
core.debug(
54+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
5455
`Blob.load() - filepath ${this.absolutePath}, received blob: ${chunk}`
5556
)
5657
})

src/git.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,10 @@ async function execGit(args: string[]) {
1313
const warningOutput: string[] = []
1414
const errorOutput: string[] = []
1515

16-
const defaultArgs: string[] = []
17-
1816
// Handle workspace
1917
const workspace = getWorkspace()
20-
if (workspace !== '') {
21-
defaultArgs.push('-C')
22-
defaultArgs.push(workspace)
23-
core.debug('execGit() - Adding GHA parameter "workspace" to git cli args')
24-
}
18+
const defaultArgs: string[] = ['-C', workspace]
19+
core.debug('execGit() - Adding GHA parameter "workspace" to git cli args')
2520

2621
core.debug('execGit() - defaultArgs: ' + JSON.stringify(defaultArgs))
2722
core.debug('execGit() - args parameter: ' + JSON.stringify(args))

0 commit comments

Comments
 (0)