Skip to content

Commit 929f5c7

Browse files
authored
Merge pull request #190 from streamdevs/179-issue-url
feat: send issue url to Twitch Chat
2 parents 7b990a9 + f9be937 commit 929f5c7

File tree

7 files changed

+33
-23
lines changed

7 files changed

+33
-23
lines changed

src/reactions/github/issue-assigned.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class IssueAssigned extends Reaction {
77
}
88

99
getTwitchChatMessage({ payload }: ReactionHandleOptions<IssuePayload>): string {
10-
return `${payload.assignee?.login} has a new assigned issue in ${payload.repository.html_url}`;
10+
return `${payload.assignee?.login} has a new assigned issue in ${payload.issue.html_url}`;
1111
}
1212

1313
canHandle({ payload, event, config }: ReactionCanHandleOptions<IssuePayload>): boolean {

src/reactions/github/issue-opened.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class IssueOpened extends Reaction<IssuePayload> {
66
return `*${payload.sender.login}* opened a issue in *${payload.repository.full_name}*`;
77
}
88
getTwitchChatMessage({ payload }: ReactionHandleOptions<IssuePayload>): string {
9-
return `${payload.sender.login} opened a issue in ${payload.repository.html_url}`;
9+
return `${payload.sender.login} opened a issue in ${payload.issue.html_url}`;
1010
}
1111
canHandle({ payload, event }: ReactionCanHandleOptions<IssuePayload>): boolean {
1212
return event === 'issues' && payload.action === 'opened';

src/schemas/github/issue-payload.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { RepositoryWebhookPayload } from './repository-webhook-payload';
22

3+
type url = string;
4+
35
export interface IssuePayload extends RepositoryWebhookPayload {
46
action: string;
57
assignee?: { login: string };
8+
issue: { html_url: url };
69
}

test/builders/github/issue-payload-builder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export class IssuePayloadBuilder {
1111
},
1212
sender: { login: internet.userName() },
1313
assignee: { login: internet.userName() },
14+
issue: { html_url: internet.url() },
1415
};
1516

1617
public with(payload: Partial<IssuePayload>): IssuePayloadBuilder {

test/reactions/github/issue-assigned.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('IssueAssigned', () => {
3737
await subject.handle({ payload });
3838

3939
expect(twitchChat.send).toHaveBeenCalledWith(
40-
`${payload.assignee?.login} has a new assigned issue in ${payload.repository.html_url}`,
40+
`${payload.assignee?.login} has a new assigned issue in ${payload.issue.html_url}`,
4141
);
4242
});
4343
});

test/reactions/github/issue-opened.spec.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { TwitchChat } from '../../../src/services/TwitchChat';
22
import { StreamLabs } from '../../../src/services/StreamLabs';
33
import { IssueOpened } from '../../../src/reactions/github/issue-opened';
44
import { IssuePayload } from '../../../src/schemas/github/issue-payload';
5+
import { IssuePayloadBuilder } from '../../builders/github/issue-payload-builder';
56

67
describe('IssueOpened', () => {
78
let twitchChat: TwitchChat;
@@ -16,16 +17,18 @@ describe('IssueOpened', () => {
1617
let payload: IssuePayload;
1718

1819
beforeEach(() => {
19-
payload = {
20-
action: 'opened',
21-
repository: {
22-
html_url: 'https://github.com/streamdevs/webhook',
23-
full_name: 'streamdevs/webhook',
24-
},
25-
sender: {
26-
login: 'orestes',
27-
},
28-
};
20+
payload = new IssuePayloadBuilder()
21+
.with({
22+
action: 'opened',
23+
repository: {
24+
html_url: 'https://github.com/streamdevs/webhook',
25+
full_name: 'streamdevs/webhook',
26+
},
27+
sender: {
28+
login: 'orestes',
29+
},
30+
})
31+
.getInstance();
2932
});
3033

3134
it('calls StreamLabs with the expected message', async () => {
@@ -44,7 +47,7 @@ describe('IssueOpened', () => {
4447
await subject.handle({ payload });
4548

4649
expect(twitchChat.send).toHaveBeenCalledWith(
47-
`${payload.sender.login} opened a issue in ${payload.repository.html_url}`,
50+
`${payload.sender.login} opened a issue in ${payload.issue.html_url}`,
4851
);
4952
});
5053
});

test/routes/github/issues.spec.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { IssuePayload } from '../../../src/schemas/github/issue-payload';
33
import { initServer } from '../../../src/server';
44
import { StreamLabs } from '../../../src/services/StreamLabs';
55
import { TwitchChat } from '../../../src/services/TwitchChat';
6+
import { IssuePayloadBuilder } from '../../builders/github/issue-payload-builder';
67

78
describe('POST /github', () => {
89
let payload: IssuePayload;
@@ -17,15 +18,17 @@ describe('POST /github', () => {
1718
twitchChatSpy = jest.spyOn(TwitchChat.prototype, 'send');
1819
twitchChatSpy.mockImplementationOnce(jest.fn());
1920

20-
payload = {
21-
action: 'assigned',
22-
assignee: { login: 'SantiMA10' },
23-
sender: { login: 'SantiMA10' },
24-
repository: {
25-
html_url: 'https://github.com/streamdevs/webhook',
26-
full_name: 'streamdevs/webhook',
27-
},
28-
};
21+
payload = new IssuePayloadBuilder()
22+
.with({
23+
action: 'assigned',
24+
assignee: { login: 'SantiMA10' },
25+
sender: { login: 'SantiMA10' },
26+
repository: {
27+
html_url: 'https://github.com/streamdevs/webhook',
28+
full_name: 'streamdevs/webhook',
29+
},
30+
})
31+
.getInstance();
2932
});
3033

3134
it('returns a 200 OK', async () => {

0 commit comments

Comments
 (0)