Skip to content

Commit

Permalink
Merge pull request #85 from github/brrygrdn/update-from-cli
Browse files Browse the repository at this point in the history
[DevTools] Trigger a job run from a cli script
  • Loading branch information
Barry Gordon authored and GitHub committed Sep 16, 2021
2 parents ea23d31 + 22184c3 commit 10f6585
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 79 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Updater output
output/output.json
repo
tmp/

# Dependency directory
node_modules
Expand Down
4 changes: 2 additions & 2 deletions __fixtures__/events/default.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"inputs": {
"jobID": "1",
"jobId": "1",
"jobToken": "xxx",
"credentialsToken": "yyy",
"dependabotAPIURL": "http://localhost:9000"
"dependabotApiUrl": "http://localhost:9000"
},
"ref": "main",
"repository": {
Expand Down
5 changes: 3 additions & 2 deletions __tests__/dependabot-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ describe('APIClient', () => {
get: jest.fn()
}
const api = new APIClient(mockAxios, {
jobID: 1,
jobId: 1,
jobToken: 'xxx',
credentialsToken: 'yyy',
dependabotAPIURL: 'https://localhost'
dependabotApiUrl: 'https://localhost',
dependabotApiDockerUrl: 'https://localhost'
})
beforeEach(jest.clearAllMocks)

Expand Down
8 changes: 4 additions & 4 deletions __tests__/inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ test('loads dynamic', () => {
ctx.eventName = 'dynamic'
ctx.payload = {
inputs: {
jobID: 1,
jobId: 1,
jobToken: 'xxx',
credentialsToken: 'yyy'
}
}

const params = getJobParameters(ctx)
expect(params?.jobID).toEqual(1)
expect(params?.jobId).toEqual(1)
expect(params?.jobToken).toEqual('xxx')
expect(params?.credentialsToken).toEqual('yyy')
})
Expand All @@ -31,14 +31,14 @@ test('loads workflow_dispatch', () => {
ctx.eventName = 'workflow_dispatch'
ctx.payload = {
inputs: {
jobID: '1',
jobId: '1',
jobToken: 'xxx',
credentialsToken: 'yyy'
}
}

const params = getJobParameters(ctx)
expect(params?.jobID).toEqual(1)
expect(params?.jobId).toEqual(1)
expect(params?.jobToken).toEqual('xxx')
expect(params?.credentialsToken).toEqual('yyy')
})
30 changes: 8 additions & 22 deletions __tests__/updater-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,21 @@ const FAKE_SERVER_PORT = 9000
describe('Updater', () => {
let server: any

// To run the js-code itself against API:
// const params = {
// jobID: 1,
// jobToken: 'xxx',
// credentialsToken: 'xxx',
// dependabotAPI: 'http://host.docker.internal:3001'
// }

// This runs the tests against a fake dependabot-api server using json-server
const fakeDependabotApiUrl = `http://localhost:${FAKE_SERVER_PORT}`
// Used from this action to get job details and credentials
const externalDependabotApiUrl =
process.env.DEPENDABOT_API_URL || fakeDependabotApiUrl
const dependabotApiUrl = `http://localhost:${FAKE_SERVER_PORT}`
// Used from within the updater container to update the job state and create prs
const internalDockerHost =
process.platform === 'darwin' ? 'host.docker.internal' : '172.17.0.1'
const internalDependabotApiUrl =
process.env.DEPENDABOT_API_URL ||
`http://${internalDockerHost}:${FAKE_SERVER_PORT}`
const dependabotApiDockerUrl = `http://${internalDockerHost}:${FAKE_SERVER_PORT}`
const params = new JobParameters(
1,
process.env.JOB_TOKEN || 'job-token',
process.env.CREDENTIALS_TOKEN || 'cred-token',
internalDependabotApiUrl
'job-token',
'cred-token',
dependabotApiUrl,
dependabotApiDockerUrl
)

const client = axios.create({baseURL: externalDependabotApiUrl})
const client = axios.create({baseURL: dependabotApiUrl})
const apiClient = new APIClient(client, params)

beforeAll(async () => {
Expand All @@ -50,9 +38,7 @@ describe('Updater', () => {
await ImageService.pull(UPDATER_IMAGE_NAME)
await ImageService.pull(PROXY_IMAGE_NAME)

if (externalDependabotApiUrl === fakeDependabotApiUrl) {
server = await runFakeDependabotApi(FAKE_SERVER_PORT)
}
server = await runFakeDependabotApi(FAKE_SERVER_PORT)
})

afterEach(async () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/updater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ describe('Updater', () => {
getJobDetails: jest.fn(),
getCredentials: jest.fn(),
params: {
jobID: 1,
jobId: 1,
jobToken: process.env.JOB_TOKEN,
credentialsToken: process.env.CREDENTIALS_TOKEN,
dependabotAPIURL: 'http://host.docker.internal:3001'
dependabotApiUrl: 'http://host.docker.internal:3001'
}
}
const mockJobDetails: any = {
Expand Down
34 changes: 17 additions & 17 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

34 changes: 25 additions & 9 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"test": "SKIP_INTEGRATION_TESTS=true jest --detectOpenHandles",
"test-integration": "jest --detectOpenHandles 'integration'",
"prepare": "husky install",
"all": "npm run format && npm run lint && npm run package && npm test"
"all": "npm run format && npm run lint && npm run package && npm test",
"dependabot": "npx ts-node src/cli.ts"
},
"repository": {
"type": "git",
Expand All @@ -29,6 +30,7 @@
"@actions/github": "^5.0.0",
"@octokit/webhooks-definitions": "^3.67.3",
"axios": "^0.21.1",
"commander": "^8.2.0",
"dockerode": "^3.3.0",
"tar-stream": "^2.2.0"
},
Expand Down
4 changes: 2 additions & 2 deletions script/hack-event.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"action": "on-demand-test",
"branch": "master",
"client_payload": {
"dependabotAPIURL": "https://3c3fcfad18d1.ngrok.io",
"jobID": "8",
"dependabotApiUrl": "https://3c3fcfad18d1.ngrok.io",
"jobId": "8",
"jobToken": "QkNM+m1lDFieJ0V6DAwUY+hG6PUKItjuS7EApTVsTQw=",
"credentialsToken": "hMAqnnY+CJGUCQjKRUzSZnR+DnbW5YEA5nL2xh8zovk=",
"updaterImage": "docker.io/library/dependabot-updater:latest",
Expand Down
Loading

0 comments on commit 10f6585

Please sign in to comment.