forked from kohchihao/tele-status
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1f67508
Showing
9 changed files
with
1,474 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Koh Chi Hao | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# tele-status | ||
|
||
Tele-status connects your GitHub Repo to Telegram about Repo Updates by a Bot you can create. | ||
|
||
Create a chatbot with **botfather** bot in telegram. Get your chat id by speaking to **jsondumpbot** in telegram. | ||
|
||
Since it is your repo and it should only be limited to you. Thats why you need to give your chat id to the bot. You can either give your **personal chat id** or a **channel chat id** and add the bot to it. | ||
|
||
You can add these details to the Repository Secrets by going to `<repo>/settings/secrets/` | ||
|
||
## Notifications | ||
- You can use the simple notifier at the master branch or the release tag like | ||
```yml | ||
- name: <WorkFlow Name> | ||
uses: kohchihao/tele-status@master | ||
if: always() | ||
with: | ||
chat: ${{ secrets.chat }} | ||
token: ${{ secrets.token }} | ||
status: ${{ job.status }} | ||
|
||
``` | ||
The `chat` is the chat id/channel id and you can get that by talking to the json dump bot. The `token` is the bot's API token and you can create a bot by speaking to Botfather bot in Telegram. | ||
|
||
Actions will only trigger on what you want to trigger. You might want to define all the triggers first. You can refer the workflow file of this repo for better guidance. or like this | ||
|
||
```yml | ||
name: Build and Notify | ||
on: | ||
push: | ||
pull_request: | ||
types: [opened,closed] | ||
issues: | ||
types: [opened, closed, reopened] | ||
issue_comment: | ||
types: [created] | ||
watch: | ||
types: [started] | ||
``` | ||
## Credits | ||
Forked and cloned from https://github.com/athul/telewire |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: 'Tele-status' | ||
description: 'Connect your GitHub Repo to Telegram' | ||
author: 'kohchihao' | ||
inputs: | ||
chat: | ||
description: 'Chat to send: chat id or @channel_name' | ||
required: true | ||
token: | ||
description: 'Telegram Bot token' | ||
required: true | ||
status: | ||
description: 'Job status' | ||
required: true | ||
stargazers: | ||
description: 'Get Stars of the Repo' | ||
default: ${{ github.event.repository.stargazers_count }} | ||
forkers: | ||
description: 'Number of Forks' | ||
default: ${{ github.event.repository.forks_count }} | ||
iu_title: | ||
description: 'Issue Title' | ||
default: ${{ github.event.issue.title }} | ||
iu_num: | ||
description: 'Issue Number' | ||
default: ${{ github.event.issue.number }} | ||
iu_actor: | ||
description: 'Issue Triggerer' | ||
default: ${{ github.event.issue.user.login }} | ||
iu_body: | ||
description: 'Issue Body' | ||
default: ${{ github.event.issue.body }} | ||
iu_com: | ||
description: 'Issue Comment' | ||
default: ${{github.event.comment.body}} | ||
pr_state: | ||
description: 'State of the PR' | ||
default: ${{ github.event.action }} | ||
pr_num: | ||
description: 'PR Number' | ||
default: ${{ github.event.number }} | ||
pr_title: | ||
description: 'Title of the PR' | ||
default: ${{ github.event.pull_request.title }} | ||
pr_body: | ||
description: 'Body/Contents of the PR' | ||
default: ${{ github.event.pull_request.body }} | ||
pr_commit_message: | ||
description: 'Commit message' | ||
default: ${{ github.event.head_commit.message }} | ||
pr_branch_name: | ||
description: 'PR Branch name' | ||
default: ${{ github.ref }} | ||
workflow_success: | ||
description: 'Workflow Success' | ||
default: ${{ success() }} | ||
workflow_failure: | ||
description: 'Workflow Failure' | ||
default: ${{ failure() }} | ||
runs: | ||
using: 'node12' | ||
main: 'dist/`index.js' | ||
branding: | ||
icon: 'repeat' | ||
color: 'green' |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require('dotenv').config; | ||
const Bot = require('node-telegram-bot-api'); | ||
const { | ||
INPUT_STATUS: status, | ||
INPUT_TOKEN: tgToken, | ||
INPUT_CHAT: chatId, | ||
INPUT_IU_TITLE: title, | ||
INPUT_IU_NUM: num, | ||
INPUT_IU_ACTOR: actor, | ||
INPUT_IU_BODY: body, | ||
INPUT_PR_NUM: prNum, | ||
INPUT_PR_STATE: prState, | ||
INPUT_PR_TITLE: prTitle, | ||
INPUT_PR_BODY: prBody, | ||
GITHUB_EVENT_NAME: ghEvent, | ||
GITHUB_REPOSITORY: repo, | ||
GITHUB_ACTOR: ghActor, // the actor that trigger the workflow | ||
GITHUB_SHA: sha, | ||
GITHUB_WORKFLOW: ghWorkflow, | ||
INPUT_PR_COMMIT_MESSAGE: prCommitMessage, | ||
INPUT_PR_BRANCH_NAME: prBranchName, | ||
WORKFLOW_SUCCESS: workflowSuccess, | ||
WORKFLOW_FAILURE: workflowFailure, | ||
} = process.env; | ||
|
||
const bot = new Bot(tgToken); | ||
|
||
const buildPrContent = () => { | ||
let buildStatus = 'Unknown'; | ||
if (workflowSuccess) { | ||
buildStatus = 'Success'; | ||
} else if (workflowFailure) { | ||
buildStatus = 'Failure'; | ||
} | ||
let message = | ||
'-------------------------------------\n' + | ||
`Workflow build <b>${buildStatus}!</b>\n` + | ||
`Title: ${title}\n` + | ||
`Branch: ${prBranchName}\n` + | ||
`User: ${ghActor}\n` + | ||
'<b>Commit Msg:</b>\n' + | ||
`${prCommitMessage}\n\n` + | ||
`<a href="https://github.com/${repo}/commit/${sha}/checks">Job Log here</a>\n` + | ||
`<a href="https://github.com/${repo}/pull/${prNum}">Link to issue/PR</a>\n` + | ||
'--------------------------------------'; | ||
return message; | ||
}; | ||
|
||
const evresp = (gevent) => { | ||
switch (gevent) { | ||
case 'pull_request': | ||
return buildPrContent(); | ||
} | ||
}; | ||
|
||
const output = evresp(ghEvent); | ||
bot.sendMessage(chatId, output, { parse_mode: 'html' }); |
Oops, something went wrong.