Skip to content

Commit

Permalink
v1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
RizkyRajitha committed Sep 1, 2020
1 parent 583bbba commit ddca983
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 64 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ jobs:
with:
TELEGRAM_BOT_ID: ${{ secrets.TELEGRAM_BOT_ID }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
STATUS: true
CUSTOMMESSAGE: "Testing Gihub \xF0\x9F\x94\xAC Action For Telegram Notify Action \xF0\x9F\x94\xAE "
CUSTOMMESSAGESUCCESS: "Testing Gihub \xF0\x9F\x94\xAC Action For Telegram Notify Action \xF0\x9F\x94\xAE . \nSuccessful"
CUSTOMMESSAGESFAILURE: "Testing Gihub \xF0\x9F\x94\xAC Action For Telegram Notify Action \xE2\x9D\x8C . \nFailed"
CUSTOMMESSAGESCANCELLED: "Testing Gihub \xF0\x9F\x94\xAC Action For Telegram Notify Action . \nCancelled"
JOBSTATUS: ${{ job.status }}
GITHUB_RUN_NUMBER: ${{ github.run_number }}
GITHUB_REPOSITORY: ${{ github.repository }}
Expand Down
20 changes: 12 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@ inputs:
description: "ID of the chat. Telegram bot will send message to this chat"
required: true
default: "null"
STATUS: # id of input
description: "status of the workflow . pass status true || false in 2 if conditions "
required: true
default: "true"
CUSTOMMESSAGE:
description: "Notify message send via the Telegram bot"
CUSTOMMESSAGESUCCESS:
description: "Notify message send via the Telegram bot when success"
required: true
default: "Successfully Completed Github Action"
CUSTOMMESSAGESFAILURE:
description: "Notify message send via the Telegram bot when failed"
required: true
default: "Github Action Failed"
CUSTOMMESSAGESCANCELLED:
description: "Notify message send via the Telegram bot when cancelled"
required: true
default: "Github Action Cancled"

JOBSTATUS:
description: Job status"
required: false
default: "false"
required: true
default: "success"

GITHUB_RUN_NUMBER:
description: "GitHub Run Number"
Expand Down
45 changes: 38 additions & 7 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

75 changes: 29 additions & 46 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ async function run() {
try {
const TELEGRAM_BOT_ID = core.getInput("TELEGRAM_BOT_ID");
const TELEGRAM_CHAT_ID = core.getInput("TELEGRAM_CHAT_ID");
const CUSTOMMESSAGE =
core.getInput("CUSTOMMESSAGE") || "Successfully Completed Github Action";
const STATUS = core.getInput("STATUS") || true;
const CUSTOMMESSAGESUCCESS =
core.getInput("CUSTOMMESSAGESUCCESS") ||
"Successfully Completed Github Action";
const CUSTOMMESSAGESFAILURE =
core.getInput("CUSTOMMESSAGESFAILURE") || "Github Action Failed";

const CUSTOMMESSAGESCANCELLED =
core.getInput("CUSTOMMESSAGESCANCELLED") || "Github Action Cancelled";

// const STATUS = core.getInput("STATUS") || true;
//${{ job.status }}
const JOBSTATUS = core.getInput("JOBSTATUS") || false;
const JOBSTATUS = core.getInput("JOBSTATUS") || "success";

// : "${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}"}]
const GITHUB_RUN_NUMBER = core.getInput("GITHUB_RUN_NUMBER") || 0;
Expand All @@ -20,49 +27,25 @@ async function run() {
const GITHUB_EVENT_NAME = core.getInput("GITHUB_EVENT_NAME") || "";
const GITHUB_SHA = core.getInput("GITHUB_SHA") || 0;

let msg =
STATUS === "true"
? `${CUSTOMMESSAGE} \xE2\x9C\x85 \n${
JOBSTATUS ? "Job status : " + JOBSTATUS + "\n" : ""
} ${
GITHUB_RUN_NUMBER
? "GitHub Run Number : " + GITHUB_RUN_NUMBER + "\n"
: ""
} ${
GITHUB_REPOSITORY
? "GitHub Repository : " + GITHUB_REPOSITORY + "\n"
: ""
}
${GITHUB_RUN_ID ? "GitHub Run ID : " + GITHUB_RUN_ID + "\n" : ""}
${GITHUB_ACTOR ? "Triggered user : " + GITHUB_ACTOR + "\n" : ""}
${
GITHUB_EVENT_NAME
? "Triggered event : " + GITHUB_EVENT_NAME + "\n"
: ""
}
${GITHUB_SHA ? "GitHub commit SHA : " + GITHUB_SHA + "\n" : ""}
let msg = "";

if (JOBSTATUS === "success") {
msg = `${CUSTOMMESSAGESUCCESS} \xE2\x9C\x85 \n`;
} else if (JOBSTATUS === "failure") {
msg = ` ${CUSTOMMESSAGESFAILURE} " \xE2\x9D\x8C \n`;
} else {
msg = ` ${CUSTOMMESSAGESCANCELLED} " \xE2\x9D\x8C \n`;
}

`
: ` ${CUSTOMMESSAGE} " \xE2\x9D\x8C \n${
JOBSTATUS ? "Job status : " + JOBSTATUS + "\n" : ""
} ${
GITHUB_RUN_NUMBER
? "GitHub Run Number : " + GITHUB_RUN_NUMBER + "\n"
: ""
} ${
GITHUB_REPOSITORY
? "GitHub Repository : " + GITHUB_REPOSITORY + "\n"
: ""
}
${GITHUB_RUN_ID ? "GitHub Run ID : " + GITHUB_RUN_ID + "\n" : ""}
${GITHUB_ACTOR ? "Triggered user : " + GITHUB_ACTOR + "\n" : ""}
${
GITHUB_EVENT_NAME
? "Triggered event : " + GITHUB_EVENT_NAME + "\n"
: ""
}
${GITHUB_SHA ? "GitHub commit SHA : " + GITHUB_SHA + "\n" : ""}
`;
msg =
msg +
`${JOBSTATUS ? "Job status : " + JOBSTATUS + "\n" : ""}
${GITHUB_RUN_NUMBER ? "GitHub Run Number : " + GITHUB_RUN_NUMBER + "\n" : ""}
${GITHUB_REPOSITORY ? "GitHub Repository : " + GITHUB_REPOSITORY + "\n" : ""}
${GITHUB_RUN_ID ? "GitHub Run ID : " + GITHUB_RUN_ID + "\n" : ""}
${GITHUB_ACTOR ? "Triggered user : " + GITHUB_ACTOR + "\n" : ""}
${GITHUB_EVENT_NAME ? "Triggered event : " + GITHUB_EVENT_NAME + "\n" : ""}
${GITHUB_SHA ? "GitHub commit SHA : " + GITHUB_SHA + "\n" : ""} `;

let data = await fetch(
`https://api.telegram.org/bot${TELEGRAM_BOT_ID}/sendMessage?chat_id=${TELEGRAM_CHAT_ID}&text=${msg}`,
Expand Down

0 comments on commit ddca983

Please sign in to comment.