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

More logging on slack hook error #67

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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: 3 additions & 1 deletion docker-compose.minio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ services:
ports:
- 27017:27017
director:
image: agoldis/sorry-cypress-director:latest
build:
dockerfile: packages/director/Dockerfile
context: .
environment:
DASHBOARD_URL: http://localhost:8080
EXECUTION_DRIVER: '../execution/mongo/driver'
Expand Down
62 changes: 57 additions & 5 deletions packages/director/src/lib/hooks/reporters/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,40 @@ export async function reportToSlack(
} *Passed:* ${passes}\n\n\n` +
`${
failures > 0 ? ':red_circle:' : ':white_circle:'
} *Failed*: ${failures}` +
`${skipped > 0 ? ':red_circle:' : ':white_circle:'} *Skipped*: ${skipped}` +
} *Failed*: ${failures}\n\n\n` +
`${
skipped > 0 ? ':red_circle:' : ':white_circle:'
} *Skipped*: ${skipped}\n\n\n` +
`${
pending > 0 ? ':large_yellow_circle:' : ':white_circle:'
} *Ignored:* ${pending}\n\n\n` +
`${flaky > 0 ? `\n\n\n:large_yellow_circle: *Flaky*: ${flaky}` : ''}`;
`${
flaky > 0 ? `:large_yellow_circle: *Flaky*: ${flaky}` : ''}`;


let commitDescription ;

if (event.run.meta.commit?.remoteOrigin?.startsWith('https://github.com')){

const branchLink = (event.run.meta.commit?.remoteOrigin || event.run.meta.commit?.branch) &&
`${event.run.meta.commit.remoteOrigin?.replace("\.git", '')}/${event.run.meta.commit.branch}`;

const commitLink = (event.run.meta.commit?.remoteOrigin || event.run.meta.commit?.sha) &&
`${event.run.meta.commit.remoteOrigin?.replace("\.git", '')}/${event.run.meta.commit.sha}`;

const commitDescription =
const sanitizedCommitMessage = (event.run.meta.commit?.message) &&
`${truncate(event.run.meta.commit?.message,{ length: 100 ,}).replace("\r", '').replace("\n", '')}`;


commitDescription =
(event.run.meta.commit?.branch || branchLink || event.run.meta.commit.authorName || commitLink || sanitizedCommitMessage) &&
`*Branch:*\n<${branchLink}|${event.run.meta.commit.branch}>
\n*Commit:*\n<${commitLink}|${sanitizedCommitMessage}>
\n*Author:*\n${event.run.meta.commit.authorName}\n\n`;

} else {

commitDescription =
(event.run.meta.commit?.branch || event.run.meta.commit?.message) &&
`*Branch:*\n${event.run.meta.commit.branch}\n\n*Commit:*\n${truncate(
event.run.meta.commit.message,
Expand All @@ -95,6 +121,8 @@ export async function reportToSlack(
}
)}`;

}

axios({
method: 'post',
url: hook.url,
Expand Down Expand Up @@ -146,7 +174,31 @@ export async function reportToSlack(
],
icon_url: 'https://sorry-cypress.s3.amazonaws.com/images/logo-bg.png',
},
}).catch((error) => {
}).then(function (response) {
console.log("[CUSTOM] SLACK HOOK SUCESS");
console.log(response.data);
console.log(response.status);
console.log(response.statusText);
console.log(response.headers);
console.log(response.config);
})
.catch((error) => {
console.log("[CUSTOM] SLACK HOOK ERROR");
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
}
getLogger().error(
{ error, ...hook },
`Error while posting Slack message to ${hook.url}`
Expand Down