Skip to content

Commit df9ea5b

Browse files
authored
remove unused output and repo path code (#1537)
1 parent 6b07cf6 commit df9ea5b

File tree

14 files changed

+32
-435
lines changed

14 files changed

+32
-435
lines changed

__fixtures__/output/happy_path/output.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

__fixtures__/output/malformed/output.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

__tests__/api_client.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ describe('ApiClient', () => {
2424
credentialsToken,
2525
dependabotApiUrl: 'https://localhost',
2626
dependabotApiDockerUrl: 'https://localhost',
27-
updaterImage: '', // irrelevant for this test
28-
workingDirectory: './job-directory'
27+
updaterImage: '' // irrelevant for this test
2928
},
3029
jobToken,
3130
credentialsToken

__tests__/inputs.test.ts

Lines changed: 0 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,15 @@
1-
import crypto from 'crypto'
2-
import fs from 'fs'
3-
import path from 'path'
41
import {Context} from '@actions/github/lib/context'
52
import {getJobParameters} from '../src/inputs'
63
import {eventFixturePath} from './helpers'
74

85
let context: Context
9-
const workspace = path.join(__dirname, '..', 'tmp')
10-
const workingDirectory = path.join(workspace, './test_working_directory')
11-
12-
beforeEach(() => {
13-
fs.mkdirSync(workingDirectory)
14-
})
15-
16-
afterEach(() => {
17-
if (fs.existsSync(workingDirectory)) {
18-
fs.rmdirSync(workingDirectory)
19-
}
20-
})
216

227
describe('when there is a fully configured Actions environment', () => {
238
beforeEach(() => {
249
process.env.GITHUB_EVENT_PATH = eventFixturePath('default')
2510
process.env.GITHUB_EVENT_NAME = 'dynamic'
2611
process.env.GITHUB_ACTOR = 'dependabot[bot]'
2712
process.env.GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
28-
process.env.GITHUB_WORKSPACE = workspace
2913

3014
context = new Context()
3115
})
@@ -39,12 +23,6 @@ describe('when there is a fully configured Actions environment', () => {
3923
expect(params?.dependabotApiUrl).toEqual('http://localhost:9000')
4024
expect(params?.dependabotApiDockerUrl).toEqual('http://localhost:9000')
4125
})
42-
43-
test('it returns an absolute path based on GITHUB_WORKSPACE and the workingDirectory input', () => {
44-
const params = getJobParameters(context)
45-
46-
expect(params?.workingDirectory).toEqual(workingDirectory)
47-
})
4826
})
4927

5028
describe('when there is no GITHUB_EVENT_NAME defined', () => {
@@ -53,7 +31,6 @@ describe('when there is no GITHUB_EVENT_NAME defined', () => {
5331
delete process.env.GITHUB_EVENT_NAME
5432
process.env.GITHUB_ACTOR = 'dependabot[bot]'
5533
process.env.GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
56-
process.env.GITHUB_WORKSPACE = workspace
5734

5835
context = new Context()
5936
})
@@ -70,7 +47,6 @@ describe('when the GITHUB_EVENT_NAME is not "dynamic"', () => {
7047
process.env.GITHUB_EVENT_PATH = eventFixturePath('default')
7148
process.env.GITHUB_EVENT_NAME = 'issue_comment'
7249
process.env.GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
73-
process.env.GITHUB_WORKSPACE = workspace
7450

7551
context = new Context()
7652
})
@@ -88,7 +64,6 @@ describe('when there is no GITHUB_ACTOR defined', () => {
8864
process.env.GITHUB_EVENT_NAME = 'dynamic'
8965
delete process.env.GITHUB_ACTOR
9066
process.env.GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
91-
process.env.GITHUB_WORKSPACE = workspace
9267

9368
context = new Context()
9469
})
@@ -106,7 +81,6 @@ describe('when the GITHUB_ACTOR is not "dependabot[bot]"', () => {
10681
process.env.GITHUB_EVENT_NAME = 'dynamic'
10782
process.env.GITHUB_ACTOR = 'classic-rando'
10883
process.env.GITHUB_TRIGGERING_ACTOR = 'classic-rando'
109-
process.env.GITHUB_WORKSPACE = workspace
11084

11185
context = new Context()
11286
})
@@ -124,7 +98,6 @@ describe('when there is no GITHUB_TRIGGERING_ACTOR defined', () => {
12498
process.env.GITHUB_EVENT_NAME = 'dynamic'
12599
process.env.GITHUB_ACTOR = 'dependabot[bot]'
126100
delete process.env.GITHUB_TRIGGERING_ACTOR
127-
process.env.GITHUB_WORKSPACE = workspace
128101

129102
context = new Context()
130103
})
@@ -142,7 +115,6 @@ describe('when the GITHUB_TRIGGERING_ACTOR is not "dependabot[bot]"', () => {
142115
process.env.GITHUB_EVENT_NAME = 'dynamic'
143116
process.env.GITHUB_ACTOR = 'dependabot[bot]'
144117
process.env.GITHUB_TRIGGERING_ACTOR = 'classic-rando'
145-
process.env.GITHUB_WORKSPACE = workspace
146118

147119
context = new Context()
148120
})
@@ -154,158 +126,14 @@ describe('when the GITHUB_TRIGGERING_ACTOR is not "dependabot[bot]"', () => {
154126
})
155127
})
156128

157-
describe('when there is no GITHUB_WORKSPACE defined', () => {
158-
beforeEach(() => {
159-
process.env.GITHUB_EVENT_PATH = eventFixturePath('default')
160-
process.env.GITHUB_EVENT_NAME = 'dynamic'
161-
process.env.GITHUB_ACTOR = 'dependabot[bot]'
162-
process.env.GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
163-
delete process.env.GITHUB_WORKSPACE
164-
165-
context = new Context()
166-
})
167-
168-
test('it throws an error', () => {
169-
expect(() => {
170-
getJobParameters(context)
171-
}).toThrow('Required Actions environment variables missing.')
172-
})
173-
})
174-
175-
describe('when the GITHUB_WORKSPACE path does not exist', () => {
176-
beforeEach(() => {
177-
const randomFolderName = crypto.randomBytes(16).toString('hex')
178-
179-
process.env.GITHUB_EVENT_PATH = eventFixturePath('default')
180-
process.env.GITHUB_EVENT_NAME = 'dynamic'
181-
process.env.GITHUB_ACTOR = 'dependabot[bot]'
182-
process.env.GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
183-
process.env.GITHUB_WORKSPACE = path.join(workspace, randomFolderName)
184-
185-
context = new Context()
186-
})
187-
188-
test('it throws an error', () => {
189-
expect(() => {
190-
getJobParameters(context)
191-
}).toThrow('The GITHUB_WORKSPACE directory does not exist.')
192-
})
193-
})
194-
195-
describe('when the GITHUB_WORKSPACE exists, but is a file', () => {
196-
const randomFileName = path.join(
197-
workspace,
198-
crypto.randomBytes(16).toString('hex')
199-
)
200-
201-
beforeEach(() => {
202-
process.env.GITHUB_EVENT_PATH = eventFixturePath('default')
203-
process.env.GITHUB_EVENT_NAME = 'dynamic'
204-
process.env.GITHUB_ACTOR = 'dependabot[bot]'
205-
process.env.GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
206-
process.env.GITHUB_WORKSPACE = randomFileName
207-
208-
fs.closeSync(fs.openSync(randomFileName, 'w'))
209-
210-
context = new Context()
211-
})
212-
213-
afterEach(() => {
214-
fs.unlinkSync(randomFileName)
215-
})
216-
217-
test('it throws an error', () => {
218-
expect(() => {
219-
getJobParameters(context)
220-
}).toThrow('The GITHUB_WORKSPACE directory does not exist.')
221-
})
222-
})
223-
224-
describe('when the workingDirectory is a blank value', () => {
225-
beforeEach(() => {
226-
process.env.GITHUB_EVENT_PATH = eventFixturePath('blank_working_directory')
227-
process.env.GITHUB_EVENT_NAME = 'dynamic'
228-
process.env.GITHUB_ACTOR = 'dependabot[bot]'
229-
process.env.GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
230-
process.env.GITHUB_WORKSPACE = workspace
231-
232-
context = new Context()
233-
234-
fs.rmdirSync(workingDirectory)
235-
fs.closeSync(fs.openSync(workingDirectory, 'w'))
236-
})
237-
238-
afterEach(() => {
239-
fs.unlinkSync(workingDirectory)
240-
})
241-
242-
test('it throws an error', () => {
243-
expect(() => {
244-
getJobParameters(context)
245-
}).toThrow('The workingDirectory input must not be blank')
246-
})
247-
})
248-
249-
describe('when the workingDirectory does not exist', () => {
250-
beforeEach(() => {
251-
process.env.GITHUB_EVENT_PATH = eventFixturePath('default')
252-
process.env.GITHUB_EVENT_NAME = 'dynamic'
253-
process.env.GITHUB_ACTOR = 'dependabot[bot]'
254-
process.env.GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
255-
process.env.GITHUB_WORKSPACE = workspace
256-
257-
context = new Context()
258-
259-
fs.rmdirSync(workingDirectory)
260-
})
261-
262-
test('it throws an error', () => {
263-
expect(() => {
264-
getJobParameters(context)
265-
}).toThrow(
266-
`The workingDirectory './test_working_directory' does not exist in GITHUB_WORKSPACE`
267-
)
268-
})
269-
})
270-
271-
describe('when the workingDirectory exists, but is a file', () => {
272-
beforeEach(() => {
273-
process.env.GITHUB_EVENT_PATH = eventFixturePath('default')
274-
process.env.GITHUB_EVENT_NAME = 'dynamic'
275-
process.env.GITHUB_ACTOR = 'dependabot[bot]'
276-
process.env.GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
277-
process.env.GITHUB_WORKSPACE = workspace
278-
279-
context = new Context()
280-
281-
fs.rmdirSync(workingDirectory)
282-
fs.closeSync(fs.openSync(workingDirectory, 'w'))
283-
})
284-
285-
afterEach(() => {
286-
fs.unlinkSync(workingDirectory)
287-
})
288-
289-
test('it throws an error', () => {
290-
expect(() => {
291-
getJobParameters(context)
292-
}).toThrow(
293-
`The workingDirectory './test_working_directory' does not exist in GITHUB_WORKSPACE`
294-
)
295-
})
296-
})
297-
298129
describe('when the event inputs are empty', () => {
299130
beforeEach(() => {
300131
process.env.GITHUB_EVENT_PATH = eventFixturePath('no_inputs')
301132
process.env.GITHUB_EVENT_NAME = 'dynamic'
302133
process.env.GITHUB_ACTOR = 'dependabot[bot]'
303134
process.env.GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
304-
process.env.GITHUB_WORKSPACE = workspace
305135

306136
context = new Context()
307-
308-
fs.rmdirSync(workingDirectory)
309137
})
310138

311139
test('it throws an error', () => {

__tests__/main.test.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import fs from 'fs'
2-
import path from 'path'
31
import * as core from '@actions/core'
42
import {Context} from '@actions/github/lib/context'
53
import {
@@ -23,8 +21,6 @@ jest.mock('../src/updater')
2321

2422
describe('run', () => {
2523
let context: Context
26-
const workspace = path.join(__dirname, '..', 'tmp')
27-
const workingDirectory = path.join(workspace, './test_working_directory')
2824

2925
let markJobAsProcessedSpy: any
3026
let reportJobErrorSpy: any
@@ -35,7 +31,6 @@ describe('run', () => {
3531
process.env.GITHUB_EVENT_NAME = 'dynamic'
3632
process.env.GITHUB_ACTOR = 'dependabot[bot]'
3733
process.env.GITHUB_TRIGGERING_ACTOR = 'dependabot[bot]'
38-
process.env.GITHUB_WORKSPACE = workspace
3934

4035
process.env.GITHUB_SERVER_URL = 'https://test.dev'
4136
process.env.GITHUB_REPOSITORY = 'foo/bar'
@@ -63,13 +58,10 @@ describe('run', () => {
6358
sendMetricsSpy = jest
6459
.spyOn(ApiClient.prototype, 'sendMetrics')
6560
.mockResolvedValue()
66-
67-
fs.mkdirSync(workingDirectory)
6861
})
6962

7063
afterEach(async () => {
7164
jest.clearAllMocks() // Reset any mocked classes
72-
fs.rmdirSync(workingDirectory)
7365
})
7466

7567
describe('when the run follows the happy path', () => {
@@ -538,8 +530,7 @@ describe('run', () => {
538530
'cred-token',
539531
'https://example.com',
540532
'172.17.0.1',
541-
'image/name:tag',
542-
'./'
533+
'image/name:tag'
543534
)
544535
)
545536

@@ -580,8 +571,7 @@ describe('run', () => {
580571
'', // credToken set as empty
581572
'https://example.com',
582573
'172.17.0.1',
583-
'image/name:tag',
584-
'./'
574+
'image/name:tag'
585575
)
586576
)
587577

@@ -624,8 +614,7 @@ describe('run', () => {
624614
'',
625615
'https://example.com',
626616
'172.17.0.1',
627-
'image/name:tag',
628-
'./'
617+
'image/name:tag'
629618
)
630619
)
631620
jest.spyOn(ApiClient.prototype, 'getJobDetails').mockImplementationOnce(
@@ -667,8 +656,7 @@ describe('run', () => {
667656
'',
668657
'https://example.com',
669658
'172.17.0.1',
670-
'image/name:tag',
671-
'./'
659+
'image/name:tag'
672660
)
673661
)
674662
jest.spyOn(ApiClient.prototype, 'getJobDetails').mockImplementationOnce(
@@ -712,8 +700,7 @@ describe('run', () => {
712700
'yyy',
713701
'https://example.com',
714702
'172.17.0.1',
715-
'image/name:tag',
716-
'./'
703+
'image/name:tag'
717704
)
718705
)
719706
jest.spyOn(ApiClient.prototype, 'getJobDetails').mockImplementationOnce(
@@ -755,8 +742,7 @@ describe('run', () => {
755742
'yyy',
756743
'https://example.com',
757744
'172.17.0.1',
758-
'image/name:tag',
759-
'./'
745+
'image/name:tag'
760746
)
761747
)
762748
jest.spyOn(ApiClient.prototype, 'getJobDetails').mockImplementationOnce(

0 commit comments

Comments
 (0)