import { Octokit } from '@octokit/core'; import { ConstructorParams, CreateGithubIssuesParams } from './github.type'; class GitHubService { service: Octokit; repo?: string; assignees?: string[]; owner?: string; constructor({ auth, repo, assignees, owner }: ConstructorParams) { this.service = new Octokit({ auth }); this.repo = repo; this.assignees = assignees; this.owner = owner; } createGithubIssue = ({ label, detail, title, assignees = this.assignees, owner = this.owner, repo = this.repo, }: CreateGithubIssuesParams) => { if (!owner) throw Error(`invalid owner: ${owner}`); if (!repo) throw Error(`invalid repo: ${repo}`); if (!assignees) throw Error(`invalid repo: ${repo}`); return this.service.request('POST /repos/{owner}/{repo}/issues', { label, detail, title, assignees, owner, repo, }); }; } export default GitHubService;