From 3415a15af79990d50366a15c3039605f57fd5b1c Mon Sep 17 00:00:00 2001 From: ivan katliarchuk Date: Sat, 8 Oct 2022 15:55:55 +0100 Subject: [PATCH 1/3] gitlab: improve test coverage --- source/platforms/gitlab/GitLabAPI.ts | 84 ++--- .../gitlab/_tests/_gitlab_api.test.ts | 34 ++ .../fixtures/updateMergeRequestInfo.json | 341 ++++++++++++++++++ 3 files changed, 406 insertions(+), 53 deletions(-) create mode 100644 source/platforms/gitlab/_tests/fixtures/updateMergeRequestInfo.json diff --git a/source/platforms/gitlab/GitLabAPI.ts b/source/platforms/gitlab/GitLabAPI.ts index 1448e4fe8..7a3ca3f2f 100644 --- a/source/platforms/gitlab/GitLabAPI.ts +++ b/source/platforms/gitlab/GitLabAPI.ts @@ -57,22 +57,26 @@ export function getGitLabAPICredentialsFromEnv(env: Env): GitLabAPICredentials { class GitLabAPI { fetch: typeof fetch - private api: InstanceType + private readonly api: InstanceType private readonly hostURL: string private readonly d = debug("GitLabAPI") + private readonly repoSlug: string + private readonly prId: number constructor(public readonly repoMetadata: RepoMetaData, public readonly repoCredentials: GitLabAPICredentials) { this.fetch = fetch this.api = new Gitlab(repoCredentials) this.hostURL = repoCredentials.host + this.repoSlug = repoMetadata.repoSlug + this.prId = Number(repoMetadata.pullRequestID) } get projectURL(): string { - return `${this.hostURL}/${this.repoMetadata.repoSlug}` + return `${this.hostURL}/${this.repoSlug}` } get mergeRequestURL(): string { - return `${this.projectURL}/merge_requests/${this.repoMetadata.pullRequestID}` + return `${this.projectURL}/merge_requests/${this.prId}` } get apiInstance() { @@ -87,57 +91,45 @@ class GitLabAPI { } getMergeRequestInfo = async (): Promise => { - this.d(`getMergeRequestInfo for repo: ${this.repoMetadata.repoSlug} pr: ${this.repoMetadata.pullRequestID}`) - const mr = (await this.api.MergeRequests.show( - this.repoMetadata.repoSlug, - Number(this.repoMetadata.pullRequestID) - )) as GitLabMR + this.d(`getMergeRequestInfo for repo: ${this.repoSlug} pr: ${this.prId}`) + const mr = (await this.api.MergeRequests.show(this.repoSlug, Number(this.prId))) as GitLabMR this.d("getMergeRequestInfo", mr) return mr } updateMergeRequestInfo = async (changes: object): Promise => { - const mr = this.api.MergeRequests.edit(this.repoMetadata.repoSlug, Number(this.repoMetadata.pullRequestID), changes) - + const mr = this.api.MergeRequests.edit(this.repoSlug, this.prId, changes) this.d("updateMergeRequestInfo", mr) - return mr } getMergeRequestApprovals = async (): Promise => { - this.d(`getMergeRequestApprovals for repo: ${this.repoMetadata.repoSlug} pr: ${this.repoMetadata.pullRequestID}`) - const approvals = (await this.api.MergeRequests.approvals(this.repoMetadata.repoSlug, { - mergerequestIid: Number(this.repoMetadata.pullRequestID), + this.d(`getMergeRequestApprovals for repo: ${this.repoSlug} pr: ${this.prId}`) + const approvals = (await this.api.MergeRequests.approvals(this.repoSlug, { + mergerequestIid: Number(this.prId), })) as GitLabApproval this.d("getMergeRequestApprovals", approvals) return approvals } getMergeRequestChanges = async (): Promise => { - this.d(`getMergeRequestChanges for repo: ${this.repoMetadata.repoSlug} pr: ${this.repoMetadata.pullRequestID}`) - const mr = (await this.api.MergeRequests.changes( - this.repoMetadata.repoSlug, - Number(this.repoMetadata.pullRequestID) - )) as GitLabMRChanges - + this.d(`getMergeRequestChanges for repo: ${this.repoSlug} pr: ${this.prId}`) + const mr = (await this.api.MergeRequests.changes(this.repoSlug, this.prId)) as GitLabMRChanges this.d("getMergeRequestChanges", mr.changes) return mr.changes } getMergeRequestCommits = async (): Promise => { - this.d("getMergeRequestCommits", this.repoMetadata.repoSlug, this.repoMetadata.pullRequestID) - const commits = (await this.api.MergeRequests.commits( - this.repoMetadata.repoSlug, - Number(this.repoMetadata.pullRequestID) - )) as GitLabMRCommit[] + this.d("getMergeRequestCommits", this.repoSlug, this.prId) + const commits = (await this.api.MergeRequests.commits(this.repoSlug, this.prId)) as GitLabMRCommit[] this.d("getMergeRequestCommits", commits) return commits } getMergeRequestNotes = async (): Promise => { - this.d("getMergeRequestNotes", this.repoMetadata.repoSlug, this.repoMetadata.pullRequestID) + this.d("getMergeRequestNotes", this.repoSlug, this.prId) const api = this.api.MergeRequestNotes - const notes = (await api.all(this.repoMetadata.repoSlug, this.repoMetadata.pullRequestID, {})) as GitLabNote[] + const notes = (await api.all(this.repoSlug, this.prId, {})) as GitLabNote[] this.d("getMergeRequestNotes", notes) return notes } @@ -151,17 +143,10 @@ class GitLabAPI { } createMergeRequestDiscussion = async (content: string, position: GitLabDiscussionTextPosition): Promise => { - this.d( - "createMergeRequestDiscussion", - this.repoMetadata.repoSlug, - this.repoMetadata.pullRequestID, - content, - position - ) + this.d("createMergeRequestDiscussion", this.repoSlug, this.prId, content, position) const api = this.api.MergeRequestDiscussions - try { - const result = await api.create(this.repoMetadata.repoSlug, this.repoMetadata.pullRequestID, content, { + const result = await api.create(this.repoSlug, this.prId, content, { position: position, }) this.d("createMergeRequestDiscussion", result) @@ -173,12 +158,10 @@ class GitLabAPI { } createMergeRequestNote = async (body: string): Promise => { - this.d("createMergeRequestNote", this.repoMetadata.repoSlug, this.repoMetadata.pullRequestID, body) - const api = this.api.MergeRequestNotes - + this.d("createMergeRequestNote", this.repoSlug, this.prId, body) try { this.d("createMergeRequestNote") - const note = (await api.create(this.repoMetadata.repoSlug, this.repoMetadata.pullRequestID, body)) as GitLabNote + const note = (await this.api.MergeRequestNotes.create(this.repoSlug, this.prId, body)) as GitLabNote this.d("createMergeRequestNote", note) return note } catch (e) { @@ -189,10 +172,9 @@ class GitLabAPI { } updateMergeRequestNote = async (id: number, body: string): Promise => { - this.d("updateMergeRequestNote", this.repoMetadata.repoSlug, this.repoMetadata.pullRequestID, id, body) - const api = this.api.MergeRequestNotes + this.d("updateMergeRequestNote", this.repoSlug, this.prId, id, body) try { - const note = (await api.edit(this.repoMetadata.repoSlug, this.repoMetadata.pullRequestID, id, body)) as GitLabNote + const note = (await this.api.MergeRequestNotes.edit(this.repoSlug, this.prId, id, body)) as GitLabNote this.d("updateMergeRequestNote", note) return note } catch (e) { @@ -204,11 +186,9 @@ class GitLabAPI { // note: deleting the _only_ note in a discussion also deletes the discussion \o/ deleteMergeRequestNote = async (id: number): Promise => { - this.d("deleteMergeRequestNote", this.repoMetadata.repoSlug, this.repoMetadata.pullRequestID, id) - const api = this.api.MergeRequestNotes - + this.d("deleteMergeRequestNote", this.repoSlug, this.prId, id) try { - await api.remove(this.repoMetadata.repoSlug, this.repoMetadata.pullRequestID, id) + await this.api.MergeRequestNotes.remove(this.repoSlug, this.prId, id) this.d("deleteMergeRequestNote", true) return true } catch (e) { @@ -220,7 +200,7 @@ class GitLabAPI { getFileContents = async (path: string, slug?: string, ref?: string): Promise => { this.d(`getFileContents requested for path:${path}, slug:${slug}, ref:${ref}`) const api = this.api.RepositoryFiles - const projectId = slug || this.repoMetadata.repoSlug + const projectId = slug || this.repoSlug // Use the current state of PR if no ref is passed if (!ref) { const mr: GitLabMR = await this.getMergeRequestInfo() @@ -248,17 +228,15 @@ class GitLabAPI { return this.getMergeRequestChanges() } const api = this.api.Repositories - const projectId = this.repoMetadata.repoSlug + const projectId = this.repoSlug const compare = (await api.compare(projectId, base, head)) as GitLabRepositoryCompare return compare.diffs } addLabels = async (...labels: string[]): Promise => { const mr = await this.getMergeRequestInfo() - mr.labels.push(...labels) - - await this.updateMergeRequestInfo({ labels: mr.labels.join(",") }) - + const noDuplicates = new Set([...(mr.labels as string[]), ...labels]) + await this.updateMergeRequestInfo({ labels: Array.from(noDuplicates).join(",") }) return true } diff --git a/source/platforms/gitlab/_tests/_gitlab_api.test.ts b/source/platforms/gitlab/_tests/_gitlab_api.test.ts index 5f6cd4011..0be8e173c 100644 --- a/source/platforms/gitlab/_tests/_gitlab_api.test.ts +++ b/source/platforms/gitlab/_tests/_gitlab_api.test.ts @@ -187,4 +187,38 @@ describe("GitLab API", () => { } nockDone() }) + + it("updateMergeRequestInfo", async () => { + const { nockDone } = await nockBack("updateMergeRequestInfo.json") + const titleToUpdate = "update merge request" + const result = await api.updateMergeRequestInfo({ title: titleToUpdate }) + nockDone() + expect(JSON.stringify(result)).toContain(titleToUpdate) + }) + + describe("mergerequest (add|remove)labels", () => { + let nockDone: { nockDone: () => void } + + afterAll(async () => { + nockDone.nockDone() + }) + + it("addLabels", async () => { + nockDone = await nockBack("updateMergeRequestInfo.json") + const result = await api.addLabels("first-label", "second-label") + expect(result).toBeTruthy() + }) + + it("removeLabels", async () => { + nockDone = await nockBack("updateMergeRequestInfo.json") + const result = await api.removeLabels("remove-me-label") + expect(result).toBeTruthy() + }) + + it("addLabels with no duplicates", async () => { + nockDone = await nockBack("updateMergeRequestInfo.json") + const result = await api.addLabels("danger-bot", "new-label") + expect(result).toBeTruthy() + }) + }) }) diff --git a/source/platforms/gitlab/_tests/fixtures/updateMergeRequestInfo.json b/source/platforms/gitlab/_tests/fixtures/updateMergeRequestInfo.json new file mode 100644 index 000000000..ed7a5a261 --- /dev/null +++ b/source/platforms/gitlab/_tests/fixtures/updateMergeRequestInfo.json @@ -0,0 +1,341 @@ +[ + { + "scope": "https://gitlab.com:443", + "method": "PUT", + "path": "/api/v4/projects/gitlab-org%2Fgitlab-foss/merge_requests/27117", + "body": "{\"title\":\"update merge request\"}", + "status": 201, + "reqheaders": { + "user-agent": "gitbeaker", + "private-token": "FAKE_DANGER_GITLAB_API_TOKEN", + "content-type": "application/json", + "content-length": "32", + "accept-encoding": "gzip, deflate, br" + }, + "response": { + "id": 27253868, + "iid": 27117, + "project_id": 13083, + "title": "update merge request", + "description": "merge request should have being updated with api", + "state": "merged", + "created_at": "2019-04-08T10:59:38.140Z", + "updated_at": "2019-05-02T14:34:54.068Z", + "merged_by": { + "id": 283999, + "name": "Douglas Barbosa Alexandre", + "username": "dbalexandre", + "state": "active", + "avatar_url": "https://gl-canary.freetls.fastly.net/uploads/-/system/user/avatar/283999/avatar.png", + "web_url": "https://gitlab.com/dbalexandre" + }, + "merged_at": "2019-04-09T13:57:11.931Z", + "closed_by": null, + "closed_at": null, + "target_branch": "master", + "source_branch": "stable-reviewer-roulette", + "user_notes_count": 4, + "upvotes": 3, + "downvotes": 0, + "assignee": { + "id": 283999, + "name": "Douglas Barbosa Alexandre", + "username": "dbalexandre", + "state": "active", + "avatar_url": "https://gl-canary.freetls.fastly.net/uploads/-/system/user/avatar/283999/avatar.png", + "web_url": "https://gitlab.com/dbalexandre" + }, + "author": { + "id": 443319, + "name": "Sean McGivern", + "username": "smcgivern", + "state": "active", + "avatar_url": "https://gl-canary.freetls.fastly.net/uploads/-/system/user/avatar/443319/avatar.png", + "web_url": "https://gitlab.com/smcgivern" + }, + "assignees": [ + { + "id": 283999, + "name": "Douglas Barbosa Alexandre", + "username": "dbalexandre", + "state": "active", + "avatar_url": "https://gl-canary.freetls.fastly.net/uploads/-/system/user/avatar/283999/avatar.png", + "web_url": "https://gitlab.com/dbalexandre" + } + ], + "source_project_id": 13083, + "target_project_id": 13083, + "labels": ["danger-bot", "Plan", "backend", "backstage", "remove-me-label"], + "work_in_progress": false, + "merge_when_pipeline_succeeds": false, + "merge_status": "can_be_merged", + "sha": "28531ab43666b5fdf37e0a70db3bcbf7d3f92183", + "merge_commit_sha": "58d4099c1469dba9ff850733ba29da11f6eeb158", + "discussion_locked": null, + "should_remove_source_branch": null, + "force_remove_source_branch": true, + "reference": "!27117", + "web_url": "https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/27117", + "squash": false, + "subscribed": false, + "changes_count": "1", + "latest_build_started_at": "2019-04-08T10:56:58.249Z", + "latest_build_finished_at": "2019-04-08T11:56:52.871Z", + "first_deployed_to_production_at": null, + "diff_refs": { + "base_sha": "50cd5d9b776848cf23f1fd1ec52789dbdf946185", + "head_sha": "28531ab43666b5fdf37e0a70db3bcbf7d3f92183", + "start_sha": "50cd5d9b776848cf23f1fd1ec52789dbdf946185" + }, + "merge_error": null, + "approvals_before_merge": 1 + }, + "rawHeaders": ["Server", "nginx"] + }, + { + "scope": "https://gitlab.com:443", + "method": "GET", + "path": "/api/v4/projects/gitlab-org%2Fgitlab-foss/merge_requests/27117", + "body": "", + "status": 200, + "response": { + "id": 27253868, + "iid": 27117, + "project_id": 13083, + "title": "Stable reviewer roulette", + "description": "some description", + "state": "merged", + "created_at": "2019-04-08T10:59:38.140Z", + "updated_at": "2019-05-02T14:34:54.068Z", + "merged_by": { + "id": 283999, + "name": "Douglas Barbosa Alexandre", + "username": "dbalexandre", + "state": "active", + "avatar_url": "https://gl-canary.freetls.fastly.net/uploads/-/system/user/avatar/283999/avatar.png", + "web_url": "https://gitlab.com/dbalexandre" + }, + "merged_at": "2019-04-09T13:57:11.931Z", + "closed_by": null, + "closed_at": null, + "target_branch": "master", + "source_branch": "stable-reviewer-roulette", + "user_notes_count": 4, + "upvotes": 3, + "downvotes": 0, + "assignee": { + "id": 283999, + "name": "Douglas Barbosa Alexandre", + "username": "dbalexandre", + "state": "active", + "avatar_url": "https://gl-canary.freetls.fastly.net/uploads/-/system/user/avatar/283999/avatar.png", + "web_url": "https://gitlab.com/dbalexandre" + }, + "source_project_id": 13083, + "target_project_id": 13083, + "labels": ["danger-bot", "Plan", "backend", "backstage"], + "work_in_progress": false, + "milestone": { + "id": 655280, + "iid": 28, + "group_id": 9970, + "title": "11.11", + "description": "", + "state": "active", + "created_at": "2018-09-21T19:08:37.027Z", + "updated_at": "2019-01-16T19:48:19.411Z", + "due_date": "2019-05-22", + "start_date": "2019-04-08", + "web_url": "https://gitlab.com/groups/gitlab-org/-/milestones/28" + }, + "merge_when_pipeline_succeeds": false, + "merge_status": "can_be_merged", + "sha": "28531ab43666b5fdf37e0a70db3bcbf7d3f92183", + "merge_commit_sha": "58d4099c1469dba9ff850733ba29da11f6eeb158", + "discussion_locked": null, + "should_remove_source_branch": null, + "force_remove_source_branch": true, + "reference": "!27117", + "web_url": "https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/27117", + "time_stats": { + "time_estimate": 0, + "total_time_spent": 0, + "human_time_estimate": null, + "human_total_time_spent": null + }, + "squash": false, + "subscribed": false, + "changes_count": "1", + "latest_build_started_at": "2019-04-08T10:56:58.249Z", + "latest_build_finished_at": "2019-04-08T11:56:52.871Z", + "first_deployed_to_production_at": null, + "diff_refs": { + "base_sha": "50cd5d9b776848cf23f1fd1ec52789dbdf946185", + "head_sha": "28531ab43666b5fdf37e0a70db3bcbf7d3f92183", + "start_sha": "50cd5d9b776848cf23f1fd1ec52789dbdf946185" + }, + "merge_error": null, + "user": { + "can_merge": false + }, + "approvals_before_merge": 1 + }, + "rawHeaders": ["Server", "nginx"] + }, + { + "scope": "https://gitlab.com:443", + "method": "PUT", + "path": "/api/v4/projects/gitlab-org%2Fgitlab-foss/merge_requests/27117", + "body": "{\"labels\":\"danger-bot,Plan,backend,backstage,first-label,second-label\"}", + "status": 201, + "reqheaders": {}, + "response": { + "id": 27253868, + "iid": 27117, + "project_id": 13083, + "title": "update merge request", + "description": "merge request. update labels", + "state": "merged", + "created_at": "2019-04-08T10:59:38.140Z", + "updated_at": "2019-05-02T14:34:54.068Z", + "merged_by": { + "id": 283999, + "name": "Douglas Barbosa Alexandre", + "username": "dbalexandre", + "state": "active", + "avatar_url": "https://gl-canary.freetls.fastly.net/uploads/-/system/user/avatar/283999/avatar.png", + "web_url": "https://gitlab.com/dbalexandre" + }, + "merged_at": "2019-04-09T13:57:11.931Z", + "closed_by": null, + "closed_at": null, + "target_branch": "master", + "source_branch": "stable-reviewer-roulette", + "user_notes_count": 4, + "upvotes": 3, + "downvotes": 0, + "source_project_id": 13083, + "target_project_id": 13083, + "labels": ["danger-bot", "Plan", "backend", "backstage", "first-label", "second-label"], + "work_in_progress": false, + "merge_when_pipeline_succeeds": false, + "merge_status": "can_be_merged", + "sha": "28531ab43666b5fdf37e0a70db3bcbf7d3f92183", + "merge_commit_sha": "58d4099c1469dba9ff850733ba29da11f6eeb158", + "discussion_locked": null, + "should_remove_source_branch": null, + "force_remove_source_branch": true, + "reference": "!27117", + "web_url": "https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/27117", + "squash": false, + "subscribed": false, + "changes_count": "1", + "latest_build_started_at": "2019-04-08T10:56:58.249Z", + "latest_build_finished_at": "2019-04-08T11:56:52.871Z", + "first_deployed_to_production_at": null, + "diff_refs": { + "base_sha": "50cd5d9b776848cf23f1fd1ec52789dbdf946185", + "head_sha": "28531ab43666b5fdf37e0a70db3bcbf7d3f92183", + "start_sha": "50cd5d9b776848cf23f1fd1ec52789dbdf946185" + }, + "merge_error": null, + "user": { + "can_merge": false + }, + "approvals_before_merge": 1 + }, + "rawHeaders": ["Server", "nginx"] + }, + { + "scope": "https://gitlab.com:443", + "method": "PUT", + "path": "/api/v4/projects/gitlab-org%2Fgitlab-foss/merge_requests/27117", + "body": "{\"labels\":\"danger-bot,Plan,backend,backstage\"}", + "status": 201, + "reqheaders": {}, + "response": { + "id": 27253868, + "iid": 27117, + "project_id": 13083, + "title": "update merge request", + "description": "merge request. update labels", + "state": "merged", + "created_at": "2019-04-08T10:59:38.140Z", + "updated_at": "2019-05-02T14:34:54.068Z", + "labels": ["danger-bot", "Plan", "backend", "backstage"], + "work_in_progress": false, + "merge_when_pipeline_succeeds": false, + "merge_status": "can_be_merged", + "sha": "28531ab43666b5fdf37e0a70db3bcbf7d3f92183", + "merge_commit_sha": "58d4099c1469dba9ff850733ba29da11f6eeb158", + "discussion_locked": null, + "should_remove_source_branch": null, + "force_remove_source_branch": true, + "reference": "!27117", + "web_url": "https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/27117", + "squash": false, + "subscribed": false, + "changes_count": "1", + "latest_build_started_at": "2019-04-08T10:56:58.249Z", + "latest_build_finished_at": "2019-04-08T11:56:52.871Z", + "first_deployed_to_production_at": null, + "diff_refs": { + "base_sha": "50cd5d9b776848cf23f1fd1ec52789dbdf946185", + "head_sha": "28531ab43666b5fdf37e0a70db3bcbf7d3f92183", + "start_sha": "50cd5d9b776848cf23f1fd1ec52789dbdf946185" + }, + "merge_error": null, + "user": { + "can_merge": false + }, + "approvals_before_merge": 1 + }, + "rawHeaders": ["Server", "nginx"] + }, + { + "scope": "https://gitlab.com:443", + "method": "PUT", + "path": "/api/v4/projects/gitlab-org%2Fgitlab-foss/merge_requests/27117", + "body": "{\"labels\":\"danger-bot,Plan,backend,backstage,new-label\"}", + "status": 201, + "reqheaders": {}, + "response": { + "id": 27253868, + "iid": 27117, + "project_id": 13083, + "title": "update merge request", + "description": "merge request. update labels", + "state": "merged", + "created_at": "2019-04-08T10:59:38.140Z", + "updated_at": "2019-05-02T14:34:54.068Z", + "labels": ["danger-bot", "Plan", "backend", "backstage", "new-label"], + "work_in_progress": false, + "merge_when_pipeline_succeeds": false, + "merge_status": "can_be_merged", + "sha": "28531ab43666b5fdf37e0a70db3bcbf7d3f92183", + "merge_commit_sha": "58d4099c1469dba9ff850733ba29da11f6eeb158", + "discussion_locked": null, + "should_remove_source_branch": null, + "force_remove_source_branch": true, + "reference": "!27117", + "web_url": "https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/27117", + "squash": false, + "subscribed": false, + "changes_count": "1", + "latest_build_started_at": "2019-04-08T10:56:58.249Z", + "latest_build_finished_at": "2019-04-08T11:56:52.871Z", + "first_deployed_to_production_at": null, + "diff_refs": { + "base_sha": "50cd5d9b776848cf23f1fd1ec52789dbdf946185", + "head_sha": "28531ab43666b5fdf37e0a70db3bcbf7d3f92183", + "start_sha": "50cd5d9b776848cf23f1fd1ec52789dbdf946185" + }, + "merge_error": null, + "user": { + "can_merge": false + }, + "approvals_before_merge": 1 + }, + "rawHeaders": ["Server", "nginx"] + } +] From bd78aa44ae28bef9bced8d1473cf3dd3cf0c2d87 Mon Sep 17 00:00:00 2001 From: ivan katliarchuk Date: Sat, 8 Oct 2022 16:00:36 +0100 Subject: [PATCH 2/3] gitlab: slightly rename test --- source/platforms/gitlab/GitLabAPI.ts | 4 ++-- source/platforms/gitlab/_tests/_gitlab_api.test.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/platforms/gitlab/GitLabAPI.ts b/source/platforms/gitlab/GitLabAPI.ts index 7a3ca3f2f..08dbf3ac3 100644 --- a/source/platforms/gitlab/GitLabAPI.ts +++ b/source/platforms/gitlab/GitLabAPI.ts @@ -92,7 +92,7 @@ class GitLabAPI { getMergeRequestInfo = async (): Promise => { this.d(`getMergeRequestInfo for repo: ${this.repoSlug} pr: ${this.prId}`) - const mr = (await this.api.MergeRequests.show(this.repoSlug, Number(this.prId))) as GitLabMR + const mr = (await this.api.MergeRequests.show(this.repoSlug, this.prId)) as GitLabMR this.d("getMergeRequestInfo", mr) return mr } @@ -106,7 +106,7 @@ class GitLabAPI { getMergeRequestApprovals = async (): Promise => { this.d(`getMergeRequestApprovals for repo: ${this.repoSlug} pr: ${this.prId}`) const approvals = (await this.api.MergeRequests.approvals(this.repoSlug, { - mergerequestIid: Number(this.prId), + mergerequestIid: this.prId, })) as GitLabApproval this.d("getMergeRequestApprovals", approvals) return approvals diff --git a/source/platforms/gitlab/_tests/_gitlab_api.test.ts b/source/platforms/gitlab/_tests/_gitlab_api.test.ts index 0be8e173c..467b8415a 100644 --- a/source/platforms/gitlab/_tests/_gitlab_api.test.ts +++ b/source/platforms/gitlab/_tests/_gitlab_api.test.ts @@ -196,7 +196,7 @@ describe("GitLab API", () => { expect(JSON.stringify(result)).toContain(titleToUpdate) }) - describe("mergerequest (add|remove)labels", () => { + describe("updateMergeRequestInfo (add|remove)labels", () => { let nockDone: { nockDone: () => void } afterAll(async () => { From de76c65fb136a62242cebdbe8a4ec0035e0496cc Mon Sep 17 00:00:00 2001 From: ivan katliarchuk Date: Sat, 8 Oct 2022 16:06:06 +0100 Subject: [PATCH 3/3] gitlab: remove reference to fetch --- source/platforms/gitlab/GitLabAPI.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/platforms/gitlab/GitLabAPI.ts b/source/platforms/gitlab/GitLabAPI.ts index 08dbf3ac3..acf8c4bd2 100644 --- a/source/platforms/gitlab/GitLabAPI.ts +++ b/source/platforms/gitlab/GitLabAPI.ts @@ -1,5 +1,4 @@ import { RepoMetaData } from "../../dsl/BitBucketServerDSL" -import { api as fetch } from "../../api/fetch" import { GitLabDiscussionTextPosition, GitLabInlineNote, @@ -56,7 +55,6 @@ export function getGitLabAPICredentialsFromEnv(env: Env): GitLabAPICredentials { } class GitLabAPI { - fetch: typeof fetch private readonly api: InstanceType private readonly hostURL: string private readonly d = debug("GitLabAPI") @@ -64,7 +62,6 @@ class GitLabAPI { private readonly prId: number constructor(public readonly repoMetadata: RepoMetaData, public readonly repoCredentials: GitLabAPICredentials) { - this.fetch = fetch this.api = new Gitlab(repoCredentials) this.hostURL = repoCredentials.host this.repoSlug = repoMetadata.repoSlug