@lifeomic/bitrise
Advanced tools
Comparing version 0.4.0 to 0.5.0
{ | ||
"name": "@lifeomic/bitrise", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Bitrise API client", | ||
"main": "src/client.js", | ||
"types": "index.d.ts", | ||
"repository": { | ||
@@ -33,3 +34,3 @@ "type": "git", | ||
"luxon": "^1.3.1", | ||
"nock": "^9.4.2", | ||
"nock": "^10.0.0", | ||
"nyc": "^12.0.2", | ||
@@ -36,0 +37,0 @@ "sinon": "^6.1.0", |
@@ -13,3 +13,3 @@ const build = require('./build'); | ||
const environments = []; | ||
for (const [ name, value ] of Object.entries(environment)) { | ||
for (const [name, value] of Object.entries(environment)) { | ||
environments.push({ mapped_to: name, value }); | ||
@@ -20,17 +20,39 @@ } | ||
const buildParameters = ( | ||
{ branch, commitHash, commitMessage, disableStatusReporting, environment, pullRequest, target, workflow } | ||
) => pickBy( | ||
{ | ||
branch: branch || 'master', | ||
branch_dest: target, | ||
commit_hash: commitHash, | ||
commit_message: commitMessage, | ||
environments: buildEnvironment(environment), | ||
pull_request_id: pullRequest, | ||
skip_git_status_report: disableStatusReporting, | ||
workflow_id: workflow | ||
}, | ||
negate(isNil) | ||
); | ||
const buildParameters = ({ | ||
target, | ||
branch, | ||
commitHash, | ||
commitMessage, | ||
environment, | ||
commitPaths, | ||
diffUrl, | ||
pullRequest, | ||
pullRequestAuthor, | ||
pullRequestHeadBranch, | ||
workflow, | ||
pullRequestMergeBranch, | ||
pullRequestRepositoryUrl, | ||
disableStatusReporting, | ||
tag | ||
}) => | ||
pickBy( | ||
{ | ||
branch: branch || 'master', | ||
branch_dest: target, | ||
commit_hash: commitHash, | ||
commit_message: commitMessage, | ||
commit_paths: commitPaths, | ||
diff_url: diffUrl, | ||
pull_request_author: pullRequestAuthor, | ||
pull_request_head_branch: pullRequestHeadBranch, | ||
pull_request_id: pullRequest, | ||
pull_request_merge_branch: pullRequestMergeBranch, | ||
pull_request_repository_url: pullRequestRepositoryUrl, | ||
environments: buildEnvironment(environment), | ||
skip_git_status_report: disableStatusReporting, | ||
workflow_id: workflow, | ||
tag: tag | ||
}, | ||
negate(isNil) | ||
); | ||
@@ -37,0 +59,0 @@ const triggerBuild = async ({ client, slug }, options = {}) => { |
@@ -0,4 +1,16 @@ | ||
const isNil = require('lodash/isNil'); | ||
const negate = require('lodash/negate'); | ||
const pickBy = require('lodash/pickBy'); | ||
const abortBuild = async ({ appSlug, buildSlug, client }, options = {}) => { | ||
if (options.reason) { | ||
await client.post(`/apps/${appSlug}/builds/${buildSlug}/abort`, { abort_reason: options.reason }); | ||
const params = pickBy( | ||
{ | ||
abort_reason: options.reason, | ||
abort_with_success: options.withSuccess, | ||
skip_notifications: options.skipNotifications | ||
}, | ||
negate(isNil) | ||
); | ||
await client.post(`/apps/${appSlug}/builds/${buildSlug}/abort`, params); | ||
return; | ||
@@ -25,3 +37,5 @@ } | ||
const parameters = timestamp ? `?timestamp=${timestamp}` : ''; | ||
const response = await client.get(`/apps/${appSlug}/builds/${buildSlug}/log${parameters}`); | ||
const response = await client.get( | ||
`/apps/${appSlug}/builds/${buildSlug}/log${parameters}` | ||
); | ||
@@ -31,3 +45,5 @@ // If the log has already been archived then polling is no good. Just | ||
if (response.data.is_archived && !timestamp) { | ||
const archiveResponse = await client.get(response.data.expiring_raw_log_url); | ||
const archiveResponse = await client.get( | ||
response.data.expiring_raw_log_url | ||
); | ||
process.stdout.write(archiveResponse.data); | ||
@@ -39,5 +55,7 @@ break; | ||
if (response.data.log_chunks.length) { | ||
response.data.log_chunks.forEach(({ chunk }) => process.stdout.write(chunk)); | ||
response.data.log_chunks.forEach(({ chunk }) => | ||
process.stdout.write(chunk) | ||
); | ||
lastActive = now; | ||
} else if (options.heartbeat && (now - lastActive) >= options.heartbeat) { | ||
} else if (options.heartbeat && now - lastActive >= options.heartbeat) { | ||
process.stdout.write('heartbeat: waiting for build output...\n'); | ||
@@ -44,0 +62,0 @@ lastActive = now; |
@@ -43,2 +43,67 @@ const app = require('../src/app'); | ||
test('an app can trigger a build with very fine grain filtering', async (test) => { | ||
const { app, client, slug } = test.context; | ||
const opts = { | ||
branch: 'some-branch', | ||
target: 'master', | ||
commitHash: '3d0faba', | ||
commitMessage: 'some message', | ||
commitPaths: [ | ||
{ | ||
added: ['*foo*'], | ||
removed: ['*bar*'], | ||
modified: ['*bazz*'] | ||
} | ||
], | ||
diffUrl: 'github.com/org/repo/tree/master/diff/3d0faba', | ||
pullRequest: '1', | ||
pullRequestAuthor: 'someone', | ||
pullRequestHeadBranch: 'some-branch', | ||
pullRequestMergeBranch: 'master', | ||
pullRequestRepositoryUrl: 'github.com/org/repo', | ||
workflow: 'deploy', | ||
tag: '1.0.0' | ||
}; | ||
const expectedBuildParams = { | ||
branch: 'some-branch', | ||
branch_dest: 'master', | ||
commit_hash: '3d0faba', | ||
commit_message: 'some message', | ||
commit_paths: [ | ||
{ | ||
added: ['*foo*'], | ||
removed: ['*bar*'], | ||
modified: ['*bazz*'] | ||
} | ||
], | ||
diff_url: 'github.com/org/repo/tree/master/diff/3d0faba', | ||
pull_request_author: 'someone', | ||
pull_request_head_branch: 'some-branch', | ||
pull_request_id: '1', | ||
pull_request_merge_branch: 'master', | ||
pull_request_repository_url: 'github.com/org/repo', | ||
workflow_id: 'deploy', | ||
tag: '1.0.0' | ||
}; | ||
const stub = stubTriggerBuild({ appSlug: slug, axios: client }); | ||
const build = await app.triggerBuild(opts); | ||
test.is(build.appSlug, slug); | ||
test.is(build.buildSlug, stub.build.build_slug); | ||
sinon.assert.calledOnce(client.post); | ||
sinon.assert.calledWithExactly( | ||
client.post, | ||
sinon.match.string, | ||
sinon.match({ | ||
build_params: sinon.match(expectedBuildParams), | ||
hook_info: sinon.match({ type: 'bitrise' }), | ||
triggered_by: '@lifeomic/bitrise' | ||
}) | ||
); | ||
}); | ||
test('an app can trigger a build for a specific commit', async (test) => { | ||
@@ -45,0 +110,0 @@ const { app, client, slug } = test.context; |
@@ -22,3 +22,5 @@ const get = require('lodash/get'); | ||
const unmatchedRequest = async (...args) => { | ||
throw new Error(`Failed to match request with arguments: ${JSON.stringify(args, null, 2)}`); | ||
throw new Error( | ||
`Failed to match request with arguments: ${JSON.stringify(args, null, 2)}` | ||
); | ||
}; | ||
@@ -29,7 +31,6 @@ | ||
stub.withArgs(`/apps/${appSlug}/builds/${buildSlug}/abort`) | ||
.resolves({ | ||
data: { status: 'ok' }, | ||
status: 200 | ||
}); | ||
stub.withArgs(`/apps/${appSlug}/builds/${buildSlug}/abort`).resolves({ | ||
data: { status: 'ok' }, | ||
status: 200 | ||
}); | ||
@@ -43,16 +44,14 @@ return stub; | ||
stub.withArgs(`/apps/${appSlug}/builds/${buildSlug}/log`) | ||
.resolves({ | ||
data: { | ||
expiring_raw_log_url: logUrl, | ||
is_archived: true | ||
}, | ||
status: 200 | ||
}); | ||
stub.withArgs(`/apps/${appSlug}/builds/${buildSlug}/log`).resolves({ | ||
data: { | ||
expiring_raw_log_url: logUrl, | ||
is_archived: true | ||
}, | ||
status: 200 | ||
}); | ||
stub.withArgs(logUrl) | ||
.resolves({ | ||
data: logText, | ||
status: 200 | ||
}); | ||
stub.withArgs(logUrl).resolves({ | ||
data: logText, | ||
status: 200 | ||
}); | ||
}; | ||
@@ -71,18 +70,17 @@ | ||
logStub.withArgs(logUrl) | ||
.resolves({ | ||
data: { | ||
is_archived: chunks.length === 0, | ||
log_chunks: chunk | ||
? [ | ||
{ | ||
chunk, | ||
position: timestamp | ||
} | ||
] | ||
: [], | ||
timestamp: chunks.length ? timestamp : null | ||
}, | ||
status: 200 | ||
}); | ||
logStub.withArgs(logUrl).resolves({ | ||
data: { | ||
is_archived: chunks.length === 0, | ||
log_chunks: chunk | ||
? [ | ||
{ | ||
chunk, | ||
position: timestamp | ||
} | ||
] | ||
: [], | ||
timestamp: chunks.length ? timestamp : null | ||
}, | ||
status: 200 | ||
}); | ||
@@ -107,7 +105,10 @@ timestamp++; | ||
exports.stubTriggerBuild = ({ appSlug, axios }) => { | ||
exports.stubTriggerBuild = ({ appSlug, axios, body }) => { | ||
const build = generateBuild(); | ||
const args = [`/apps/${appSlug}/builds`]; | ||
if (body) args.push(body); | ||
const stub = getStub(axios, 'post') | ||
.withArgs(`/apps/${appSlug}/builds`) | ||
.withArgs(...args) | ||
.resolves({ | ||
@@ -114,0 +115,0 @@ data: build, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
192543
15
871
0