Skip to content

Commit 338df99

Browse files
committed
Add optional title to disguish notifications
1 parent f87d8e1 commit 338df99

File tree

8 files changed

+28
-7
lines changed

8 files changed

+28
-7
lines changed

.github/workflows/examples.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ jobs:
216216
new: fixtures/file4_added.txt
217217
mode: addition
218218
token: ${{ secrets.GITHUB_TOKEN }}
219+
title: Works
219220
notify_issue: true
220221
notify_check: true
221222

@@ -229,5 +230,6 @@ jobs:
229230
new: fixtures/file2_deleted.txt
230231
mode: addition
231232
token: ${{ secrets.GITHUB_TOKEN }}
233+
title: Fails
232234
notify_issue: true
233235
notify_check: true

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ _Optional_ The path where to output the diff (as well as on the console)
5252

5353
_Optional_ Your `GITHUB_TOKEN`, **required** when using `notify_check` and/or `notify_issue`
5454

55+
### `title`
56+
57+
_Optional_ add a title to the notifications to distinguish between multiple workflows/jobs
58+
5559
### `notify_check`
5660

5761
_Optional_ Will create a [GitHub Check Run](https://developer.github.com/v3/checks/runs/#create-a-check-run) if `'true'` is specified, **requires** `token` to be given as well

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ inputs:
2424
token:
2525
description: 'your GITHUB_TOKEN, used when sending notifications'
2626
required: false
27+
title:
28+
description: 'add a title to the notifications to distinguish between multiple workflows/jobs'
29+
required: false
2730
notify_issue:
2831
description: 'send a notification to the linked issue/pullrequest with the output'
2932
required: false

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/inputs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ export const parseInputs = (getInput: GetInput): Inputs.Args => {
2222
const notify_check = getInput('notify_check');
2323
const notify_issue = getInput('notify_issue');
2424
if (notify_check || notify_issue) {
25+
const label = getInput('title');
2526
const token = getInput('token', {required: true});
2627
notifications = {
2728
token,
29+
label,
2830
check: notify_check === 'true',
2931
issue: notify_issue === 'true',
3032
};

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ async function run(): Promise<void> {
1919

2020
if (inputs.notifications.check) {
2121
core.debug(`Notification: Check Run`);
22-
await createRun(octokit, github.context, result);
22+
await createRun(octokit, github.context, result, inputs.notifications.label);
2323
}
2424
if (inputs.notifications.issue) {
2525
core.debug(`Notification: Issue`);
2626
const issueId = github.context.issue.number;
2727
if (issueId || issueId === 0) {
28-
await createComment(octokit, github.context, result);
28+
await createComment(octokit, github.context, result, inputs.notifications.label);
2929
} else {
3030
core.debug(`Notification: no issue id`);
3131
}

src/namespaces/Inputs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type Args = {
88

99
notifications?: {
1010
token: string;
11+
label?: string;
1112
issue: boolean;
1213
check: boolean;
1314
};

src/notifications.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ const formatDate = (): string => {
66
return new Date().toISOString();
77
};
88

9-
const title = 'Smart Diff';
9+
const getTitle = (label?: string): string => {
10+
const more = label ? ` (${label})` : '';
11+
return `Smart Diff${more}`;
12+
};
1013

11-
export const createRun = async (octokit: GitHub, context: Context, result: Result): Promise<void> => {
14+
export const createRun = async (octokit: GitHub, context: Context, result: Result, label?: string): Promise<void> => {
15+
const title = getTitle(label);
1216
await octokit.checks.create({
1317
owner: context.repo.owner,
1418
repo: context.repo.repo,
@@ -26,12 +30,17 @@ export const createRun = async (octokit: GitHub, context: Context, result: Resul
2630
});
2731
};
2832

29-
export const createComment = async (octokit: GitHub, context: Context, result: Result): Promise<void> => {
33+
export const createComment = async (
34+
octokit: GitHub,
35+
context: Context,
36+
result: Result,
37+
label?: string,
38+
): Promise<void> => {
3039
await octokit.issues.createComment({
3140
owner: context.repo.owner,
3241
repo: context.repo.repo,
3342
issue_number: context.issue.number,
34-
body: `## ${title}: ${result.passed ? 'Success' : 'Failure'}
43+
body: `## ${getTitle(label)}: ${result.passed ? 'Success' : 'Failure'}
3544
${result.summary}
3645
3746
${result.output}

0 commit comments

Comments
 (0)