From a5cf1a0366f93dccc3ede20d0f6f18e854b89599 Mon Sep 17 00:00:00 2001 From: Addy Pathania Date: Mon, 17 Jun 2024 09:00:29 -0400 Subject: [PATCH 1/3] add workflow to notify teams --- .github/workflows/notify_teams.yml | 18 +++++++++++++ scripts/notify-teams.js | 42 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 .github/workflows/notify_teams.yml create mode 100644 scripts/notify-teams.js diff --git a/.github/workflows/notify_teams.yml b/.github/workflows/notify_teams.yml new file mode 100644 index 0000000000..81543709d2 --- /dev/null +++ b/.github/workflows/notify_teams.yml @@ -0,0 +1,18 @@ +name: Notify Teams (Release) +on: + release: + types: [published] + +jobs: + notify_teams: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Send Notification + run: node ./scripts/notify-teams.js + env: + GITHUB: ${{ toJson(github) }} + TEAMS_WEBHOOK_URL: ${{ vars.TEAMS_WEBHOOK_URL }} diff --git a/scripts/notify-teams.js b/scripts/notify-teams.js new file mode 100644 index 0000000000..9ee571b0a8 --- /dev/null +++ b/scripts/notify-teams.js @@ -0,0 +1,42 @@ +const github = JSON.parse(process.env.GITHUB); + +/** + * Transforms a payload object into a Teams message card format. + * + * @param {Object} payload - The payload object containing release information. + */ +function transformPayload(payload) { + const title = `JSS Release: ${payload.tag_name}`; + const releaseUrl = payload.html_url; + const publishedBy = payload.author.login; + + const teamsPayload = { + '@type': 'MessageCard', + '@context': 'http://schema.org/extensions', + themeColor: '0076D7', + title, + text: `**Release:** ${releaseUrl}\n\n**Published by:** ${publishedBy}`, + }; + return teamsPayload; +} + +(async () => { + if (!process.env.TEAMS_WEBHOOK_URL) { + console.log('Skipped teams notification about release.'); + return; + } + + const event = github.event.release; + + try { + await fetch(process.env.TEAMS_WEBHOOK_URL, { + method: 'POST', + body: JSON.stringify({ + ...transformPayload(event), + }), + }); + } catch (error) { + console.log('Error occurred while trying to post on teams channel', error); + process.exit(1); + } +})(); From 1987b0dcac5b75b7e4956d31c7c4844c34380999 Mon Sep 17 00:00:00 2001 From: Addy Pathania Date: Mon, 17 Jun 2024 14:32:02 -0400 Subject: [PATCH 2/3] add body to the post --- scripts/notify-teams.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/notify-teams.js b/scripts/notify-teams.js index 9ee571b0a8..76ed429e65 100644 --- a/scripts/notify-teams.js +++ b/scripts/notify-teams.js @@ -9,13 +9,14 @@ function transformPayload(payload) { const title = `JSS Release: ${payload.tag_name}`; const releaseUrl = payload.html_url; const publishedBy = payload.author.login; + const body = payload.body; const teamsPayload = { '@type': 'MessageCard', '@context': 'http://schema.org/extensions', themeColor: '0076D7', - title, - text: `**Release:** ${releaseUrl}\n\n**Published by:** ${publishedBy}`, + title: title, + text: `**Release:** ${releaseUrl}\n\n**Published by:** ${publishedBy}\n\n**Changelog:**\n\n${body}`, }; return teamsPayload; } From b61e7cca6e7885285ee4a4d7595eb20fd3ca53aa Mon Sep 17 00:00:00 2001 From: Addy Pathania Date: Mon, 17 Jun 2024 14:34:40 -0400 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 828a1ca3ad..785c8dc702 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ Our versioning strategy is as follows: ### 🧹 Chores * Update node/types to version 20 in all packages and samples ([#1810](https://github.com/Sitecore/jss/pull/1810)) +* Github - Teams integration ([#1823](https://github.com/Sitecore/jss/pull/1823)) ## 22.0.0