Skip to content

Commit

Permalink
Merge pull request #9 from PasseiDireto/feat/workflow-teams
Browse files Browse the repository at this point in the history
Chore: Update notification when use microsoft workflow
  • Loading branch information
jhonsouza authored Dec 3, 2024
2 parents 5b2a27d + 9c4ebdb commit 1ea99f6
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 12 deletions.
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,40 @@ jobs:
timezone: America/Sao_Paulo
```
```yaml
name: MS Teams Notification use microsoft workflow

on:
push:
branches: ["main"]
pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout the code
uses: actions/checkout@v4
# this is the new step using the ms-teams-notification action
- name: Notify dedicated teams channel
uses: PasseiDireto/pd-teams-notification-action@main
with:
github-token: ${{ github.token }} # this will use the runner's token.
workflow-teams-webhook-uri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }}
notification-summary: Your custom notification message
notification-color-workflow: good
timezone: America/Sao_Paulo
```
3. Make it your own with the following configurations.
- `github-token` - (required), set to the following:
- `${{ github.token }}`
- `webhook-uri` - (required), setup a new secret to store your Microsoft Teams Webhook URI (ex. `MS_TEAMS_WEBHOOK_URI`). Learn more about setting up [GitHub Secrets](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) or [Microsoft Teams Incoming Webhook](https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook).
- `webhook-uri` - If use microsoft workflow this parameter is optional, setup a new secret to store your Microsoft Teams Webhook URI (ex. `MS_TEAMS_WEBHOOK_URI`). Learn more about setting up [GitHub Secrets](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) or [Microsoft Teams Incoming Webhook](https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook).
- `workflow-teams-webhook-uri` - If use incoming webhook this parameter is optional, setup a new secret to store your Microsoft Teams Webhook URI (ex. `MS_TEAMS_WEBHOOK_URI`). Learn more about setting up [GitHub Secrets](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) or [Microsoft Teams Incoming Webhook](https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook).
- `notification-summary` (required), Your custom notification message (ex. Deployment Started or Build Successful)
- `notification-color` (optional), Custom color to help distinguish type of notification. Can be any [HEX color](https://html-color.codes/). (ex. **007bff** or **17a2b8** for info, **28a745** success, **ffc107** warning, **dc3545** error, etc.)
- `notification-color` - If use microsoft workflow this parameter is optional, Custom color to help distinguish type of notification. Can be any [HEX color](https://html-color.codes/). (ex. **007bff** or **17a2b8** for info, **28a745** success, **ffc107** warning, **dc3545** error, etc.)
- `notification-color-workflow` - If use incoming webhook this parameter is optional, Custom color to help distinguish type of notification. The options can be used are: (**accent** for info, **good** for success, **attention** for error, **warning** for warning)
- `timezone` - (optional, defaults to `America/Sao_Paulo`), a [valid database timezone name](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones), (ex. Australia/Sydney or America/Denver, etc.)

## Examples
Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ inputs:
required: true
notification-color:
description: "Color of notification header line"
required: true
required: false
notification-color-workflow:
description: "Color of notification header line"
required: false
timezone:
description: "Timezone (ex. America/Sao_Paulo)"
required: false
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ async function run(): Promise<void> {
const workflowWebhookUri: string = core.getInput('workflow-teams-webhook-uri', { required: false });

const notificationSummary = core.getInput('notification-summary') || 'GitHub Action Notification';
const notificationColor = core.getInput('notification-color') || '0b93ff';
const notificationColor = core.getInput('notification-color') || '';
const notificationColorWorkflow = core.getInput('notification-color-workflow') || ''
const timezone = core.getInput('timezone') || 'America/Sao_Paulo';

const timestamp = moment().tz(timezone).format('dddd, MMMM Do YYYY, h:mm:ss a z');
Expand All @@ -28,13 +29,15 @@ async function run(): Promise<void> {

const octokit = new Octokit({ auth: `token ${githubToken}` });
const commit = await octokit.repos.getCommit(params);
const html_url = commit.data.html_url;
const author = commit.data.author;
const authorLogin = author ? author.login : 'None';

const messageCard = await createMessageCard(
notificationSummary,
notificationColor,
!notificationColor ? notificationColorWorkflow : notificationColor,
commit,
html_url,
author,
authorLogin,
runNum,
Expand Down
9 changes: 5 additions & 4 deletions src/message-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export function createMessageCard(
notificationSummary: string,
notificationColor: string,
commit: any,
html_url: string,
author: any,
authorLogin: string,
runNum: string,
Expand Down Expand Up @@ -42,7 +43,7 @@ export function createMessageCard(
},
{
'@context': 'http://schema.org',
target: [commit.data.html_url],
target: [`${html_url}`],
'@type': 'ViewAction',
name: 'View Commit Changes',
},
Expand Down Expand Up @@ -72,7 +73,7 @@ export function createMessageCard(
},
{
"type": "Column",
"width": "*",
"width": "auto",
"items": [
{
"type": "TextBlock",
Expand All @@ -97,14 +98,14 @@ export function createMessageCard(
],
"actions": [
{
"type": "ACtion.OpenUrl",
"type": "Action.OpenUrl",
"title": "View Workflow Run",
"url": `${repoUrl}/actions/runs/${runId}`
},
{
"type": "Action.OpenUrl",
"title": "View Commit Changes",
"url": commit.data.html_url
"url": html_url
}
]
}
Expand Down

0 comments on commit 1ea99f6

Please sign in to comment.