From 7e82b27acfae7ad05bd0b0b5f110465c22cf9775 Mon Sep 17 00:00:00 2001 From: Laura Liberda Date: Thu, 11 Feb 2021 20:31:55 +0100 Subject: [PATCH] commit diff/patch getters --- src/types.ts | 2 ++ src/vendor/github/repomgr.ts | 3 ++- src/vendor/github/vendormgr.ts | 11 +++++++++++ src/vendor/gitlab/repomgr.ts | 2 ++ src/vendor/gitlab/vendormgr.ts | 11 +++++++++++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index 93352b0..e69a0a9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -111,7 +111,9 @@ export interface MergeRequest extends RepoElement { export interface Commit extends RepoElement { type: ENTITY_TYPE.COMMIT; patchURL: string; + patchContent: () => Promise; diffURL: string; + diffContent: () => Promise; } /** the account that did an action */ diff --git a/src/vendor/github/repomgr.ts b/src/vendor/github/repomgr.ts index 9519a04..73547c6 100644 --- a/src/vendor/github/repomgr.ts +++ b/src/vendor/github/repomgr.ts @@ -219,9 +219,10 @@ export default class GitHubRepoManager implements RepoManager { 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`, + patchContent: () => this.vendorMgr._http_get(`${this.repo.url}/commit/${c.oid}.patch`), diffURL: `${this.repo.url}/commit/${c.oid}.diff`, + diffContent: () => this.vendorMgr._http_get(`${this.repo.url}/commit/${c.oid}.diff`), })), isDraft: pullRequest.isDraft, url: `${this.repo.url}/pull/${pullRequest.number}`, diff --git a/src/vendor/github/vendormgr.ts b/src/vendor/github/vendormgr.ts index 0971a37..021778c 100644 --- a/src/vendor/github/vendormgr.ts +++ b/src/vendor/github/vendormgr.ts @@ -56,4 +56,15 @@ export default class GitHubVendorManager implements VendorManager .then((res) => JSON.parse(res.body)) .then((res) => res.data) as Promise; } + + /** used to provide diff/patch contents */ + public async _http_get(url: string | URL): Promise { + return got + .get(url, { + headers: { + Authorization: `Bearer ${this.config.token}`, + }, + }) + .then((res) => res.body); + } } diff --git a/src/vendor/gitlab/repomgr.ts b/src/vendor/gitlab/repomgr.ts index 8c027fe..a278ebf 100644 --- a/src/vendor/gitlab/repomgr.ts +++ b/src/vendor/gitlab/repomgr.ts @@ -224,7 +224,9 @@ export default class GitHubRepoManager implements RepoManager { repo: this.repo, url: `${this.repo.url}/-/commit/${c.id}`, diffURL: `${this.repo.url}/-/commit/${c.id}.diff`, + diffContent: () => this.vendorMgr._http_get(`${this.repo.url}/-/commit/${c.id}.diff`), patchURL: `${this.repo.url}/-/commit/${c.id}.patch`, + patchContent: () => this.vendorMgr._http_get(`${this.repo.url}/-/commit/${c.id}.patch`), })), url: `${this.repo.url}/-/merge_requests/${mergeRequest.iid}`, }; diff --git a/src/vendor/gitlab/vendormgr.ts b/src/vendor/gitlab/vendormgr.ts index 24f9937..de62996 100644 --- a/src/vendor/gitlab/vendormgr.ts +++ b/src/vendor/gitlab/vendormgr.ts @@ -70,4 +70,15 @@ export default class GitLabVendorManager implements VendorManager }, }).then((res) => JSON.parse(res.body) as T); } + + /** used to provide diff/patch contents */ + public async _http_get(url: string | URL): Promise { + return got + .get(url, { + headers: { + Authorization: `Bearer ${this.config.token}`, + }, + }) + .then((res) => res.body); + } }