Skip to content

Commit

Permalink
feat: using webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
tsyl-dcrespo committed Apr 19, 2022
1 parent b51660f commit 458cde0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ You must use the changelog style generated by [Lerna](https://github.com/lerna/l
| Property | Default | Description |
| ------------- | :------------: | ------------------------------------ |
| CHANGELOGPATH | `CHANGELOG.md` | Changelog path. |
| CHANNELID | - | Discord channel id. |
| TOKEN | - | Discord bot token. |
| WEBHOOK | - | Discord webhook. |
| PROJECT | - | Project name. Used in message title. |

## Usage example
Expand Down
10 changes: 5 additions & 5 deletions src/lib/sendChangelogMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { RequestOptions } from "https";

import { changelogData } from "../types";

const CHANNELID = process.env.CHANNELID;
const TOKEN = process.env.TOKEN;
const WEBHOOK = process.env.WEBHOOK || "";
const PROJECT = process.env.PROJECT || "";

export function sendChangelogToChannel(changelog: changelogData) {
if (!WEBHOOK) throw new Error("WEBHOOK is not defined");
const msg = generateMsg(changelog);
sendMessage(msg);
}
Expand Down Expand Up @@ -56,15 +56,15 @@ function getEmojiSection(section: string) {
function sendMessage(message: string) {
const post_data = JSON.stringify({
content: message,
username: "Git up to date",
});

const post_options = {
host: "discordapp.com",
host: "discord.com",
port: 443,
path: `/api/channels/${CHANNELID}/messages`,
path: WEBHOOK.replace("https://discord.com", ""),
method: "POST",
headers: {
Authorization: `Bot ${TOKEN}`,
"Content-Type": "application/json",
"Content-Length": Buffer.byteLength(post_data),
},
Expand Down

0 comments on commit 458cde0

Please sign in to comment.