Skip to content

Commit 55ea2f5

Browse files
committed
Fix filtering out contributions created by bots
1 parent 4c4cea2 commit 55ea2f5

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

api/src/contribution/controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class ContributionController {
2020
): Promise<GetContributionsResponseDto> {
2121
const { contributions, filters } = await this.contributionRepository.find(
2222
(contribution) =>
23+
!contribution.createdBy.username.includes("[bot]") &&
2324
(labels.length === 0 || labels.some((label) => contribution.labels.includes(label))) &&
2425
(languages.length === 0 ||
2526
languages.some((language) => contribution.languages.includes(language))) &&

api/src/contribution/repository.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class ContributionRepository {
2222

2323
let contributions = (
2424
await Promise.all(
25-
projects.reduce<Promise<Model<ContributionEntity, "project">[]>[]>(
25+
projects.reduce<Promise<Model<ContributionEntity, "project" | "createdBy">[]>[]>(
2626
(pV, { repositories, name, slug }) => [
2727
...pV,
2828
...repositories
@@ -38,8 +38,7 @@ export class ContributionRepository {
3838
owner,
3939
repository,
4040
});
41-
// @TODO-ZM: filter out the ones created by bots
42-
return issuesIncludingPRs.map<Model<ContributionEntity, "project">>(
41+
return issuesIncludingPRs.map<Model<ContributionEntity, "project" | "createdBy">>(
4342
({
4443
number,
4544
labels: gLabels,
@@ -49,6 +48,7 @@ export class ContributionRepository {
4948
created_at, // eslint-disable-line camelcase
5049
updated_at, // eslint-disable-line camelcase
5150
comments,
51+
user,
5252
}) => ({
5353
id: `${number}`,
5454
labels: gLabels.map(({ name }) => name),
@@ -64,6 +64,7 @@ export class ContributionRepository {
6464
updatedAt: updated_at, // eslint-disable-line camelcase
6565
commentsCount: comments,
6666
/* eslint-enable camelcase */
67+
createdBy: this.githubService.githubUserToAccountEntity(user),
6768
}),
6869
);
6970
} catch (error) {

api/src/contribution/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class FilterDto {
3131
export class GetContributionsResponseDto extends GeneralResponseDto {
3232
@ValidateNested({ each: true })
3333
@Type(() => ContributionEntity)
34-
contributions!: Model<ContributionEntity, "project">[];
34+
contributions!: Model<ContributionEntity, "project" | "createdBy">[];
3535

3636
@ValidateNested({ each: true })
3737
@Type(() => FilterDto)

packages/models/src/contribution/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Type } from "class-transformer";
22
import { IsDateString, IsNumber, IsString, IsUrl, ValidateNested } from "class-validator";
33
import { BaseEntity, Model } from "src/_base";
4+
import { AccountEntity } from "src/account";
45
import { ProjectReferenceEntity } from "src/project-reference";
56

67
export class ContributionEntity extends BaseEntity {
@@ -14,6 +15,10 @@ export class ContributionEntity extends BaseEntity {
1415
@Type(() => ProjectReferenceEntity)
1516
project!: Model<ProjectReferenceEntity>;
1617

18+
@ValidateNested()
19+
@Type(() => AccountEntity)
20+
createdBy!: Model<AccountEntity>;
21+
1722
@IsString()
1823
type!: "issue" | "pullRequest";
1924

0 commit comments

Comments
 (0)