Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PERCY_TARGET_COMMIT. #34

Merged
merged 2 commits into from
Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ class Environment {
return null;
}

get targetCommitSha() {
return this._env.PERCY_TARGET_COMMIT || null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this is consistently inconsistent — we name the other sha env var PERCY_COMMIT, and then translate it to "commitSha" internally.

}

get branch() {
if (this._env.PERCY_BRANCH) {
return this._env.PERCY_BRANCH;
Expand Down
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class PercyClient {
attributes: {
branch: commitData.branch,
'target-branch': this.environment.targetBranch,
'target-commit-sha': this.environment.targetCommitSha,
'commit-sha': commitData.sha,
'commit-committed-at': commitData.committedAt,
'commit-author-name': commitData.authorName,
Expand Down
20 changes: 20 additions & 0 deletions test/environment-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ COMMIT_MESSAGE:Sinon stubs are lovely`);
PERCY_COMMIT: 'percy-commit',
PERCY_BRANCH: 'percy-branch',
PERCY_TARGET_BRANCH: 'percy-target-branch',
PERCY_TARGET_COMMIT: 'percy-target-commit',
PERCY_PULL_REQUEST: '256',
PERCY_PARALLEL_NONCE: 'percy-nonce',
PERCY_PARALLEL_TOTAL: '3',
Expand All @@ -103,6 +104,7 @@ COMMIT_MESSAGE:Sinon stubs are lovely`);

it('allows override with percy env vars', function() {
assert.strictEqual(environment.commitSha, 'percy-commit');
assert.strictEqual(environment.targetCommitSha, 'percy-target-commit');
assert.strictEqual(environment.branch, 'percy-branch');
assert.strictEqual(environment.targetBranch, 'percy-target-branch');
assert.strictEqual(environment.pullRequestNumber, '256');
Expand Down Expand Up @@ -152,7 +154,9 @@ COMMIT_MESSAGE:Sinon stubs are lovely`);
it('has the correct properties', function() {
assert.strictEqual(environment.ci, 'travis');
assert.strictEqual(environment.commitSha, 'travis-commit-sha');
assert.strictEqual(environment.targetCommitSha, null);
assert.strictEqual(environment.branch, 'travis-branch');
assert.strictEqual(environment.targetBranch, null);
assert.strictEqual(environment.pullRequestNumber, null);
assert.strictEqual(environment.project, null);
assert.strictEqual(environment.repo, 'travis/repo-slug'); // TODO: Deprecated, remove.
Expand All @@ -169,7 +173,9 @@ COMMIT_MESSAGE:Sinon stubs are lovely`);
it('has the correct properties', function() {
assert.strictEqual(environment.pullRequestNumber, '256');
assert.strictEqual(environment.branch, 'travis-pr-branch');
assert.strictEqual(environment.targetBranch, null);
assert.strictEqual(environment.commitSha, 'travis-commit-sha');
assert.strictEqual(environment.targetCommitSha, null);
});
});
});
Expand All @@ -188,7 +194,9 @@ COMMIT_MESSAGE:Sinon stubs are lovely`);
it('has the correct properties', function() {
assert.strictEqual(environment.ci, 'jenkins');
assert.strictEqual(environment.commitSha, 'jenkins-commit-sha');
assert.strictEqual(environment.targetCommitSha, null);
assert.strictEqual(environment.branch, 'jenkins-branch');
assert.strictEqual(environment.targetBranch, null);
assert.strictEqual(environment.pullRequestNumber, '256');
assert.strictEqual(environment.project, null);
assert.strictEqual(environment.repo, null); // TODO: Deprecated, remove.
Expand All @@ -214,7 +222,9 @@ COMMIT_MESSAGE:Sinon stubs are lovely`);
it('has the correct properties', function() {
assert.strictEqual(environment.ci, 'circle');
assert.strictEqual(environment.commitSha, 'circle-commit-sha');
assert.strictEqual(environment.targetCommitSha, null);
assert.strictEqual(environment.branch, 'circle-branch');
assert.strictEqual(environment.targetBranch, null);
assert.strictEqual(environment.pullRequestNumber, '123');
assert.strictEqual(environment.project, null);
assert.strictEqual(environment.repo, 'circle/repo-name'); // TODO: Deprecated, remove.
Expand Down Expand Up @@ -242,7 +252,9 @@ COMMIT_MESSAGE:Sinon stubs are lovely`);
it('has the correct properties', function() {
assert.strictEqual(environment.ci, 'codeship');
assert.strictEqual(environment.commitSha, 'codeship-commit-sha');
assert.strictEqual(environment.targetCommitSha, null);
assert.strictEqual(environment.branch, 'codeship-branch');
assert.strictEqual(environment.targetBranch, null);
assert.strictEqual(environment.pullRequestNumber, null);
assert.strictEqual(environment.project, null);
assert.strictEqual(environment.repo, null); // TODO: Deprecated, remove.
Expand All @@ -265,7 +277,9 @@ COMMIT_MESSAGE:Sinon stubs are lovely`);
it('has the correct properties', function() {
assert.strictEqual(environment.ci, 'drone');
assert.strictEqual(environment.commitSha, 'drone-commit-sha');
assert.strictEqual(environment.targetCommitSha, null);
assert.strictEqual(environment.branch, 'drone-branch');
assert.strictEqual(environment.targetBranch, null);
assert.strictEqual(environment.pullRequestNumber, '123');
assert.strictEqual(environment.project, null);
assert.strictEqual(environment.repo, null); // TODO: Deprecated, remove.
Expand All @@ -291,7 +305,9 @@ COMMIT_MESSAGE:Sinon stubs are lovely`);
it('has the correct properties', function() {
assert.strictEqual(environment.ci, 'semaphore');
assert.strictEqual(environment.commitSha, 'semaphore-commit-sha');
assert.strictEqual(environment.targetCommitSha, null);
assert.strictEqual(environment.branch, 'semaphore-branch');
assert.strictEqual(environment.targetBranch, null);
assert.strictEqual(environment.pullRequestNumber, '123');
assert.strictEqual(environment.project, null);
assert.strictEqual(environment.repo, 'repo-owner/repo-name'); // TODO: Deprecated, remove.
Expand All @@ -317,7 +333,9 @@ COMMIT_MESSAGE:Sinon stubs are lovely`);
it('has the correct properties', function() {
assert.strictEqual(environment.ci, 'buildkite');
assert.strictEqual(environment.commitSha, 'buildkite-commit-sha');
assert.strictEqual(environment.targetCommitSha, null);
assert.strictEqual(environment.branch, 'buildkite-branch');
assert.strictEqual(environment.targetBranch, null);
assert.strictEqual(environment.pullRequestNumber, null);
assert.strictEqual(environment.project, null);
assert.strictEqual(environment.repo, null); // TODO: Deprecated, remove.
Expand Down Expand Up @@ -362,7 +380,9 @@ COMMIT_MESSAGE:Sinon stubs are lovely`);
it('has the correct properties', function() {
assert.strictEqual(environment.ci, 'heroku');
assert.strictEqual(environment.commitSha, 'heroku-commit-sha');
assert.strictEqual(environment.targetCommitSha, null);
assert.strictEqual(environment.branch, 'heroku-branch');
assert.strictEqual(environment.targetBranch, null);
assert.strictEqual(environment.pullRequestNumber, null);
assert.strictEqual(environment.project, null);
assert.strictEqual(environment.parallelNonce, 'heroku-test-run-id');
Expand Down
1 change: 1 addition & 0 deletions test/main-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('PercyClient', function() {
attributes: {
branch: commitData.branch,
'target-branch': percyClient.environment.targetBranch,
'target-commit-sha': percyClient.environment.targetCommitSha,
'commit-sha': commitData.sha,
'commit-committed-at': commitData.committedAt,
'commit-author-name': commitData.authorName,
Expand Down