commit diff/patch getters

This commit is contained in:
Laura Liberda 2021-02-11 20:31:55 +01:00
parent f6f71b64d2
commit 7e82b27acf
5 changed files with 28 additions and 1 deletions

View file

@ -111,7 +111,9 @@ export interface MergeRequest extends RepoElement {
export interface Commit extends RepoElement {
type: ENTITY_TYPE.COMMIT;
patchURL: string;
patchContent: () => Promise<string>;
diffURL: string;
diffContent: () => Promise<string>;
}
/** the account that did an action */

View file

@ -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}`,

View file

@ -56,4 +56,15 @@ export default class GitHubVendorManager implements VendorManager<GitHubConfig>
.then((res) => JSON.parse(res.body))
.then((res) => res.data) as Promise<T>;
}
/** used to provide diff/patch contents */
public async _http_get(url: string | URL): Promise<string> {
return got
.get(url, {
headers: {
Authorization: `Bearer ${this.config.token}`,
},
})
.then((res) => res.body);
}
}

View file

@ -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}`,
};

View file

@ -70,4 +70,15 @@ export default class GitLabVendorManager implements VendorManager<GitLabConfig>
},
}).then((res) => JSON.parse(res.body) as T);
}
/** used to provide diff/patch contents */
public async _http_get(url: string | URL): Promise<string> {
return got
.get(url, {
headers: {
Authorization: `Bearer ${this.config.token}`,
},
})
.then((res) => res.body);
}
}