Skip to content

Commit

Permalink
Make createIssue receive GitHubIssueContent
Browse files Browse the repository at this point in the history
  • Loading branch information
yykamei committed Mar 28, 2024
1 parent 83a9d2c commit 8e9c184
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
9 changes: 2 additions & 7 deletions src/APIClient.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import type { GitHubIssue } from "./GitHubIssue";
import type { GitHubIssueContent } from "./GitHubIssueContent";
import type { GitHubWorkflow } from "./GitHubWorkflow";
import type { GitHubWorkflowRun } from "./GitHubWorkflowRun";

export type IssueBody = {
readonly title: string;
readonly body: string;
readonly assignees?: string[];
readonly labels?: string[];
};
export interface APIClient {
getWorkflows(owner: string, repo: string): Promise<GitHubWorkflow[]>;
getWorkflow(
Expand All @@ -24,6 +19,6 @@ export interface APIClient {
createIssue(
owner: string,
repo: string,
issueBody: IssueBody,
issueContent: GitHubIssueContent,
): Promise<GitHubIssue>;
}
7 changes: 4 additions & 3 deletions src/GitHubAPIClient.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getOctokit } from "@actions/github";
import type { Octokit } from "@octokit/core";
import type { APIClient, IssueBody } from "./APIClient";
import type { APIClient } from "./APIClient";
import { DateTime } from "./DateTime";
import { GitHubIssue } from "./GitHubIssue";
import type { GitHubIssueContent } from "./GitHubIssueContent";
import { GitHubWorkflow } from "./GitHubWorkflow";
import { GitHubWorkflowRun } from "./GitHubWorkflowRun";

Expand Down Expand Up @@ -82,9 +83,9 @@ export class GitHubAPIClient implements APIClient {
async createIssue(
owner: string,
repo: string,
issueBody: IssueBody,
issueContent: GitHubIssueContent,
): Promise<GitHubIssue> {
const { title, body, assignees, labels } = issueBody;
const { title, body, assignees, labels } = issueContent;
const response = await this.client.request(
"POST /repos/{owner}/{repo}/issues",
{
Expand Down
7 changes: 4 additions & 3 deletions src/GitHubRepository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { APIClient, IssueBody } from "./APIClient";
import type { APIClient } from "./APIClient";
import type { GitHubIssue } from "./GitHubIssue";
import type { GitHubIssueContent } from "./GitHubIssueContent";
import type { GitHubWorkflow } from "./GitHubWorkflow";
import type { GitHubWorkflowRun } from "./GitHubWorkflowRun";

Expand All @@ -24,7 +25,7 @@ export class GitHubRepository {
return this.apiClient.getWorkflowRuns(this.owner, this.repo, workflow.id);
}

async createIssue(issueBody: IssueBody): Promise<GitHubIssue> {
return this.apiClient.createIssue(this.owner, this.repo, issueBody);
async createIssue(issueContent: GitHubIssueContent): Promise<GitHubIssue> {
return this.apiClient.createIssue(this.owner, this.repo, issueContent);
}
}
5 changes: 3 additions & 2 deletions src/TestClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { APIClient, IssueBody } from "./APIClient";
import type { APIClient } from "./APIClient";
import { DateTime } from "./DateTime";
import { GitHubIssue } from "./GitHubIssue";
import type { GitHubIssueContent } from "./GitHubIssueContent";
import { GitHubWorkflow } from "./GitHubWorkflow";
import { GitHubWorkflowRun } from "./GitHubWorkflowRun";

Expand Down Expand Up @@ -39,7 +40,7 @@ export class TestClient implements APIClient {
async createIssue(
_owner: string,
_repo: string,
_issueBody: IssueBody,
_issueContent: GitHubIssueContent,
): Promise<GitHubIssue> {
return new GitHubIssue({
id: 234,
Expand Down
10 changes: 6 additions & 4 deletions tests/GitHubAPIClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { GitHubAPIClient } from "../src/GitHubAPIClient";
import { GitHubIssueContent } from "../src/GitHubIssueContent";
import { GitHubWorkflow } from "../src/GitHubWorkflow";

describe("GitHubAPIClient.getWorkflow()", () => {
Expand Down Expand Up @@ -132,10 +133,11 @@ describe("GitHubAPIClient.createIssue()", () => {
status: 200,
});

const issue = await client.createIssue("yykamei", "test-repo", {
title: "test",
body: "body",
});
const issue = await client.createIssue(
"yykamei",
"test-repo",
new GitHubIssueContent([], "test"),
);
expect(spy).toHaveBeenCalledTimes(1);
expect(issue).toHaveProperty("parameters");
});
Expand Down
3 changes: 2 additions & 1 deletion tests/GitHubRepository.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, it } from "vitest";
import { GitHubIssueContent } from "../src/GitHubIssueContent";
import { GitHubRepository } from "../src/GitHubRepository";
import { GitHubWorkflow } from "../src/GitHubWorkflow";
import { TestClient } from "../src/TestClient";
Expand All @@ -10,6 +11,6 @@ describe("GitHubRepository", () => {
repository.getWorkflows();
repository.getWorkflow("abc.yml");
repository.getWorkflowRuns(new GitHubWorkflow(8, "Eight", "eight.yml"));
repository.createIssue({ title: "t", body: "b" });
repository.createIssue(new GitHubIssueContent([], "title"));
});
});

0 comments on commit 8e9c184

Please sign in to comment.