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

[Chore] Github - Teams Integration #1823

Merged
merged 3 commits into from
Jun 17, 2024
Merged
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
18 changes: 18 additions & 0 deletions .github/workflows/notify_teams.yml
Original file line number Diff line number Diff line change
@@ -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 }}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
43 changes: 43 additions & 0 deletions scripts/notify-teams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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 body = payload.body;

const teamsPayload = {
'@type': 'MessageCard',
'@context': 'http://schema.org/extensions',
themeColor: '0076D7',
title: title,
text: `**Release:** ${releaseUrl}\n\n**Published by:** ${publishedBy}\n\n**Changelog:**\n\n${body}`,
};
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);
}
})();