Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add templates for messages #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ The following inputs briefly explained here are fully declared and documented in

* `project_name` [**Required**] - Project name to display

* `release_template` - Release template (default: `New release available! {{projectName}}: {{version}}`)

* `changelog_template` - Changelog template (default: `Changelog: {{changelog}}`)

## Examples

Run this action on new tag push or new release!
Expand Down
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ inputs:
project_name:
description: 'Project name to display'
required: true
release_template:
description: Release template
default: 'New release available for {{projectName}}: {{version}} 🎉'
changelog_template:
description: Changelog template
default: 'Changelog: {{changelogUrl}}'

outputs:
status:
description: 'The status of message sent'
license:
description: 'The license used in the repository'

runs:
using: 'node20'
Expand Down
20 changes: 17 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15146,6 +15146,14 @@ const github = __nccwpck_require__(5438)
const https = __nccwpck_require__(5687)
const simpleGit = __nccwpck_require__(9103);

const renderTemplate = (template, args={}) => {
let finalRender = template;
for (const [key, value] of Object.entries(args)) {
finalRender = finalRender.replace(`{{${key}}}`, value);
}
return finalRender;
}

const main = async () => {
const currentRepoGit = simpleGit();
const tags = (await currentRepoGit.tags({'--sort' : 'taggerdate'})).all
Expand All @@ -15157,18 +15165,24 @@ const main = async () => {
const slackToken = core.getInput('slack_token')
const channelId = core.getInput('channel_id')
const projectName = core.getInput('project_name')
const releaseTemplate = core.getInput('release_template')
const changelogTemplate = core.getInput('changelog_template')

const payload = JSON.stringify({
channel: channelId,
token: slackToken,
attachments: [
{
pretext : `Rilasciata la nuova versione di ${projectName}: ${version}!`,
text : `Changelog disponibile qua: ${changelogUrl}`,
pretext : renderTemplate(releaseTemplate, {
projectName: projectName,
version: version
}), // `Nuova versione disponibile! ${projectName}: ${version}!`,
text : renderTemplate(changelogTemplate, {
changelogUrl: changelogUrl
}),
},
],
})

const requestOptions = {
method: 'POST',
port: 443,
Expand Down
20 changes: 17 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ const github = require('@actions/github')
const https = require('https')
const simpleGit = require('simple-git');

const renderTemplate = (template, args={}) => {
let finalRender = template;
for (const [key, value] of Object.entries(args)) {
finalRender = finalRender.replace(`{{${key}}}`, value);
}
return finalRender;
}

const main = async () => {
const currentRepoGit = simpleGit();
const tags = (await currentRepoGit.tags({'--sort' : 'taggerdate'})).all
Expand All @@ -14,18 +22,24 @@ const main = async () => {
const slackToken = core.getInput('slack_token')
const channelId = core.getInput('channel_id')
const projectName = core.getInput('project_name')
const releaseTemplate = core.getInput('release_template')
const changelogTemplate = core.getInput('changelog_template')

const payload = JSON.stringify({
channel: channelId,
token: slackToken,
attachments: [
{
pretext : `Rilasciata la nuova versione di ${projectName}: ${version}!`,
text : `Changelog disponibile qua: ${changelogUrl}`,
pretext : renderTemplate(releaseTemplate, {
projectName: projectName,
version: version
}), // `Nuova versione disponibile! ${projectName}: ${version}!`,
text : renderTemplate(changelogTemplate, {
changelogUrl: changelogUrl
}),
},
],
})

const requestOptions = {
method: 'POST',
port: 443,
Expand Down
Loading