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

Use deployment-status ref instead of sha #915

Merged
merged 3 commits into from
Aug 21, 2019
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
8 changes: 8 additions & 0 deletions lib/activity/deployments.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
const cache = require('../cache');
const { DeploymentStatus } = require('../messages/deployment-status');

async function trackDeploymentStatus(context) {
const { ref, sha } = context.payload.deployment;
const hasCustomRef = ref && ref !== sha;
context.log({ hasCustomRef, ref, sha }, 'Processing deployment status');
}

async function deploymentStatus(context, subscription, slack) {
trackDeploymentStatus(context);

const deploymentStatusMessage = new DeploymentStatus({
deploymentStatus: context.payload.deployment_status,
deployment: context.payload.deployment,
Expand Down
18 changes: 10 additions & 8 deletions lib/messages/deployment-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@ class DeploymentStatus extends Message {
htmlURL: deployment.creator.html_url,
},
footer: `<${repository.html_url}|${repository.full_name}>`,

});
this.deploymentStatus = deploymentStatus;
this.deployment = deployment;
this.repository = repository;
this.shortSha = this.deployment.sha.substr(0, 7);

const { ref, sha } = deployment;
this.shortSha = sha.substr(0, 7);
this.prettyRef = ref && ref !== sha ? `${ref} (${this.shortSha})` : this.shortSha;
this.commitLink = `${this.repository.html_url}/commit/${this.deployment.sha}`;
}

getCore() {
// @todo show ref instead of sha if one exists
let center = `${this.shortSha}`;
let centerWithLink = `<${this.commitLink}|\`${this.shortSha}\`>`;
let center = `${this.prettyRef}`;

let centerWithLink = `<${this.commitLink}|\`${this.prettyRef}\`>`;
if (this.deployment.environment) {
center += ` to ${this.deployment.environment}`;
centerWithLink += this.deploymentStatus.target_url ?
` to <${this.deploymentStatus.target_url}|${this.deployment.environment}>` :
` to ${this.deployment.environment}`;
centerWithLink += this.deploymentStatus.target_url
? ` to <${this.deploymentStatus.target_url}|${this.deployment.environment}>`
: ` to ${this.deployment.environment}`;
}
if (this.deploymentStatus.state === 'pending') {
return {
Expand Down
40 changes: 40 additions & 0 deletions test/messages/__snapshots__/deployment-status.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Deployment status rendering uses ref and the short sha, when ref differs from the sha 1`] = `
Object {
"attachments": Array [
Object {
"author_icon": "https://avatars1.githubusercontent.com/u/7718702?v=4",
"author_link": "https://github.com/wilhelmklopp",
"author_name": "wilhelmklopp",
"color": "#28a745",
"fallback": "[github-slack/app] Successfully deployed master (3dce5c8) to github-slack-app",
"footer": "<https://github.com/github-slack/app|github-slack/app>",
"footer_icon": "https://github.githubassets.com/favicon.ico",
"mrkdwn_in": Array [
"text",
],
"text": "Successfully deployed <https://github.com/github-slack/app/commit/3dce5c8488afc87a1ffbb840fc33b4a8331a1034|\`master (3dce5c8)\`> to <https://dashboard.heroku.com/apps/github-slack-app/activity/builds/056df7bf-83c4-4ac1-911b-c8642413eef0|github-slack-app>",
},
],
}
`;

exports[`Deployment status rendering uses short sha if ref is unequal but null 1`] = `
Object {
"attachments": Array [
Object {
"author_icon": "https://avatars1.githubusercontent.com/u/7718702?v=4",
"author_link": "https://github.com/wilhelmklopp",
"author_name": "wilhelmklopp",
"color": "#28a745",
"fallback": "[github-slack/app] Successfully deployed 3dce5c8 to github-slack-app",
"footer": "<https://github.com/github-slack/app|github-slack/app>",
"footer_icon": "https://github.githubassets.com/favicon.ico",
"mrkdwn_in": Array [
"text",
],
"text": "Successfully deployed <https://github.com/github-slack/app/commit/3dce5c8488afc87a1ffbb840fc33b4a8331a1034|\`3dce5c8\`> to <https://dashboard.heroku.com/apps/github-slack-app/activity/builds/056df7bf-83c4-4ac1-911b-c8642413eef0|github-slack-app>",
},
],
}
`;

exports[`Deployment status rendering works for error status 1`] = `
Object {
"attachments": Array [
Expand Down
30 changes: 30 additions & 0 deletions test/messages/deployment-status.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,34 @@ describe('Deployment status rendering', () => {
});
expect(deploymentStatusMessage.toJSON()).toMatchSnapshot();
});
test('uses ref and the short sha, when ref differs from the sha', () => {
const deployment = {
...deploymentStatusSuccessFixture.deployment,
ref: 'master',
};
const deploymentStatusMessage = new DeploymentStatus({
deploymentStatus: deploymentStatusSuccessFixture.deployment_status,
deployment,
repository: deploymentStatusSuccessFixture.repository,
});

const message = deploymentStatusMessage.toJSON().attachments[0].text;
expect(message).toMatch(/successfully deployed.*master.*\(3dce5c8\)/i);
expect(deploymentStatusMessage.toJSON()).toMatchSnapshot();
});
test('uses short sha if ref is unequal but null', () => {
const deployment = {
...deploymentStatusSuccessFixture.deployment,
ref: null,
};
const deploymentStatusMessage = new DeploymentStatus({
deploymentStatus: deploymentStatusSuccessFixture.deployment_status,
deployment,
repository: deploymentStatusSuccessFixture.repository,
});

const message = deploymentStatusMessage.toJSON().attachments[0].text;
expect(message).toMatch(/successfully deployed.*3dce5c8.*/i);
expect(deploymentStatusMessage.toJSON()).toMatchSnapshot();
});
});