@octokit/plugin-enterprise-compatibility
Advanced tools
Comparing version 1.2.7 to 1.2.8
@@ -7,3 +7,3 @@ 'use strict'; | ||
const VERSION = "1.2.7"; | ||
const VERSION = "1.2.8"; | ||
@@ -25,25 +25,2 @@ function isIssueLabelsUpdateOrReplace({ | ||
const REGEX_IS_GET_REFERENCE_PATH = /\/repos\/[^/]+\/[^/]+\/git\/ref\//; | ||
const REGEX_IS_LIST_REFERENCES_PATH = /\/repos\/[^/]+\/[^/]+\/git\/matching-refs\//; | ||
function isGetReference({ | ||
method, | ||
url | ||
}) { | ||
if (!["GET", "HEAD"].includes(method)) { | ||
return false; | ||
} | ||
return REGEX_IS_GET_REFERENCE_PATH.test(url); | ||
} | ||
function isListReferences({ | ||
method, | ||
url | ||
}) { | ||
if (!["GET", "HEAD"].includes(method)) { | ||
return false; | ||
} | ||
return REGEX_IS_LIST_REFERENCES_PATH.test(url); | ||
} | ||
function enterpriseCompatibility(octokit) { | ||
@@ -63,38 +40,2 @@ octokit.hook.wrap("request", async (request, options) => { | ||
return request(options); | ||
} | ||
const isGetReferenceRequest = isGetReference(options); | ||
const isListReferencesRequest = isListReferences(options); | ||
if (isGetReferenceRequest || isListReferencesRequest) { | ||
options.url = options.url.replace(/\/repos\/([^/]+)\/([^/]+)\/git\/(ref|matching-refs)\/(.*)$/, "/repos/$1/$2/git/refs/$4"); | ||
return request(options).then(response => { | ||
if (isGetReferenceRequest) { | ||
if (Array.isArray(response.data)) { | ||
throw new requestError.RequestError(`More than one reference found at "${options.url}"`, 404, { | ||
request: options | ||
}); | ||
} // ✅ received single reference | ||
return response; | ||
} // make sure that | ||
if (!Array.isArray(response.data)) { | ||
response.data = [response.data]; | ||
} | ||
return response; | ||
}).catch(error => { | ||
if (isListReferencesRequest && error.status === 404) { | ||
return { | ||
status: 200, | ||
headers: error.headers, | ||
data: [] | ||
}; | ||
} | ||
throw error; | ||
}); | ||
} // TODO: implement fix for #62 here | ||
@@ -116,3 +57,3 @@ // https://github.com/octokit/plugin-enterprise-compatibility.js/issues/60 | ||
const deprecatedUrl = options.url.replace(/\/orgs\/[^/]+\/teams\/[^/]+/, "/teams/:team_id"); | ||
const deprecatedUrl = options.url.replace(/\/orgs\/[^/]+\/teams\/[^/]+/, "/teams/{team_id}"); | ||
throw new requestError.RequestError(`"${options.method} ${options.url}" is not supported in your GitHub Enterprise Server version. Please replace with octokit.request("${options.method} ${deprecatedUrl}", { team_id })`, 404, { | ||
@@ -119,0 +60,0 @@ request: options |
import { RequestError } from "@octokit/request-error"; | ||
import { VERSION } from "./version"; | ||
import { isIssueLabelsUpdateOrReplace } from "./is-issue-labels-update-or-replace"; | ||
import { isGetReference, isListReferences, } from "./is-get-reference-or-list-references"; | ||
export function enterpriseCompatibility(octokit) { | ||
@@ -18,34 +17,2 @@ octokit.hook.wrap("request", async (request, options) => { | ||
} | ||
const isGetReferenceRequest = isGetReference(options); | ||
const isListReferencesRequest = isListReferences(options); | ||
if (isGetReferenceRequest || isListReferencesRequest) { | ||
options.url = options.url.replace(/\/repos\/([^/]+)\/([^/]+)\/git\/(ref|matching-refs)\/(.*)$/, "/repos/$1/$2/git/refs/$4"); | ||
return request(options) | ||
.then((response) => { | ||
if (isGetReferenceRequest) { | ||
if (Array.isArray(response.data)) { | ||
throw new RequestError(`More than one reference found at "${options.url}"`, 404, { | ||
request: options, | ||
}); | ||
} | ||
// ✅ received single reference | ||
return response; | ||
} | ||
// make sure that | ||
if (!Array.isArray(response.data)) { | ||
response.data = [response.data]; | ||
} | ||
return response; | ||
}) | ||
.catch((error) => { | ||
if (isListReferencesRequest && error.status === 404) { | ||
return { | ||
status: 200, | ||
headers: error.headers, | ||
data: [], | ||
}; | ||
} | ||
throw error; | ||
}); | ||
} | ||
// TODO: implement fix for #62 here | ||
@@ -64,3 +31,3 @@ // https://github.com/octokit/plugin-enterprise-compatibility.js/issues/60 | ||
} | ||
const deprecatedUrl = options.url.replace(/\/orgs\/[^/]+\/teams\/[^/]+/, "/teams/:team_id"); | ||
const deprecatedUrl = options.url.replace(/\/orgs\/[^/]+\/teams\/[^/]+/, "/teams/{team_id}"); | ||
throw new RequestError(`"${options.method} ${options.url}" is not supported in your GitHub Enterprise Server version. Please replace with octokit.request("${options.method} ${deprecatedUrl}", { team_id })`, 404, { | ||
@@ -67,0 +34,0 @@ request: options, |
@@ -1,1 +0,1 @@ | ||
export const VERSION = "1.2.7"; | ||
export const VERSION = "1.2.8"; |
@@ -1,1 +0,1 @@ | ||
export declare const VERSION = "1.2.7"; | ||
export declare const VERSION = "1.2.8"; |
import { RequestError } from '@octokit/request-error'; | ||
const VERSION = "1.2.7"; | ||
const VERSION = "1.2.8"; | ||
@@ -15,17 +15,2 @@ function isIssueLabelsUpdateOrReplace({ method, url }) { | ||
const REGEX_IS_GET_REFERENCE_PATH = /\/repos\/[^/]+\/[^/]+\/git\/ref\//; | ||
const REGEX_IS_LIST_REFERENCES_PATH = /\/repos\/[^/]+\/[^/]+\/git\/matching-refs\//; | ||
function isGetReference({ method, url }) { | ||
if (!["GET", "HEAD"].includes(method)) { | ||
return false; | ||
} | ||
return REGEX_IS_GET_REFERENCE_PATH.test(url); | ||
} | ||
function isListReferences({ method, url }) { | ||
if (!["GET", "HEAD"].includes(method)) { | ||
return false; | ||
} | ||
return REGEX_IS_LIST_REFERENCES_PATH.test(url); | ||
} | ||
function enterpriseCompatibility(octokit) { | ||
@@ -44,34 +29,2 @@ octokit.hook.wrap("request", async (request, options) => { | ||
} | ||
const isGetReferenceRequest = isGetReference(options); | ||
const isListReferencesRequest = isListReferences(options); | ||
if (isGetReferenceRequest || isListReferencesRequest) { | ||
options.url = options.url.replace(/\/repos\/([^/]+)\/([^/]+)\/git\/(ref|matching-refs)\/(.*)$/, "/repos/$1/$2/git/refs/$4"); | ||
return request(options) | ||
.then((response) => { | ||
if (isGetReferenceRequest) { | ||
if (Array.isArray(response.data)) { | ||
throw new RequestError(`More than one reference found at "${options.url}"`, 404, { | ||
request: options, | ||
}); | ||
} | ||
// ✅ received single reference | ||
return response; | ||
} | ||
// make sure that | ||
if (!Array.isArray(response.data)) { | ||
response.data = [response.data]; | ||
} | ||
return response; | ||
}) | ||
.catch((error) => { | ||
if (isListReferencesRequest && error.status === 404) { | ||
return { | ||
status: 200, | ||
headers: error.headers, | ||
data: [], | ||
}; | ||
} | ||
throw error; | ||
}); | ||
} | ||
// TODO: implement fix for #62 here | ||
@@ -90,3 +43,3 @@ // https://github.com/octokit/plugin-enterprise-compatibility.js/issues/60 | ||
} | ||
const deprecatedUrl = options.url.replace(/\/orgs\/[^/]+\/teams\/[^/]+/, "/teams/:team_id"); | ||
const deprecatedUrl = options.url.replace(/\/orgs\/[^/]+\/teams\/[^/]+/, "/teams/{team_id}"); | ||
throw new RequestError(`"${options.method} ${options.url}" is not supported in your GitHub Enterprise Server version. Please replace with octokit.request("${options.method} ${deprecatedUrl}", { team_id })`, 404, { | ||
@@ -93,0 +46,0 @@ request: options, |
{ | ||
"name": "@octokit/plugin-enterprise-compatibility", | ||
"description": "Octokit plugin for improving GHE compatibility", | ||
"version": "1.2.7", | ||
"version": "1.2.8", | ||
"license": "MIT", | ||
@@ -22,4 +22,4 @@ "files": [ | ||
"dependencies": { | ||
"@octokit/request-error": "^2.0.0", | ||
"@octokit/types": "^6.0.0" | ||
"@octokit/request-error": "^2.0.4", | ||
"@octokit/types": "^6.0.3" | ||
}, | ||
@@ -26,0 +26,0 @@ "devDependencies": { |
@@ -55,3 +55,3 @@ # plugin-enterprise-compatibility.js | ||
octokit.request("POST /repos/:owner/:repo/issues/:issue_number/labels", { | ||
octokit.request("POST /repos/{owner}/{repo}/issues/{issue_number}/labels", { | ||
owner, | ||
@@ -58,0 +58,0 @@ repo, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19366
13
157
Updated@octokit/types@^6.0.3