fetching MR commit list
This commit is contained in:
parent
1d2bb6317e
commit
2496327b39
10
src/types.ts
10
src/types.ts
|
@ -61,6 +61,7 @@ export interface RepoManager {
|
|||
export enum ENTITY_TYPE {
|
||||
ISSUE = 'issue',
|
||||
MERGE_REQUEST = 'merge_request',
|
||||
COMMIT = 'commit',
|
||||
}
|
||||
|
||||
/** issue, merge request or whatever the fuck you need */
|
||||
|
@ -68,8 +69,10 @@ export interface RepoElement {
|
|||
type: ENTITY_TYPE;
|
||||
id: string;
|
||||
title: string;
|
||||
/** text body of the entity */
|
||||
content: string;
|
||||
repo: Repo;
|
||||
/** URL to a user-readable page */
|
||||
url: string;
|
||||
}
|
||||
|
||||
|
@ -101,9 +104,16 @@ export interface MergeRequest extends RepoElement {
|
|||
state: MERGE_REQUEST_STATE;
|
||||
/** null if unknown */
|
||||
mergability: MERGE_REQUEST_MERGABILITY | null;
|
||||
commits: Commit[];
|
||||
isDraft: boolean;
|
||||
}
|
||||
|
||||
export interface Commit extends RepoElement {
|
||||
type: ENTITY_TYPE.COMMIT;
|
||||
patchURL: string;
|
||||
diffURL: string;
|
||||
}
|
||||
|
||||
/** the account that did an action */
|
||||
export enum ACTOR_TYPE {
|
||||
/** human person, absolutely not a sentient lizard */
|
||||
|
|
34
src/vendor/github/repomgr.ts
vendored
34
src/vendor/github/repomgr.ts
vendored
|
@ -9,6 +9,7 @@
|
|||
import {
|
||||
RepoManager,
|
||||
Issue,
|
||||
Commit,
|
||||
Repo,
|
||||
ACTOR_TYPE,
|
||||
ISSUE_STATE,
|
||||
|
@ -19,7 +20,7 @@ import {
|
|||
} from '../../types';
|
||||
import GitHubVendorManager from './vendormgr';
|
||||
import assert from 'assert';
|
||||
import { GHMutation, GHMutationCreateIssueArgs } from './api-types';
|
||||
import { GHMutation, GHMutationCreateIssueArgs, GHPullRequestCommit } from './api-types';
|
||||
|
||||
export default class GitHubRepoManager implements RepoManager {
|
||||
vendorMgr: GitHubVendorManager;
|
||||
|
@ -164,10 +165,20 @@ export default class GitHubRepoManager implements RepoManager {
|
|||
isDraft
|
||||
mergeable
|
||||
state
|
||||
commits(first: 250) {
|
||||
nodes {
|
||||
commit {
|
||||
messageHeadline
|
||||
messageBody
|
||||
oid
|
||||
}
|
||||
}
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
`,
|
||||
{
|
||||
owner: this.repo.owner.username,
|
||||
name: this.repo.name,
|
||||
|
@ -177,6 +188,11 @@ export default class GitHubRepoManager implements RepoManager {
|
|||
assert(resp.repository, 'no repository');
|
||||
assert(resp.repository.pullRequest, 'no pull request');
|
||||
const { pullRequest } = resp.repository;
|
||||
assert(pullRequest.commits.nodes, 'no commits in pull request (?)');
|
||||
assert(
|
||||
pullRequest.commits.nodes.length === pullRequest.commits.totalCount,
|
||||
"no replicating today, github is fucked up and the commit pagination doesn't fucking work",
|
||||
);
|
||||
return {
|
||||
type: ENTITY_TYPE.MERGE_REQUEST,
|
||||
id: number,
|
||||
|
@ -193,6 +209,20 @@ export default class GitHubRepoManager implements RepoManager {
|
|||
CONFLICTING: MERGE_REQUEST_MERGABILITY.CONFLICTING,
|
||||
UNKNOWN: null,
|
||||
}[pullRequest.mergeable],
|
||||
// for some fucking reason GitHub declared that the array of commits could contain null values
|
||||
commits: (pullRequest.commits.nodes.filter((n) => !!n) as GHPullRequestCommit[])
|
||||
.map((n) => n.commit)
|
||||
.map<Commit>((c) => ({
|
||||
type: ENTITY_TYPE.COMMIT,
|
||||
id: c.oid,
|
||||
title: c.messageHeadline,
|
||||
content: c.messageBody,
|
||||
repo: this.repo,
|
||||
url: `${this.repo.url}/commit/${c.oid}`,
|
||||
// won't work on private repositories
|
||||
patchURL: `${this.repo.url}/commit/${c.oid}.patch`,
|
||||
diffURL: `${this.repo.url}/commit/${c.oid}.diff`,
|
||||
})),
|
||||
isDraft: pullRequest.isDraft,
|
||||
url: `${this.repo.url}/pull/${pullRequest.number}`,
|
||||
};
|
||||
|
|
18
src/vendor/gitlab/repomgr.ts
vendored
18
src/vendor/gitlab/repomgr.ts
vendored
|
@ -10,6 +10,7 @@ import {
|
|||
RepoManager,
|
||||
Issue,
|
||||
Repo,
|
||||
Commit,
|
||||
ACTOR_TYPE,
|
||||
ISSUE_STATE,
|
||||
MergeRequest,
|
||||
|
@ -17,6 +18,7 @@ import {
|
|||
MERGE_REQUEST_MERGABILITY,
|
||||
ENTITY_TYPE,
|
||||
} from '../../types';
|
||||
import { GL4MergeRequestCommit } from './rest-api-types';
|
||||
import GitLabVendorManager from './vendormgr';
|
||||
import assert from 'assert';
|
||||
|
||||
|
@ -165,6 +167,12 @@ export default class GitHubRepoManager implements RepoManager {
|
|||
assert(resp.project, 'no project');
|
||||
assert(resp.project.mergeRequest, 'no merge request');
|
||||
const { mergeRequest } = resp.project;
|
||||
// for some fucking reason this is not available under the GQL API
|
||||
// https://gitlab.com/gitlab-org/gitlab/-/issues/300780
|
||||
const commits = await this.vendorMgr._doRequest_v4<GL4MergeRequestCommit[]>(
|
||||
'GET',
|
||||
`projects/${encodeURIComponent(this.repoId)}/merge_requests/${number}/commits`,
|
||||
);
|
||||
return {
|
||||
type: ENTITY_TYPE.MERGE_REQUEST,
|
||||
id: number,
|
||||
|
@ -186,6 +194,16 @@ export default class GitHubRepoManager implements RepoManager {
|
|||
mergeRequest.mergeStatus || ''
|
||||
] || null,
|
||||
isDraft: mergeRequest.workInProgress,
|
||||
commits: commits.map<Commit>((c) => ({
|
||||
type: ENTITY_TYPE.COMMIT,
|
||||
id: c.id,
|
||||
title: c.title,
|
||||
content: c.message,
|
||||
repo: this.repo,
|
||||
url: `${this.repo.url}/-/commit/${c.id}`,
|
||||
diffURL: `${this.repo.url}/-/commit/${c.id}.diff`,
|
||||
patchURL: `${this.repo.url}/-/commit/${c.id}.patch`,
|
||||
})),
|
||||
url: `${this.repo.url}/-/merge_requests/${mergeRequest.iid}`,
|
||||
};
|
||||
}
|
||||
|
|
17
src/vendor/gitlab/rest-api-types.ts
vendored
Normal file
17
src/vendor/gitlab/rest-api-types.ts
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
/**
|
||||
* Roses are red,
|
||||
* Violets are blue,
|
||||
* GitLab is fucked up,
|
||||
* so this code needs too
|
||||
*/
|
||||
|
||||
export interface GL4MergeRequestCommit {
|
||||
id: string;
|
||||
short_id: string;
|
||||
title: string;
|
||||
author_name: string;
|
||||
author_email: string;
|
||||
/** "2012-09-20T09:06:12+03:00" */
|
||||
created_at: string;
|
||||
message: string;
|
||||
}
|
4
src/vendor/gitlab/vendormgr.ts
vendored
4
src/vendor/gitlab/vendormgr.ts
vendored
|
@ -60,7 +60,7 @@ export default class GitLabVendorManager implements VendorManager<GitLabConfig>
|
|||
}
|
||||
|
||||
/** internal and for RepoManager */
|
||||
public async _doRequest_v4(method: 'GET' | 'POST', path: string, query?: any) {
|
||||
public async _doRequest_v4<T = any>(method: 'GET' | 'POST', path: string, query?: any) {
|
||||
// did you know that gitlab graphql api is fucked up
|
||||
// and does not support some of the core functionality like creating issues?
|
||||
return got(`${this.v4Endpoint}/${path}?${qs.stringify(query)}`, {
|
||||
|
@ -68,6 +68,6 @@ export default class GitLabVendorManager implements VendorManager<GitLabConfig>
|
|||
headers: {
|
||||
Authorization: `Bearer ${this.config.token}`,
|
||||
},
|
||||
}).then((res) => JSON.parse(res.body));
|
||||
}).then((res) => JSON.parse(res.body) as T);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue