From 7af3f35baf4e0e51cbe19ece68c115c0cf58b623 Mon Sep 17 00:00:00 2001 From: ssube Date: Tue, 11 Aug 2020 19:37:00 -0500 Subject: [PATCH] feat(remote): sketch out interface, stub github/gitlab remotes --- src/remote/github.ts | 44 ++++++++++++++++++++++++++++ src/remote/gitlab.ts | 45 ++++++++++++++++++++++++++++ src/remote/index.ts | 70 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 src/remote/github.ts create mode 100644 src/remote/gitlab.ts create mode 100644 src/remote/index.ts diff --git a/src/remote/github.ts b/src/remote/github.ts new file mode 100644 index 0000000..5ca0977 --- /dev/null +++ b/src/remote/github.ts @@ -0,0 +1,44 @@ +import { NotImplementedError } from '@apextoaster/js-utils'; + +import { IssueUpdate, LabelUpdate, Remote } from '.'; + +/** + * Github/Octokit API implementation of the `Remote` contract. + */ +export class GithubRemote implements Remote { + public async createComment() { + throw new NotImplementedError(); + } + + public async createLabel(): Promise { + throw new NotImplementedError(); + } + + public async deleteLabel(): Promise { + throw new NotImplementedError(); + } + + public async getIssue(): Promise> { + throw new NotImplementedError(); + } + + public async getLabel(): Promise> { + throw new NotImplementedError(); + } + + public async listIssues(): Promise> { + throw new NotImplementedError(); + } + + public async listLabels(): Promise> { + throw new NotImplementedError(); + } + + public async updateIssue(): Promise { + throw new NotImplementedError(); + } + + public async updateLabel(): Promise { + throw new NotImplementedError(); + } +} diff --git a/src/remote/gitlab.ts b/src/remote/gitlab.ts new file mode 100644 index 0000000..1aa0823 --- /dev/null +++ b/src/remote/gitlab.ts @@ -0,0 +1,45 @@ +import { NotImplementedError } from '@apextoaster/js-utils'; + +import { IssueUpdate, LabelUpdate, Remote } from '.'; + +/** + * Gitlab API implementation of the `Remote` contract. + */ +export class GitlabRemote implements Remote { + public async createComment() { + throw new NotImplementedError(); + } + + public async createLabel(): Promise { + throw new NotImplementedError(); + } + + public async deleteLabel(): Promise { + throw new NotImplementedError(); + } + + public async getIssue(): Promise> { + throw new NotImplementedError(); + } + + public async getLabel(): Promise> { + throw new NotImplementedError(); + } + + public async listIssues(): Promise> { + throw new NotImplementedError(); + } + + public async listLabels(): Promise> { + throw new NotImplementedError(); + } + + public async updateIssue(): Promise { + throw new NotImplementedError(); + } + + public async updateLabel(): Promise { + throw new NotImplementedError(); + } +} + diff --git a/src/remote/index.ts b/src/remote/index.ts new file mode 100644 index 0000000..5ba7b3a --- /dev/null +++ b/src/remote/index.ts @@ -0,0 +1,70 @@ +export interface LabelQuery { + project: string; + name: string; +} + +export interface IssueQuery { + project: string; + issue: string; +} + +export interface CommentUpdate extends IssueQuery { + comment: string; +} + +export interface IssueUpdate extends IssueQuery { + labels: Array; + name: string; +} + +export interface LabelUpdate extends LabelQuery { + color: string; + desc: string; +} + +/** + * Basic functions which every remote API must provide. + */ +export interface Remote { + /** + * Add a comment to an issue (for attribution and auditing). + */ + createComment(options: CommentUpdate): Promise; + + /** + * Create a new label. + */ + createLabel(options: LabelQuery): Promise; + + /** + * Delete an existing label. + */ + deleteLabel(options: LabelQuery): Promise; + + /** + * Get details of a single issue. + */ + getIssue(options: IssueQuery): Promise>; + + /** + * Get details of a single label. + */ + getLabel(options: LabelQuery): Promise>; + + /** + * List all issues. + */ + listIssues(): Promise>; + + /** + * List all labels. + */ + listLabels(): Promise>; + + /** + * Set labels on an issue. + */ + updateIssue(options: IssueUpdate): Promise; + + updateLabel(options: LabelUpdate): Promise; +}