draft merge request getting
This commit is contained in:
parent
7ddedb0b0d
commit
81f42abf6d
33
src/types.ts
33
src/types.ts
|
@ -45,15 +45,46 @@ export interface RepoManager {
|
|||
repo: Repo;
|
||||
initialize: () => Promise<RepoManager>;
|
||||
getIssue: (id: string) => Promise<Issue>;
|
||||
getMergeRequest: (id: string) => Promise<MergeRequest>;
|
||||
}
|
||||
|
||||
export interface Issue {
|
||||
/** issue, merge request or whatever the fuck you need */
|
||||
export interface RepoElement {
|
||||
id: string;
|
||||
title: string;
|
||||
content: string;
|
||||
repo: Repo;
|
||||
}
|
||||
|
||||
/** basic */
|
||||
export enum ISSUE_STATE {
|
||||
OPEN = 'open',
|
||||
CLOSED = 'closed',
|
||||
}
|
||||
|
||||
export interface Issue extends RepoElement {
|
||||
state: ISSUE_STATE;
|
||||
}
|
||||
|
||||
export enum MERGE_REQUEST_STATE {
|
||||
OPEN = 'open',
|
||||
/** closed without merging */
|
||||
CLOSED = 'closed',
|
||||
MERGED = 'merged',
|
||||
}
|
||||
|
||||
export enum MERGE_REQUEST_MERGABILITY {
|
||||
MERGEABLE = 'mergeable',
|
||||
CONFLICTING = 'conflicting',
|
||||
}
|
||||
|
||||
export interface MergeRequest extends RepoElement {
|
||||
state: MERGE_REQUEST_STATE;
|
||||
/** null if unknown */
|
||||
mergability: MERGE_REQUEST_MERGABILITY | null;
|
||||
isDraft: boolean;
|
||||
}
|
||||
|
||||
/** the account that did an action */
|
||||
export enum ACTOR_TYPE {
|
||||
/** human person, absolutely not a sentient lizard */
|
||||
|
|
66
src/vendor/github/repomgr.ts
vendored
66
src/vendor/github/repomgr.ts
vendored
|
@ -1,4 +1,13 @@
|
|||
import { RepoManager, Issue, Repo, ACTOR_TYPE } from '../../types';
|
||||
import {
|
||||
RepoManager,
|
||||
Issue,
|
||||
Repo,
|
||||
ACTOR_TYPE,
|
||||
ISSUE_STATE,
|
||||
MergeRequest,
|
||||
MERGE_REQUEST_STATE,
|
||||
MERGE_REQUEST_MERGABILITY,
|
||||
} from '../../types';
|
||||
import GitHubVendorManager from './vendormgr';
|
||||
import assert from 'assert';
|
||||
|
||||
|
@ -91,10 +100,63 @@ export default class GitHubRepoManager implements RepoManager {
|
|||
assert(resp.repository.issue, 'no issue');
|
||||
const { issue } = resp.repository;
|
||||
return {
|
||||
id: issue.number.toString(),
|
||||
id: number,
|
||||
content: issue.body,
|
||||
title: issue.title,
|
||||
repo: this.repo,
|
||||
state: issue.closed ? ISSUE_STATE.CLOSED : ISSUE_STATE.OPEN,
|
||||
};
|
||||
}
|
||||
|
||||
public async getMergeRequest(number: string): Promise<MergeRequest> {
|
||||
const resp = await this.vendorMgr._doRequest(
|
||||
`
|
||||
query Query($owner: String!, $name: String!, $number: Int!) {
|
||||
repository(owner: $owner, name: $name) {
|
||||
pullRequest(number: $number) {
|
||||
title
|
||||
body
|
||||
isDraft
|
||||
closed
|
||||
closedAt
|
||||
mergeable
|
||||
merged
|
||||
mergedAt
|
||||
mergedBy {
|
||||
login
|
||||
}
|
||||
labels(first: 0) {
|
||||
nodes {
|
||||
name
|
||||
color
|
||||
description
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
{
|
||||
owner: this.repo.owner.username,
|
||||
name: this.repo.name,
|
||||
number: parseInt(number, 10),
|
||||
},
|
||||
);
|
||||
assert(resp.repository, 'no repository');
|
||||
assert(resp.repository.pullRequest, 'no pull request');
|
||||
const { pullRequest } = resp.repository;
|
||||
return {
|
||||
id: number,
|
||||
content: pullRequest.body,
|
||||
title: pullRequest.title,
|
||||
repo: this.repo,
|
||||
state: pullRequest.closed ? MERGE_REQUEST_STATE.CLOSED : MERGE_REQUEST_STATE.OPEN,
|
||||
mergability: {
|
||||
MERGEABLE: MERGE_REQUEST_MERGABILITY.MERGEABLE,
|
||||
CONFLICTING: MERGE_REQUEST_MERGABILITY.CONFLICTING,
|
||||
UNKNOWN: null,
|
||||
}[pullRequest.mergeable],
|
||||
isDraft: pullRequest.isDraft,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue