Skip to content

Commit 309db3c

Browse files
committed
fix: fix review comments
1 parent 2d37ea6 commit 309db3c

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

src/handlers/app.handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export class AppHandler {
102102
apiKey = await this.services.configService.getApiKey(context);
103103
config = await this.services.configService.getConfig(context, apiKey);
104104

105+
await this.services.appService.init(context);
105106
await callback(apiKey, config);
106107
} catch (error) {
107108
if ('repository' in context.payload) {
@@ -129,7 +130,6 @@ export class AppHandler {
129130
): Promise<void> {
130131
await this.safeEventHandler(context, async (apiKey, config) => {
131132
await this.handlers.contributorHandler.safeCacheContributors(context, apiKey);
132-
await this.services.appService.init(context);
133133
await this.handlers.chatHandler.handle(context, apiKey, config);
134134
});
135135
}

src/services/app.service.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { GitHubService } from './github.service';
77
export class AppService {
88
private static instance: AppService;
99
private appData?: RestEndpointMethodTypes['apps']['getAuthenticated']['response']['data'];
10+
private user?: RestEndpointMethodTypes['users']['getByUsername']['response']['data'];
1011

1112
private constructor() {}
1213

@@ -19,11 +20,13 @@ export class AppService {
1920
}
2021

2122
async init(context: Context): Promise<void> {
22-
if (!this.appData) {
23+
if (!this.appData || !this.user) {
2324
try {
2425
const { data } = await GitHubService.getAuthenticated(context);
2526

2627
this.appData = data;
28+
29+
this.user = await GitHubService.getByUsername(this.appData!.slug + '[bot]', context);
2730
} catch (error) {
2831
throw new SystemError('Failed to get authenticated app data', Severity.ERROR, error);
2932
}
@@ -42,9 +45,15 @@ export class AppService {
4245
return this.appData!.slug;
4346
}
4447

45-
getId(): number | undefined {
48+
getLogin(): string {
49+
this.ensureInitialized();
50+
51+
return this.user!.login;
52+
}
53+
54+
getEmail(): string {
4655
this.ensureInitialized();
4756

48-
return this.appData!.id;
57+
return `${this.user!.id}+${this.user!.login}@users.noreply.github.com`;
4958
}
5059
}

src/services/github.service.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ export class GitHubService {
7070
return context.octokit.apps.getAuthenticated();
7171
}
7272

73+
static getByUsername = async (
74+
username: string,
75+
context: Context
76+
): Promise<RestEndpointMethodTypes['users']['getByUsername']['response']['data']> => {
77+
const { data } = await context.octokit.users.getByUsername({
78+
username
79+
});
80+
81+
return data;
82+
};
83+
7384
static paginateListComments(
7485
context: Context
7586
): Promise<RestEndpointMethodTypes['issues']['listComments']['response']['data']> {

src/utils/review-skip-conditions.util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export class ReviewSkipConditions {
3737
const commitSha = this.context.payload.after;
3838
const commit = await GitHubService.getCommit(commitSha, this.context);
3939
const { message } = commit.data.commit;
40-
const slug = this.appService.getAppSlug();
41-
const id = this.appService.getId();
42-
const coAuthoredMessage = `${slug}[bot] <${id}+${slug}[bot]@users.noreply.github.com>`;
40+
const login = this.appService.getLogin();
41+
const email = this.appService.getEmail();
42+
const coAuthoredMessage = `${login} <${email}>`;
4343

4444
return message.toLowerCase().includes(coAuthoredMessage.toLowerCase());
4545
}

0 commit comments

Comments
 (0)