Skip to content

Commit

Permalink
feat(pr): add extra pr data to db item
Browse files Browse the repository at this point in the history
this function will insert data fetched from github directly. This is the 'FINAL DATA' that we
collect once (without any history). Potentially, we can collect history on this, but we'll do this
once an achievement idea comes along that need that data
  • Loading branch information
thatkookooguy committed May 6, 2021
1 parent 8667e25 commit acaa7df
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 4 deletions.
19 changes: 18 additions & 1 deletion server/src/api/pull-request/pull-request.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@kb-dev-tools';
import { PullRequest } from '@kb-models';

import { PullRequestService } from './pull-request.service';
import { IFetchedData, PullRequestService } from './pull-request.service';

describe('PullRequestService', () => {
let service: PullRequestService;
Expand Down Expand Up @@ -109,4 +109,21 @@ describe('PullRequestService', () => {
pr = new PullRequest(dbPR.toObject());
expect(pr.reviewers).not.toContain(mockReviewer.username);
});

it('should add extra PR data', async () => {
const mockPr = DtoMockGenerator.pullRequest();
await service.create(mockPr);
const extraData: IFetchedData = {
comments: [{ id: 'comment' }],
commits: [{ id: 'commit' }],
files: [{ name: 'file.ts' }],
reactions: [{ id: 'reaction' }],
reviewComments: [{ id: 'review-comment' }],
reviews: [{ id: 'review' }]
};
await service.updatePRExtraData(mockPr.prid, extraData);
const dbPR = await service.findOneAsync({ prid: mockPr.prid });
const pr = new PullRequest(dbPR.toObject());
expect(pr).toEqual(expect.objectContaining(extraData));
});
});
15 changes: 15 additions & 0 deletions server/src/api/pull-request/pull-request.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ export interface INewData {
description?: string;
}

export interface IFetchedData {
comments: any[];
reviewComments: any[];
commits: any[];
files: any[];
reactions: any[];
reviews: any[];
}

@Injectable()
export class PullRequestService extends BaseService<PullRequest> {
constructor(
Expand Down Expand Up @@ -134,4 +143,10 @@ export class PullRequestService extends BaseService<PullRequest> {
status: newStatus
});
}

async updatePRExtraData(prid: string, extraData: IFetchedData) {
return await this.prModel.findOneAndUpdate({ prid }, {
...extraData
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const pullRequestMergedEvent = {
event: 'pull_request',
payload: {
action: 'closed',
number: 2,
number: 1,
pull_request: {
url: 'https://api.github.com/repos/Thatkookooguy/test-new-achievibit-events/pulls/2',
id: 353189935,
Expand All @@ -11,7 +11,7 @@ export const pullRequestMergedEvent = {
diff_url: 'https://github.com/Thatkookooguy/test-new-achievibit-events/pull/2.diff',
patch_url: 'https://github.com/Thatkookooguy/test-new-achievibit-events/pull/2.patch',
issue_url: 'https://api.github.com/repos/Thatkookooguy/test-new-achievibit-events/issues/2',
number: 2,
number: 1,
state: 'closed',
locked: false,
title: 'Update README.md',
Expand Down
56 changes: 55 additions & 1 deletion server/src/interfaces/github-pr-payload.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
* Github Webhook event types
* https://developer.github.com/v3/activity/events/types/
*/

export enum IGithubCommentAuthorAssociation {
COLLABORATOR = 'COLLABORATOR',
CONTRIBUTOR = 'CONTRIBUTOR',
FIRST_TIMER = 'FIRST_TIMER',
FIRST_TIME_CONTRIBUTOR = 'FIRST_TIME_CONTRIBUTOR',
MANNEQUIN = 'MANNEQUIN',
MEMBER = 'MEMBER',
NONE = 'NONE',
OWNER = 'OWNER'
}
export interface IGithubUser {
login: string;
id: number;
Expand All @@ -22,6 +33,20 @@
site_admin: boolean;
}

export interface IGithubComment {
url: string;
html_url: string;
issue_url: string;
id: number;
node_id: string;
user: IGithubUser;
created_at: string;
updated_at: string;
author_association: string;
body: string;
performed_via_github_app: string | null;
}

export interface IGithubRepo {
id: number;
name: string;
Expand Down Expand Up @@ -189,6 +214,7 @@ export interface IGithubReviewComment {
url: string;
path: string;
commit_id: string;
author_association: IGithubCommentAuthorAssociation;
}

export interface IGithubReview {
Expand All @@ -198,7 +224,35 @@ export interface IGithubReview {
state: string;
submitted_at: string;
commit_id: string;
author_association: string;
author_association: IGithubCommentAuthorAssociation;
}

export interface IGithubCommit {
sha: string;
node_id: string;
commit: {
author: IGithubUser;
committer: IGithubUser;
message: string;
tree: any;
url: string;
comment_count: number;
verification: any;
};
url: string;
html_url: string;
comments_url: string;
author: IGithubUser;
committer: IGithubUser;
parents: any;
}

export interface IGithubReaction {
id: number;
node_id: string;
user: IGithubUser;
content: string;
created_at: string;
}

/**
Expand Down

0 comments on commit acaa7df

Please sign in to comment.