Skip to content

Commit

Permalink
pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
jaiveerk committed Jul 24, 2024
1 parent 4b9af6f commit c082d00
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 31 deletions.
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@types/node": "^12.20.41",
"@vercel/ncc": "^0.36.1",
"jest": "^26.0.0",
"prettier": "^2.7.1",
"prettier": "^2.8.8",
"ts-jest": "^26.0.0",
"typescript": "3.9.5"
}
Expand Down
18 changes: 13 additions & 5 deletions src/types/privatekubectl.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { PrivateKubectl, extractFileNames, replaceFileNamesWithBaseNames } from './privatekubectl'
import {
PrivateKubectl,
extractFileNames,
replaceFileNamesWithBaseNames
} from './privatekubectl'
import * as exec from '@actions/exec'

describe('Private kubectl', () => {
Expand All @@ -12,9 +16,13 @@ describe('Private kubectl', () => {
)

it('should extract filenames correctly', () => {
expect(extractFileNames(testString)).toEqual(
['testdir/test.yml', 'test2.yml', 'testdir/subdir/test3.yml', 'test4.yml', 'test5.yml']
)
expect(extractFileNames(testString)).toEqual([
'testdir/test.yml',
'test2.yml',
'testdir/subdir/test3.yml',
'test4.yml',
'test5.yml'
])
})

it('should replace filenames with basenames correctly', () => {
Expand All @@ -26,7 +34,7 @@ describe('Private kubectl', () => {
test('Should throw well defined Error on error from Azure', async () => {
const errorMsg = 'An error message'
jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
return { exitCode: 1, stdout: '', stderr: errorMsg }
return {exitCode: 1, stdout: '', stderr: errorMsg}
})

await expect(mockKube.executeCommand('az', 'test')).rejects.toThrow(
Expand Down
43 changes: 25 additions & 18 deletions src/types/privatekubectl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Kubectl } from './kubectl'
import {Kubectl} from './kubectl'
import * as minimist from 'minimist'
import { ExecOptions, ExecOutput, getExecOutput } from '@actions/exec'
import {ExecOptions, ExecOutput, getExecOutput} from '@actions/exec'
import * as core from '@actions/core'
import * as os from 'os'
import * as fs from 'fs'
Expand Down Expand Up @@ -54,7 +54,9 @@ export class PrivateKubectl extends Kubectl {
try {
this.moveFileToTempManifestDir(filename)
} catch (e) {
core.debug(`Error moving file ${filename} to temp directory: ${e}`)
core.debug(
`Error moving file ${filename} to temp directory: ${e}`
)
}
}
}
Expand All @@ -78,7 +80,7 @@ export class PrivateKubectl extends Kubectl {
)
}

const runObj: { logs: string; exitCode: number } = JSON.parse(
const runObj: {logs: string; exitCode: number} = JSON.parse(
runOutput.stdout
)
if (!silent) core.info(runObj.logs)
Expand All @@ -93,15 +95,14 @@ export class PrivateKubectl extends Kubectl {
} as ExecOutput
}


private containsFilenames(str: string) {
return str.includes('-f ') || str.includes('filename ')
}

private createTempManifestsDirectory() {
const manifestsDir = '/tmp/manifests'
if (!fs.existsSync('/tmp/manifests')) {
fs.mkdirSync('/tmp/manifests', { recursive: true })
fs.mkdirSync('/tmp/manifests', {recursive: true})
}
}

Expand All @@ -110,29 +111,29 @@ export class PrivateKubectl extends Kubectl {
if (!fs.existsSync('/tmp/' + file)) {
core.debug(
'/tmp/' +
file +
' does not exist, and therefore cannot be moved to the manifest directory'
file +
' does not exist, and therefore cannot be moved to the manifest directory'
)
}

fs.copyFile('/tmp/' + file, '/tmp/manifests/' + file, function (err) {
if (err) {
core.debug(
'Could not rename ' +
'/tmp/' +
file +
' to ' +
'/tmp/manifests/' +
file +
' ERROR: ' +
err
'/tmp/' +
file +
' to ' +
'/tmp/manifests/' +
file +
' ERROR: ' +
err
)
return
}
core.debug(
"Successfully moved file '" +
file +
"' from /tmp to /tmp/manifest directory"
file +
"' from /tmp to /tmp/manifest directory"
)
})
}
Expand All @@ -144,7 +145,13 @@ export function replaceFileNamesWithBaseNames(kubectlCmd: string) {

let result = kubectlCmd
if (filenames.length != basenames.length) {
throw Error('replacing filenames with basenames, ' + filenames.length + ' filenames != ' + basenames.length + 'basenames')
throw Error(
'replacing filenames with basenames, ' +
filenames.length +
' filenames != ' +
basenames.length +
'basenames'
)
}
for (let index = 0; index < filenames.length; index++) {
result = result.replace(filenames[index], basenames[index])
Expand Down

0 comments on commit c082d00

Please sign in to comment.