diff --git a/src/vendor/gitlab/repomgr.ts b/src/vendor/gitlab/repomgr.ts index ca9361d..8c027fe 100644 --- a/src/vendor/gitlab/repomgr.ts +++ b/src/vendor/gitlab/repomgr.ts @@ -18,6 +18,7 @@ import { MERGE_REQUEST_MERGABILITY, ENTITY_TYPE, } from '../../types'; +import { GLIssue, GLMutation, GLMutationCreateIssueArgs } from './api-types'; import { GL4MergeRequestCommit } from './rest-api-types'; import GitLabVendorManager from './vendormgr'; import assert from 'assert'; @@ -113,9 +114,13 @@ export default class GitHubRepoManager implements RepoManager { assert(resp.project, 'no project'); assert(resp.project.issue, 'no issue'); const { issue } = resp.project; + return this._parseIssue(issue); + } + + public _parseIssue(issue: GLIssue): Issue { return { type: ENTITY_TYPE.ISSUE, - id: number, + id: issue.iid, content: issue.description || '', title: issue.title, repo: this.repo, @@ -130,17 +135,34 @@ 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`, + const resp = await this.vendorMgr._doRequest_gql( + ` + mutation ($input: CreateIssueInput!) { + createIssue(input: $input) { + issue { + iid + title + description + state + } + } + } + `, { - title: issue.title, - description: issue.content, + input: { + projectPath: this.repoPath, + title: issue.title, + description: issue.content, + }, }, ); - assert(resp.iid); - return this.getIssue(resp.iid.toString()); + assert(resp.createIssue, 'creating issue failed for unknown reason'); + assert( + !Array.isArray(resp.createIssue.errors) || resp.createIssue.errors.length === 0, + `GitLab said: ${(resp.createIssue.errors || []).map((e) => `"${e}"`).join(', ')}`, + ); + assert(resp.createIssue.issue, 'creating issue failed for unknown reason (2)'); + return this._parseIssue(resp.createIssue.issue); } public async getMergeRequest(number: string): Promise { diff --git a/src/vendor/gitlab/vendormgr.ts b/src/vendor/gitlab/vendormgr.ts index 97314df..24f9937 100644 --- a/src/vendor/gitlab/vendormgr.ts +++ b/src/vendor/gitlab/vendormgr.ts @@ -46,7 +46,7 @@ export default class GitLabVendorManager implements VendorManager } /** internal and for RepoManager */ - public async _doRequest_gql(query: string, variables: any) { + public async _doRequest_gql(query: string, variables: D) { return got .post(this.gqlEndpoint, { body: JSON.stringify({ query, variables }), @@ -56,7 +56,7 @@ export default class GitLabVendorManager implements VendorManager }, }) .then((res) => JSON.parse(res.body)) - .then((res) => res.data) as Promise; + .then((res) => res.data) as Promise; } /** internal and for RepoManager */