mirror of
https://github.com/SethCohen/github-releases-to-discord
synced 2026-09-14 20:13:23 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c811a53b57 | ||
|
|
e67e0f9064 | ||
|
|
d76d7aafe4 | ||
|
|
a809bb6f0e | ||
|
|
998060befe | ||
|
|
27e9acb517 |
@@ -1,7 +1,7 @@
|
|||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
types: [published]
|
types: [published]
|
||||||
name: github-release-to-discord
|
name: test-action
|
||||||
jobs:
|
jobs:
|
||||||
github-release-to-discord:
|
github-release-to-discord:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -9,7 +9,6 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: Github Releases To Discord
|
- name: Github Releases To Discord
|
||||||
uses: SethCohen/github-release-to-discord@v1.12.0
|
uses: ./ # Uses an action in the root directory
|
||||||
id: release
|
|
||||||
with:
|
with:
|
||||||
webhook_url: ${{ secrets.WEBHOOK_URL }}
|
webhook_url: ${{ secrets.WEBHOOK_URL }}
|
||||||
@@ -1,5 +1,12 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [1.13.0](https://github.com/SethCohen/github-release-to-discord/compare/v1.12.1...v1.13.0) (2022-08-25)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* created test action ([d76d7aa](https://github.com/SethCohen/github-release-to-discord/commit/d76d7aafe49eadfc8d388bef38a8d3fb0230041b))
|
||||||
|
|
||||||
## [1.12.1](https://github.com/SethCohen/github-release-to-discord/compare/v1.12.0...v1.12.1) (2022-08-24)
|
## [1.12.1](https://github.com/SethCohen/github-release-to-discord/compare/v1.12.0...v1.12.1) (2022-08-24)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,19 +2,8 @@
|
|||||||
A GitHub action that parses a GitHub release and posts it to a Discord channel as a stylized Discord webhook.
|
A GitHub action that parses a GitHub release and posts it to a Discord channel as a stylized Discord webhook.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
## Output
|
||||||
## Setup Instructions
|

|
||||||
1. Open your **Server Settings** and head into the **Integrations** tab:
|
|
||||||
2. Click the "**Create Webhook**" button to create a new webhook!
|
|
||||||

|
|
||||||

|
|
||||||
3. Copy the webhook url
|
|
||||||
4. Create a new Github repository secret called WEBHOOK_URL and paste the webhook url into it.
|
|
||||||

|
|
||||||
5. Save the secret.
|
|
||||||
6. Add the secret to your action configuration.
|
|
||||||
|
|
||||||
And you're done!
|
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
@@ -25,12 +14,9 @@ And you're done!
|
|||||||
| username | ❌ | "Release Changelog" | String username for webhook. |
|
| username | ❌ | "Release Changelog" | String username for webhook. |
|
||||||
| avatar_url | ❌ | ["Profile Picture"](https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png) | String url to webhook avatar picture. |
|
| avatar_url | ❌ | ["Profile Picture"](https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png) | String url to webhook avatar picture. |
|
||||||
|
|
||||||
|
|
||||||
## Output
|
|
||||||

|
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
|
`.github/workflows/github-release-to-discord.yml`
|
||||||
```yaml
|
```yaml
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
@@ -50,3 +36,16 @@ jobs:
|
|||||||
username: "Release Changelog"
|
username: "Release Changelog"
|
||||||
avatar_url: "https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png"
|
avatar_url: "https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Setup Instructions
|
||||||
|
1. Open your **Server Settings** and head into the **Integrations** tab:
|
||||||
|
2. Click the "**Create Webhook**" button to create a new webhook!
|
||||||
|

|
||||||
|

|
||||||
|
3. Copy the webhook url
|
||||||
|
4. Create a new Github repository secret called WEBHOOK_URL and paste the webhook url into it.
|
||||||
|

|
||||||
|
5. Save the secret.
|
||||||
|
6. Add the secret to your action configuration.
|
||||||
|
|
||||||
|
And you're done! Whenever you create a new release, the workflow should run and, if properly setup, post to your specified Discord channel.
|
||||||
|
|||||||
@@ -2,6 +2,31 @@ import core from '@actions/core';
|
|||||||
import github from '@actions/github';
|
import github from '@actions/github';
|
||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stylizes a markdown body into an appropriate embed message style.
|
||||||
|
* H3s converted to bold and underlined.
|
||||||
|
* H2s converted to bold.
|
||||||
|
* Redundant whitespace and newlines removed.
|
||||||
|
* @param description
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
const formatDescription = (description) => {
|
||||||
|
return description
|
||||||
|
.replace(/### (.*?)\n/g,function (substring) {
|
||||||
|
const newString = substring.slice(4).replace(/(\r\n|\n|\r)/gm, "")
|
||||||
|
return `**__${newString}__**`
|
||||||
|
})
|
||||||
|
.replace(/## (.*?)\n/g,function (substring) {
|
||||||
|
const newString = substring.slice(3).replace(/(\r\n|\n|\r)/gm, "")
|
||||||
|
return `**${newString}**`
|
||||||
|
})
|
||||||
|
.replace(/\n\s*\n/g, '\n')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the context of the action, returns a GitHub Release payload.
|
||||||
|
* @returns {Promise<{html_url, body: (*|string), version: string}>}
|
||||||
|
*/
|
||||||
async function getContext () {
|
async function getContext () {
|
||||||
const payload = github.context.payload
|
const payload = github.context.payload
|
||||||
|
|
||||||
@@ -14,52 +39,47 @@ async function getContext () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the action.
|
||||||
|
* Get inputs, creates a stylized response webhook, and sends it to the channel.
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
async function run () {
|
async function run () {
|
||||||
try {
|
const webhookUrl = core.getInput('webhook_url')
|
||||||
const webhookUrl = core.getInput('webhook_url')
|
const color = core.getInput('color')
|
||||||
const color = core.getInput('color')
|
const username = core.getInput('username')
|
||||||
const username = core.getInput('username')
|
const avatarUrl = core.getInput('avatar_url')
|
||||||
const avatarUrl = core.getInput('avatar_url')
|
|
||||||
|
|
||||||
if (!webhookUrl) {
|
if (!webhookUrl) return core.setFailed('webhook_url not set. Please set it.')
|
||||||
return core.setFailed('webhook_url not set. Please set it.')
|
|
||||||
}
|
|
||||||
|
|
||||||
const content = await getContext()
|
const {body, html_url, version} = await getContext()
|
||||||
|
|
||||||
const description = content.body
|
const description = formatDescription(body)
|
||||||
.replace(/### (.*?)\n/g,function (substring) {
|
|
||||||
const newString = substring.slice(4).replace(/(\r\n|\n|\r)/gm, "")
|
|
||||||
return `**__${newString}__**`
|
|
||||||
})
|
|
||||||
.replace(/## (.*?)\n/g,function (substring) {
|
|
||||||
const newString = substring.slice(3).replace(/(\r\n|\n|\r)/gm, "")
|
|
||||||
return `**${newString}**`
|
|
||||||
})
|
|
||||||
.replace(/\n\s*\n/g, '\n')
|
|
||||||
|
|
||||||
const embedMsg = {
|
const embedMsg = {
|
||||||
title: `Release ${content.version}`,
|
title: `Release ${version}`,
|
||||||
url: content.html_url,
|
url: html_url,
|
||||||
color: color,
|
color: color,
|
||||||
description: description,
|
description: description
|
||||||
}
|
|
||||||
|
|
||||||
const body = { username: username, avatar_url: avatarUrl, embeds: [embedMsg], }
|
|
||||||
|
|
||||||
const url = `${webhookUrl}?wait=true`
|
|
||||||
|
|
||||||
fetch(url, {
|
|
||||||
method: 'post',
|
|
||||||
body: JSON.stringify(body),
|
|
||||||
headers: { 'Content-Type': 'application/json' }
|
|
||||||
})
|
|
||||||
.then(res => res.json())
|
|
||||||
.then(data => core.info(JSON.stringify(data)))
|
|
||||||
.catch(err => core.info(err))
|
|
||||||
} catch (error) {
|
|
||||||
core.setFailed(error.message)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const requestBody = {
|
||||||
|
username: username,
|
||||||
|
avatar_url: avatarUrl,
|
||||||
|
embeds: [embedMsg]
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = `${webhookUrl}?wait=true`
|
||||||
|
fetch(url, {
|
||||||
|
method: 'post',
|
||||||
|
body: JSON.stringify(requestBody),
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
})
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(data => core.info(JSON.stringify(data)))
|
||||||
|
.catch(err => core.info(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
.then(() => {core.info('Action completed successfully')})
|
||||||
|
.catch(err => {core.setFailed(err.message)})
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "github-release-to-discord",
|
"name": "github-release-to-discord",
|
||||||
"version": "1.9.0",
|
"version": "1.12.1",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
|
|||||||
Generated
+3
-3
@@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "github-release-to-discord",
|
"name": "github-release-to-discord",
|
||||||
"version": "1.12.1",
|
"version": "1.13.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "github-release-to-discord",
|
"name": "github-release-to-discord",
|
||||||
"version": "1.12.1",
|
"version": "1.13.0",
|
||||||
"license": "ISC",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.9.1",
|
"@actions/core": "^1.9.1",
|
||||||
"@actions/github": "^5.0.3",
|
"@actions/github": "^5.0.3",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "github-release-to-discord",
|
"name": "github-release-to-discord",
|
||||||
"version": "1.12.1",
|
"version": "1.13.0",
|
||||||
"description": "Github Action that parses a release and sends it to a Discord channel",
|
"description": "Github Action that parses a release and sends it to a Discord channel",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
|||||||
Reference in New Issue
Block a user