Skip to content

Commit

Permalink
Merge pull request #1 from ctinnovation/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
andrea-avanzi authored Nov 1, 2021
2 parents 97bc8ab + c35d301 commit 4868507
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 83 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This repository is generated by [typescript-action](https://github.com/actions/t
|Name|Required|Description|
|:---:|:---:|:---|
|name|true|Job name. Used for notification titles.|
|buildNumber|false|Build number|
|url|true|Google Chat Webhook URL.|
|status|true|Job status. Available values are `success`, `failure`, `cancelled`. We recommend using `${{ job.status }}`|

Expand Down
55 changes: 13 additions & 42 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,8 @@ function run() {
const url = core.getInput('url', { required: true });
const status = JobStatus.parse(core.getInput('status', { required: true }));
const artifactUrl = core.getInput('artifactUrl', { required: true });
const repoRef = core.getInput('repoRef', { required: false });
core.debug(`input params: name=${name}, status=${status}, url=${url}, artifactUrl=${artifactUrl}`);
yield GoogleChat.notify(repoRef, name, url, status, artifactUrl);
yield GoogleChat.notify(name, url, status, artifactUrl);
console.info('Sent message.');
}
catch (error) {
Expand Down Expand Up @@ -2474,68 +2473,40 @@ const textButton = (text, url) => ({
onClick: { openLink: { url } }
}
});
function notify(repoRef, name, url, status, artifactUrl) {
function notify(name, url, status, artifactUrl) {
return __awaiter(this, void 0, void 0, function* () {
const { owner, repo } = github.context.repo;
const { eventName, sha, ref, runId } = github.context;
const { eventName, sha, ref, runId, runNumber } = github.context;
const { number } = github.context.issue;
const repoUrl = `https://github.com/${owner}/${repo}`;
const eventPath = eventName === 'pull_request' ? `/pull/${number}` : `/commit/${sha}`;
const eventUrl = `${repoUrl}${eventPath}`;
const checksUrl = `${repoUrl}${eventPath}/checks`;
const eventPath = eventName === 'pull_request' ? `/pull/${number}` : `/commit/${sha.substring(0, 8)}`;
const jobUrl = `${repoUrl}/actions/runs/${runId}`;
const body = {
cards: [{
"header": {
"title": repo,
"subtitle": ((repoRef) ? repoRef : ref),
"subtitle": name,
"imageUrl": "https://lh3.googleusercontent.com/proxy/p3mSfQtf-xADb2Us8knTTzMHpQwoBKW5JU3ZISKETZMJ72D3uQMJ9Xa2JbRM1vuYVev448pQU2VgOaz0RCMq0GnlfvX20ruFgNdM9XKmDOTlIgw6yocpurQ=s64-c",
"imageStyle": "IMAGE"
},
sections: [
{
widgets: [
{
"textParagraph": {
"text": `<b>Commit ID:</b> ${sha.substring(0, 8)}<br><b>Status:</b> <font color="${statusColorPalette[status]}">${statusText[status]}</font><br><b>Event:</b> ${eventName}`
"keyValue": {
"topLabel": "Build #",
"content": `<b>${runNumber}</b> - <b><font color="${statusColorPalette[status]}">${statusText[status]}</font></b>`,
"button": textButton("JOB DETAILS", jobUrl)
}
},
{
keyValue: {
topLabel: "Artifact",
contentMultiline: "true",
content: `${name}`,
button: {
textButton: {
text: "GET IT",
onClick: {
openLink: {
url: `https://www.google.com/url?q=${artifactUrl}`
}
}
}
}
"keyValue": {
"topLabel": "Event Ref.",
"content": eventPath,
"button": textButton("DOWNLOAD", `https://www.google.com/url?q=${artifactUrl}`)
}
}
]
},
{
widgets: [
{
buttons: [
{
textButton: {
text: "JOB DETAILS",
onClick: {
openLink: {
url: `${jobUrl}`
}
}
}
}
]
}
]
}
]
}]
Expand Down
52 changes: 13 additions & 39 deletions src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,66 +21,40 @@ const textButton = (text: string, url: string) => ({
}
});

export async function notify(repoRef: string, name: string, url: string, status: Status, artifactUrl: string) {
export async function notify( name: string,url: string, status: Status, artifactUrl: string) {
const { owner, repo } = github.context.repo;
const { eventName, sha, ref, runId } = github.context;
const { eventName, sha, ref, runId, runNumber } = github.context;
const { number } = github.context.issue;
const repoUrl = `https://github.com/${owner}/${repo}`;
const eventPath = eventName === 'pull_request' ? `/pull/${number}` : `/commit/${sha}`;
const eventUrl = `${repoUrl}${eventPath}`;
const checksUrl = `${repoUrl}${eventPath}/checks`;
const eventPath = eventName === 'pull_request' ? `/pull/${number}` : `/commit/${sha.substring(0, 8)}`;
const jobUrl = `${repoUrl}/actions/runs/${runId}`;

const body = {
cards: [{

"header": {
"title": repo,
"subtitle": ((repoRef) ? repoRef : ref),
"subtitle": name,
"imageUrl": "https://lh3.googleusercontent.com/proxy/p3mSfQtf-xADb2Us8knTTzMHpQwoBKW5JU3ZISKETZMJ72D3uQMJ9Xa2JbRM1vuYVev448pQU2VgOaz0RCMq0GnlfvX20ruFgNdM9XKmDOTlIgw6yocpurQ=s64-c",
"imageStyle": "IMAGE"
},
sections: [
{
widgets: [
{
"textParagraph": {
"text": `<b>Commit ID:</b> ${sha.substring(0, 8)}<br><b>Status:</b> <font color="${statusColorPalette[status]}">${statusText[status]}</font><br><b>Event:</b> ${eventName}`
"keyValue": {
"topLabel": "Build #",
"content": `<b>${runNumber}</b> - <b><font color="${statusColorPalette[status]}">${statusText[status]}</font></b>`,
"button": textButton("JOB DETAILS", jobUrl)

}
},
{
keyValue: {
topLabel: "Artifact",
contentMultiline: "true",
content: `${name}`,
button: {
textButton: {
text: "GET IT",
onClick: {
openLink: {
url: `https://www.google.com/url?q=${artifactUrl}`
}
}
}
"keyValue": {
"topLabel": "Event Ref.",
"content": eventPath,
"button": textButton("DOWNLOAD", `https://www.google.com/url?q=${artifactUrl}`)
}
}
}
]
},
{
widgets: [
{
buttons: [
{
textButton: {
text: "JOB DETAILS",
onClick: {
openLink: {
url: `${jobUrl}`
}
}
}
}]
}
]
}
Expand Down
3 changes: 1 addition & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ async function run() {
const url = core.getInput('url', { required: true });
const status = JobStatus.parse(core.getInput('status', { required: true }));
const artifactUrl = core.getInput('artifactUrl', { required: true });
const repoRef = core.getInput('repoRef', { required: false });

core.debug(`input params: name=${name}, status=${status}, url=${url}, artifactUrl=${artifactUrl}`);

await GoogleChat.notify(repoRef, name, url, status, artifactUrl);
await GoogleChat.notify(name, url, status, artifactUrl);
console.info('Sent message.')
} catch (error) {
core.setFailed(error.message);
Expand Down

0 comments on commit 4868507

Please sign in to comment.