generated from clicampo/gh-action-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add discord support * fix: correct discord message * fix: correct discord message * fix: correct discord message
- Loading branch information
Showing
5 changed files
with
193 additions
and
1 deletion.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,65 @@ | ||
import fetch from 'node-fetch' | ||
import * as core from '@actions/core' | ||
|
||
export const notifyDiscordChannel = async(webhookUrl: string, options: { | ||
projectName: string | ||
projectUrl: string | ||
productionActionUrl: string | ||
nextVersion: string | ||
changelog: string | ||
isReleaseCandidate: boolean | ||
}) => { | ||
core.startGroup('Notifying Discord channel') | ||
const version = options.nextVersion + (options.isReleaseCandidate ? '-rc' : '') | ||
const payload = { | ||
username: '', | ||
avatar_url: '', | ||
content: `The project **${options.projectName}** has just released the version **${version}**!\n${ | ||
options.changelog | ||
// replace headings with bold text | ||
.replace(/#+ ([^\n]+)/g, '**$1**') | ||
// replace links with discord link syntax | ||
.replace(/\[([^\]]+)\]\(([^\)]+)\)/g, '<$2|$1>') | ||
.replace(/\- /g, '→') | ||
}`, | ||
embeds: [] as any[], | ||
components: [] as any[], | ||
} | ||
payload.embeds.push({ | ||
title: 'See project', | ||
url: options.projectUrl, | ||
}) | ||
payload.embeds.push({ | ||
title: 'Deploy to production', | ||
url: options.productionActionUrl, | ||
}) | ||
payload.components.push({ | ||
type: '1', | ||
components: [ | ||
{ | ||
type: 2, | ||
style: 5, | ||
label: 'See project', | ||
url: options.projectUrl, | ||
}, | ||
{ | ||
type: 2, | ||
style: 5, | ||
label: 'Deploy to production', | ||
url: options.productionActionUrl, | ||
}, | ||
], | ||
}) | ||
|
||
core.info(`Sending payload to Discord\n${JSON.stringify(payload, null, 4)}`) | ||
const response = await fetch(webhookUrl, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(payload), | ||
}) | ||
core.endGroup() | ||
return response | ||
} |
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