Skip to content

Commit 9cd6b20

Browse files
authored
Merge pull request #576 from YiweiShen/codez-chore-543-refactor-github-consolidate-types-and-contents-code-3121065203
refactor(github): consolidate types and contents code
2 parents 27479f1 + a5b438f commit 9cd6b20

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

src/github/contents.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import * as core from '@actions/core';
55
import type { Octokit } from 'octokit';
6-
import type { RepoContext, AgentEvent, GithubContentsData } from './types';
6+
import type { RepoContext, AgentEvent, GitHubContentsData } from './types';
77
import { GitHubError } from '../utils/errors';
88

99
/**
@@ -46,7 +46,7 @@ export async function getContentsData(
4646
octokit: Octokit,
4747
repo: RepoContext,
4848
event: AgentEvent,
49-
): Promise<GithubContentsData> {
49+
): Promise<GitHubContentsData> {
5050
if (event.type === 'issuesOpened' || event.type === 'issueCommentCreated') {
5151
return getIssueData(octokit, repo, event.github.issue.number);
5252
} else if (event.type === 'pullRequestCommentCreated') {
@@ -66,7 +66,7 @@ async function getIssueData(
6666
octokit: Octokit,
6767
repo: RepoContext,
6868
issueNumber: number,
69-
): Promise<GithubContentsData> {
69+
): Promise<GitHubContentsData> {
7070
core.info(`Fetching data for issue #${issueNumber}...`);
7171
try {
7272
// Fetch issue and its comments via GraphQL in a single request
@@ -126,7 +126,7 @@ async function getPullRequestData(
126126
octokit: Octokit,
127127
repo: RepoContext,
128128
pullNumber: number,
129-
): Promise<GithubContentsData> {
129+
): Promise<GitHubContentsData> {
130130
core.info(`Fetching data for pull request #${pullNumber} via GraphQL...`);
131131
try {
132132
// Fetch PR and its issue‐thread comments via GraphQL
@@ -188,7 +188,7 @@ async function getPullRequestReviewCommentsData(
188188
repo: RepoContext,
189189
pullNumber: number,
190190
targetCommentId: number,
191-
): Promise<GithubContentsData> {
191+
): Promise<GitHubContentsData> {
192192
core.info(`Fetching data for pull request review comments #${pullNumber}...`);
193193
try {
194194
// Get PR body

src/github/types.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,34 @@ export type GitHubEventIssuesOpened = { action: 'opened'; issue: GitHubIssue };
3939
export type GitHubEventIssueCommentCreated = {
4040
action: 'created';
4141
issue: GitHubIssue;
42-
comment: GithubComment;
42+
comment: GitHubComment;
4343
};
4444
export type GitHubEventPullRequestCommentCreated = {
4545
action: 'created';
4646
issue: GitHubPullRequest;
47-
comment: GithubComment;
47+
comment: GitHubComment;
4848
};
49+
/**
50+
* Minimal pull request representation for review events.
51+
*/
52+
export type GitHubPullRequestMinimal = Pick<GitHubPullRequest, 'number' | 'title' | 'body'>;
53+
54+
/**
55+
* GitHub pull request review comment payload.
56+
*/
57+
export type GitHubReviewComment = {
58+
id: number;
59+
body: string;
60+
path: string;
61+
in_reply_to_id?: number;
62+
position?: number;
63+
line?: number;
64+
};
65+
4966
export type GitHubEventPullRequestReviewCommentCreated = {
5067
action: 'created';
51-
pull_request: { number: number; title?: string; body?: string };
52-
comment: {
53-
id: number;
54-
body: string;
55-
path: string;
56-
in_reply_to_id?: number;
57-
position?: number;
58-
line?: number;
59-
};
68+
pull_request: GitHubPullRequestMinimal;
69+
comment: GitHubReviewComment;
6070
};
6171
export type GitHubEventIssuesAssigned = {
6272
action: 'assigned';
@@ -72,7 +82,10 @@ export type GitHubEventPullRequestSynchronize = {
7282
pull_request: GitHubPullRequest;
7383
};
7484

75-
export type GithubComment = { id: number; body: string };
85+
/**
86+
* Basic GitHub issue or pull request comment.
87+
*/
88+
export type GitHubComment = { id: number; body: string };
7689
export type GitHubIssue = {
7790
number: number;
7891
title: string;
@@ -89,7 +102,7 @@ export type GitHubPullRequest = {
89102
/**
90103
* Content and comments data for issues and pull requests.
91104
*/
92-
export type GithubContentsData = {
105+
export type GitHubContentsData = {
93106
content: { number?: number; title: string; body: string; login: string };
94107
comments: { body: string; login: string }[];
95108
};

0 commit comments

Comments
 (0)