From 9a68c139a5089cf57f9643c07f7c84e0ac419e05 Mon Sep 17 00:00:00 2001
From: Sergio Zharinov <zharinov@users.noreply.github.com>
Date: Tue, 7 Apr 2020 18:12:59 +0400
Subject: [PATCH] feat(internal): Add support for missing HTTP methods (#5899)

---
 .../http/__snapshots__/index.spec.ts.snap     | 36 +++++++++++++++++++
 lib/util/http/index.spec.ts                   | 36 +++++++++++++++++++
 lib/util/http/index.ts                        | 30 +++++++++++++++-
 3 files changed, 101 insertions(+), 1 deletion(-)

diff --git a/lib/util/http/__snapshots__/index.spec.ts.snap b/lib/util/http/__snapshots__/index.spec.ts.snap
index 8d5d6afa80..b8031b689a 100644
--- a/lib/util/http/__snapshots__/index.spec.ts.snap
+++ b/lib/util/http/__snapshots__/index.spec.ts.snap
@@ -1,5 +1,14 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
+exports[`util/http/index deleteJson 1`] = `
+Object {
+  "body": Object {},
+  "headers": Object {
+    "content-type": "application/json",
+  },
+}
+`;
+
 exports[`util/http/index get 1`] = `
 Object {
   "body": "",
@@ -16,6 +25,24 @@ Object {
 }
 `;
 
+exports[`util/http/index headJson 1`] = `
+Object {
+  "body": Object {},
+  "headers": Object {
+    "content-type": "application/json",
+  },
+}
+`;
+
+exports[`util/http/index patchJson 1`] = `
+Object {
+  "body": Object {},
+  "headers": Object {
+    "content-type": "application/json",
+  },
+}
+`;
+
 exports[`util/http/index postJson 1`] = `
 Object {
   "body": Object {},
@@ -24,3 +51,12 @@ Object {
   },
 }
 `;
+
+exports[`util/http/index putJson 1`] = `
+Object {
+  "body": Object {},
+  "headers": Object {
+    "content-type": "application/json",
+  },
+}
+`;
diff --git a/lib/util/http/index.spec.ts b/lib/util/http/index.spec.ts
index d58b3c527d..27ea216f34 100644
--- a/lib/util/http/index.spec.ts
+++ b/lib/util/http/index.spec.ts
@@ -33,6 +33,42 @@ describe(getName(__filename), () => {
     ).toMatchSnapshot();
     expect(nock.isDone()).toBe(true);
   });
+  it('putJson', async () => {
+    nock(baseUrl)
+      .put('/')
+      .reply(200, {});
+    expect(
+      await http.putJson('http://renovate.com', { body: {}, baseUrl })
+    ).toMatchSnapshot();
+    expect(nock.isDone()).toBe(true);
+  });
+  it('patchJson', async () => {
+    nock(baseUrl)
+      .patch('/')
+      .reply(200, {});
+    expect(
+      await http.patchJson('http://renovate.com', { body: {}, baseUrl })
+    ).toMatchSnapshot();
+    expect(nock.isDone()).toBe(true);
+  });
+  it('deleteJson', async () => {
+    nock(baseUrl)
+      .delete('/')
+      .reply(200, {});
+    expect(
+      await http.deleteJson('http://renovate.com', { body: {}, baseUrl })
+    ).toMatchSnapshot();
+    expect(nock.isDone()).toBe(true);
+  });
+  it('headJson', async () => {
+    nock(baseUrl)
+      .head('/')
+      .reply(200, {});
+    expect(
+      await http.headJson('http://renovate.com', { body: {}, baseUrl })
+    ).toMatchSnapshot();
+    expect(nock.isDone()).toBe(true);
+  });
 
   it('stream', async () => {
     nock(baseUrl)
diff --git a/lib/util/http/index.ts b/lib/util/http/index.ts
index c4a6201a08..0cd6819b48 100644
--- a/lib/util/http/index.ts
+++ b/lib/util/http/index.ts
@@ -20,7 +20,7 @@ export interface HttpPostOptions extends HttpOptions {
 
 interface InternalHttpOptions extends HttpOptions {
   json?: boolean;
-  method?: 'get' | 'post';
+  method?: 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head';
 }
 
 export interface HttpResponse<T = string> {
@@ -97,6 +97,34 @@ export class Http {
     return this.requestJson<T>(url, { ...options, method: 'post' });
   }
 
+  async putJson<T = unknown>(
+    url: string,
+    options: HttpPostOptions
+  ): Promise<HttpResponse<T>> {
+    return this.requestJson<T>(url, { ...options, method: 'put' });
+  }
+
+  async patchJson<T = unknown>(
+    url: string,
+    options: HttpPostOptions
+  ): Promise<HttpResponse<T>> {
+    return this.requestJson<T>(url, { ...options, method: 'patch' });
+  }
+
+  async deleteJson<T = unknown>(
+    url: string,
+    options: HttpPostOptions
+  ): Promise<HttpResponse<T>> {
+    return this.requestJson<T>(url, { ...options, method: 'delete' });
+  }
+
+  async headJson<T = unknown>(
+    url: string,
+    options: HttpPostOptions
+  ): Promise<HttpResponse<T>> {
+    return this.requestJson<T>(url, { ...options, method: 'head' });
+  }
+
   stream(url: string, options?: HttpOptions): NodeJS.ReadableStream {
     const combinedOptions: any = {
       method: 'get',
-- 
GitLab