Skip to content

Commit

Permalink
feat: untested class to get all information
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 committed Feb 27, 2024
1 parent a86c62f commit f5104e1
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 12 deletions.
43 changes: 43 additions & 0 deletions src/get-activity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { GetActivity } from "./get-activity";
import { parseGitHubUrl } from "./start";
import { config } from "dotenv";

config();
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
if (!GITHUB_TOKEN) {
console.warn("GITHUB_TOKEN is not set");
}
// Mock process.argv
process.argv = ["path/to/node", "path/to/script", `--auth=${GITHUB_TOKEN}`];

describe("GetActivity class", () => {
let activity: GetActivity;

beforeAll(async () => {
const issue22 = parseGitHubUrl("https://github.com/ubiquibot/comment-incentives/issues/22");
activity = new GetActivity(issue22);
// Wait for all promises to resolve
await Promise.all([activity.self, activity.events, activity.comments, activity.linkedReviews]);
console.dir(activity, { depth: null, colors: true });
});

it("should create an instance of GetActivity", () => {
expect(activity).toBeInstanceOf(GetActivity);
});

it("should initialize self as an object", () => {
expect(typeof activity.self).toBe("object");
});

it("should initialize events as an object", () => {
expect(typeof activity.events).toBe("object");
});

it("should initialize comments as an object", () => {
expect(typeof activity.comments).toBe("object");
});

it("should initialize linkedReviews as an array", () => {
expect(Array.isArray(activity.linkedReviews)).toBe(true);
});
});
27 changes: 18 additions & 9 deletions src/getters.ts → src/get-activity.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import collectLinkedPulls from "./data-collection/collect-linked-pulls";
import { GitHubComment, GitHubPullRequest } from "./github-types";
import { IssueParams, getIssue, getIssueComments, getIssueEvents, getPullRequest, getPullRequestComments, getPullRequestReviewComments } from "./start";
import { GitHubPullRequest, GitHubPullRequestComment, GitHubPullRequestReview } from "./github-types";
import {
IssueParams,
PullParams,
getIssue,
getIssueComments,
getIssueEvents,
getPullRequest,
getPullRequestReviewComments,
getPullRequestReviews,
} from "./start";

export class GetIssue {
export class GetActivity {
self: null;
events: null;
comments: null;
Expand All @@ -29,11 +38,11 @@ export class GetIssue {

class Review {
self: GitHubPullRequest;
comments: GitHubComment[];
reviewComments: [];
constructor(pullParams: pullParams) {
self = getPullRequest(pullParams).catch(console.error);
comments = getPullRequestComments(pullParams).catch(console.error);
reviewComments = getPullRequestReviewComments(pullParams).catch(console.error);
reviews: GitHubPullRequestReview[];
reviewComments: GitHubPullRequestComment[];
constructor(pullParams: PullParams) {
this.self = getPullRequest(pullParams).catch(console.error);
this.reviews = getPullRequestReviews(pullParams).catch(console.error);
this.reviewComments = getPullRequestReviewComments(pullParams).catch(console.error);
}
}
2 changes: 2 additions & 0 deletions src/github-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export type GitHubIssueEvent = RestEndpointMethodTypes["issues"]["listEvents"]["
export type GitHubTimelineEvent = RestEndpointMethodTypes["issues"]["listEventsForTimeline"]["response"]["data"][0];
export type GitHubRepository = RestEndpointMethodTypes["repos"]["get"]["response"]["data"];
export type GitHubUser = RestEndpointMethodTypes["users"]["getByUsername"]["response"]["data"];
export type GitHubPullRequestReview = RestEndpointMethodTypes["pulls"]["listReviews"]["response"]["data"][0];
export type GitHubPullRequestComment = RestEndpointMethodTypes["pulls"]["listReviewComments"]["response"]["data"][0];

type LinkPullRequestDetail = {
url: "https://api.github.com/repos/ubiquibot/comment-incentives/pulls/25";
Expand Down
6 changes: 3 additions & 3 deletions src/start.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getOctokitInstance } from "./get-authentication-token";
import { GitHubIssue, GitHubPullRequest, GitHubTimelineEvent, GitHubUser } from "./github-types";
import { GitHubIssue, GitHubPullRequest, GitHubPullRequestReview, GitHubTimelineEvent, GitHubUser } from "./github-types";

// async function main(gitHubIssueUrl: GitHubIssue["html_url"]) {
// const issueParams = parseGitHubUrl(gitHubIssueUrl);
Expand Down Expand Up @@ -67,9 +67,9 @@ export async function getIssueComments(issueParams: IssueParams) {
const octokit = getOctokitInstance();
return await octokit.paginate(octokit.issues.listComments.endpoint.merge(issueParams));
}
export async function getPullRequestComments(pullParams: PullParams) {
export async function getPullRequestReviews(pullParams: PullParams): Promise<GitHubPullRequestReview[]> {
const octokit = getOctokitInstance();
return await octokit.paginate(octokit.pulls.listCommentsForReview.endpoint.merge(pullParams));
return await octokit.paginate(octokit.pulls.listReviews.endpoint.merge(pullParams));
}
export async function getPullRequestReviewComments(pullParams: PullParams) {
const octokit = getOctokitInstance();
Expand Down

0 comments on commit f5104e1

Please sign in to comment.