initial issue replicating (gitlab)
This commit is contained in:
parent
5708778ab3
commit
a94ce60ec5
|
@ -53,6 +53,7 @@ export interface RepoManager {
|
||||||
repo: Repo;
|
repo: Repo;
|
||||||
initialize: () => Promise<RepoManager>;
|
initialize: () => Promise<RepoManager>;
|
||||||
getIssue: (id: string) => Promise<Issue>;
|
getIssue: (id: string) => Promise<Issue>;
|
||||||
|
replicateIssue?: (issue: Issue) => Promise<Issue>;
|
||||||
getMergeRequest: (id: string) => Promise<MergeRequest>;
|
getMergeRequest: (id: string) => Promise<MergeRequest>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
33
src/vendor/gitlab/repomgr.ts
vendored
33
src/vendor/gitlab/repomgr.ts
vendored
|
@ -23,6 +23,7 @@ export default class GitHubRepoManager implements RepoManager {
|
||||||
vendorMgr: GitLabVendorManager;
|
vendorMgr: GitLabVendorManager;
|
||||||
repo: Repo;
|
repo: Repo;
|
||||||
repoPath: string;
|
repoPath: string;
|
||||||
|
repoId: string;
|
||||||
|
|
||||||
constructor(vendorMgr: GitLabVendorManager, repoPath: string) {
|
constructor(vendorMgr: GitLabVendorManager, repoPath: string) {
|
||||||
this.vendorMgr = vendorMgr;
|
this.vendorMgr = vendorMgr;
|
||||||
|
@ -43,17 +44,16 @@ export default class GitHubRepoManager implements RepoManager {
|
||||||
name: repoSmallPath,
|
name: repoSmallPath,
|
||||||
};
|
};
|
||||||
this.repoPath = repoPath;
|
this.repoPath = repoPath;
|
||||||
|
this.repoId = ''; // for strict null check, is replaced in .initialize
|
||||||
}
|
}
|
||||||
|
|
||||||
public async initialize() {
|
public async initialize() {
|
||||||
let meta = await this.vendorMgr._doRequest(
|
const meta = await this.vendorMgr._doRequest_gql(
|
||||||
`
|
`
|
||||||
query ($path: ID!, $ownerStr: String!, $ownerID: ID!) {
|
query ($path: ID!, $ownerStr: String!, $ownerID: ID!) {
|
||||||
project(fullPath: $path) {
|
project(fullPath: $path) {
|
||||||
|
id
|
||||||
path
|
path
|
||||||
namespace {
|
|
||||||
path
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
group(fullPath: $ownerID) {
|
group(fullPath: $ownerID) {
|
||||||
id
|
id
|
||||||
|
@ -73,8 +73,11 @@ export default class GitHubRepoManager implements RepoManager {
|
||||||
ownerID: this.repo.owner.username,
|
ownerID: this.repo.owner.username,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
assert(meta.project);
|
assert(meta.project, 'no project');
|
||||||
assert(meta.group || meta.user);
|
assert(meta.group || meta.user, 'no top-level project owner');
|
||||||
|
const [, repoId] = /\/(\d+)$/.exec(meta.project.id) || [,];
|
||||||
|
assert(repoId, 'broken project id');
|
||||||
|
this.repoId = repoId;
|
||||||
this.repo.owner.username = meta.project.path;
|
this.repo.owner.username = meta.project.path;
|
||||||
if (meta.group) {
|
if (meta.group) {
|
||||||
this.repo.owner.type = ACTOR_TYPE.ORG;
|
this.repo.owner.type = ACTOR_TYPE.ORG;
|
||||||
|
@ -85,7 +88,7 @@ export default class GitHubRepoManager implements RepoManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getIssue(number: string): Promise<Issue> {
|
public async getIssue(number: string): Promise<Issue> {
|
||||||
const resp = await this.vendorMgr._doRequest(
|
const resp = await this.vendorMgr._doRequest_gql(
|
||||||
`
|
`
|
||||||
query ($path: ID!, $id: String!) {
|
query ($path: ID!, $id: String!) {
|
||||||
project(fullPath: $path) {
|
project(fullPath: $path) {
|
||||||
|
@ -119,8 +122,22 @@ export default class GitHubRepoManager implements RepoManager {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async replicateIssue(issue: Issue) {
|
||||||
|
// yes, v4, gitlab doesn't support creating issues with graphql api 🤦♀️
|
||||||
|
const resp = await this.vendorMgr._doRequest_v4(
|
||||||
|
'POST',
|
||||||
|
`projects/${encodeURIComponent(this.repoId)}/issues`,
|
||||||
|
{
|
||||||
|
title: issue.title,
|
||||||
|
description: issue.content,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
assert(resp.iid);
|
||||||
|
return this.getIssue(resp.iid.toString());
|
||||||
|
}
|
||||||
|
|
||||||
public async getMergeRequest(number: string): Promise<MergeRequest> {
|
public async getMergeRequest(number: string): Promise<MergeRequest> {
|
||||||
const resp = await this.vendorMgr._doRequest(
|
const resp = await this.vendorMgr._doRequest_gql(
|
||||||
`
|
`
|
||||||
query ($path: ID!, $id: String!) {
|
query ($path: ID!, $id: String!) {
|
||||||
project(fullPath: $path) {
|
project(fullPath: $path) {
|
||||||
|
|
21
src/vendor/gitlab/vendormgr.ts
vendored
21
src/vendor/gitlab/vendormgr.ts
vendored
|
@ -7,6 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import got from 'got';
|
import got from 'got';
|
||||||
|
import qs from 'querystring';
|
||||||
import { VendorManager, VENDOR_TYPE, Vendor, RepoManager } from '../../types';
|
import { VendorManager, VENDOR_TYPE, Vendor, RepoManager } from '../../types';
|
||||||
import { GLQuery } from './api-types';
|
import { GLQuery } from './api-types';
|
||||||
import GitLabRepoManager from './repomgr';
|
import GitLabRepoManager from './repomgr';
|
||||||
|
@ -20,6 +21,8 @@ export interface GitLabConfig {
|
||||||
export default class GitLabVendorManager implements VendorManager<GitLabConfig> {
|
export default class GitLabVendorManager implements VendorManager<GitLabConfig> {
|
||||||
vendor: Vendor;
|
vendor: Vendor;
|
||||||
config: GitLabConfig;
|
config: GitLabConfig;
|
||||||
|
apiEndpoint: string;
|
||||||
|
v4Endpoint: string;
|
||||||
gqlEndpoint: string;
|
gqlEndpoint: string;
|
||||||
|
|
||||||
constructor(config: GitLabConfig) {
|
constructor(config: GitLabConfig) {
|
||||||
|
@ -29,7 +32,9 @@ export default class GitLabVendorManager implements VendorManager<GitLabConfig>
|
||||||
domain: config.domain,
|
domain: config.domain,
|
||||||
};
|
};
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.gqlEndpoint = `https://${this.vendor.domain}/api/graphql`;
|
this.apiEndpoint = `https://${this.vendor.domain}/api`;
|
||||||
|
this.v4Endpoint = `${this.apiEndpoint}/v4`;
|
||||||
|
this.gqlEndpoint = `${this.apiEndpoint}/graphql`;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async initialize() {
|
public async initialize() {
|
||||||
|
@ -41,7 +46,7 @@ export default class GitLabVendorManager implements VendorManager<GitLabConfig>
|
||||||
}
|
}
|
||||||
|
|
||||||
/** internal and for RepoManager */
|
/** internal and for RepoManager */
|
||||||
public async _doRequest(query: string, variables: any) {
|
public async _doRequest_gql(query: string, variables: any) {
|
||||||
return got
|
return got
|
||||||
.post(this.gqlEndpoint, {
|
.post(this.gqlEndpoint, {
|
||||||
body: JSON.stringify({ query, variables }),
|
body: JSON.stringify({ query, variables }),
|
||||||
|
@ -53,4 +58,16 @@ export default class GitLabVendorManager implements VendorManager<GitLabConfig>
|
||||||
.then((res) => JSON.parse(res.body))
|
.then((res) => JSON.parse(res.body))
|
||||||
.then((res) => res.data) as Promise<GLQuery>;
|
.then((res) => res.data) as Promise<GLQuery>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** internal and for RepoManager */
|
||||||
|
public async _doRequest_v4(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)}`, {
|
||||||
|
method,
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${this.config.token}`,
|
||||||
|
},
|
||||||
|
}).then((res) => JSON.parse(res.body));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue