return entity types

This commit is contained in:
Laura Liberda 2021-02-01 12:04:19 +01:00
parent 0538691173
commit 3c5867b3da
3 changed files with 15 additions and 0 deletions

View file

@ -57,8 +57,14 @@ export interface RepoManager {
getMergeRequest: (id: string) => Promise<MergeRequest>;
}
export enum ENTITY_TYPE {
ISSUE = 'issue',
MERGE_REQUEST = 'merge_request',
}
/** issue, merge request or whatever the fuck you need */
export interface RepoElement {
// type: ENTITY_TYPE;
id: string;
title: string;
content: string;
@ -72,6 +78,7 @@ export enum ISSUE_STATE {
}
export interface Issue extends RepoElement {
type: ENTITY_TYPE.ISSUE;
state: ISSUE_STATE;
}
@ -88,6 +95,7 @@ export enum MERGE_REQUEST_MERGABILITY {
}
export interface MergeRequest extends RepoElement {
type: ENTITY_TYPE.MERGE_REQUEST;
state: MERGE_REQUEST_STATE;
/** null if unknown */
mergability: MERGE_REQUEST_MERGABILITY | null;

View file

@ -15,6 +15,7 @@ import {
MergeRequest,
MERGE_REQUEST_STATE,
MERGE_REQUEST_MERGABILITY,
ENTITY_TYPE,
} from '../../types';
import GitHubVendorManager from './vendormgr';
import assert from 'assert';
@ -103,6 +104,7 @@ export default class GitHubRepoManager implements RepoManager {
assert(resp.repository.issue, 'no issue');
const { issue } = resp.repository;
return {
type: ENTITY_TYPE.ISSUE,
id: number,
content: issue.body,
title: issue.title,
@ -137,6 +139,7 @@ export default class GitHubRepoManager implements RepoManager {
assert(resp.createIssue.issue, 'creating issue failed');
const replicated = resp.createIssue.issue;
return {
type: ENTITY_TYPE.ISSUE,
id: replicated.number.toString(),
content: replicated.body,
title: replicated.title,
@ -170,6 +173,7 @@ export default class GitHubRepoManager implements RepoManager {
assert(resp.repository.pullRequest, 'no pull request');
const { pullRequest } = resp.repository;
return {
type: ENTITY_TYPE.MERGE_REQUEST,
id: number,
content: pullRequest.body,
title: pullRequest.title,

View file

@ -15,6 +15,7 @@ import {
MergeRequest,
MERGE_REQUEST_STATE,
MERGE_REQUEST_MERGABILITY,
ENTITY_TYPE,
} from '../../types';
import GitLabVendorManager from './vendormgr';
import assert from 'assert';
@ -109,6 +110,7 @@ export default class GitHubRepoManager implements RepoManager {
assert(resp.project.issue, 'no issue');
const { issue } = resp.project;
return {
type: ENTITY_TYPE.ISSUE,
id: number,
content: issue.description || '',
title: issue.title,
@ -160,6 +162,7 @@ export default class GitHubRepoManager implements RepoManager {
assert(resp.project.mergeRequest, 'no merge request');
const { mergeRequest } = resp.project;
return {
type: ENTITY_TYPE.MERGE_REQUEST,
id: number,
content: mergeRequest.description || '',
title: mergeRequest.title,