Skip to content

Commit 4c5343b

Browse files
authored
fix: remove workaround for "replace all labels". All GHES versions now support sending labels with a labels namespace key in the request body (#235)
1 parent fb3be75 commit 4c5343b

File tree

3 files changed

+0
-217
lines changed

3 files changed

+0
-217
lines changed

src/index.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,6 @@ import { isIssueLabelsUpdateOrReplace } from "./is-issue-labels-update-or-replac
88

99
export function enterpriseCompatibility(octokit: Octokit) {
1010
octokit.hook.wrap("request", async (request, options) => {
11-
// see https://github.com/octokit/rest.js/blob/15.x/lib/routes.json#L3046-L3068
12-
if (isIssueLabelsUpdateOrReplace(options)) {
13-
options.data = options.labels;
14-
delete options.labels;
15-
16-
// for @octokit/rest v16.x, remove validation of labels option
17-
/* istanbul ignore if */
18-
if (options.request.validate) {
19-
delete options.request.validate.labels;
20-
}
21-
return request(options);
22-
}
23-
2411
// TODO: implement fix for #62 here
2512

2613
// https://github.com/octokit/plugin-enterprise-compatibility.js/issues/60

test/octokit-core.test.ts

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -4,112 +4,6 @@ import { Octokit } from "@octokit/core";
44
import { enterpriseCompatibility } from "../src";
55
const OctokitWithPlugin = Octokit.plugin(enterpriseCompatibility);
66

7-
describe("{POST|PUT} /repos/{owner}/{repo}/issues/{issue_number}/labels", () => {
8-
it("POST sends labels in request body", () => {
9-
const mock = fetchMock
10-
.sandbox()
11-
.post(
12-
"https://original.test/repos/octokit/rest.js/issues/1/labels",
13-
{},
14-
{
15-
// @ts-ignore definitions missing, see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/40133
16-
body: {
17-
labels: ["foo", "bar"],
18-
},
19-
}
20-
)
21-
.post(
22-
"https://patched.test/repos/octokit/rest.js/issues/1/labels",
23-
{},
24-
{
25-
// @ts-ignore definitions missing, see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/40133
26-
body: ["foo", "bar"],
27-
}
28-
);
29-
30-
const octokitOriginal = new Octokit({
31-
baseUrl: "https://original.test",
32-
request: {
33-
fetch: mock,
34-
},
35-
});
36-
const octokitPatched = new OctokitWithPlugin({
37-
baseUrl: "https://patched.test",
38-
request: {
39-
fetch: mock,
40-
},
41-
});
42-
43-
const options = {
44-
method: "POST",
45-
url: "/repos/{owner}/{repo}/issues/{issue_number}/labels",
46-
owner: "octokit",
47-
repo: "rest.js",
48-
issue_number: 1,
49-
labels: ["foo", "bar"],
50-
};
51-
52-
return Promise.all([
53-
// @ts-ignore no idea why TypeScript is complaining about "POST" not being compatible with RequestMethod, which is an enum including "POST"
54-
octokitOriginal.request(options),
55-
// @ts-ignore
56-
octokitPatched.request(options),
57-
]);
58-
});
59-
60-
it("octokit.issues.setLabels() sends labels in request body", () => {
61-
const mock = fetchMock
62-
.sandbox()
63-
.put(
64-
"https://original.test/repos/octokit/rest.js/issues/1/labels",
65-
{},
66-
{
67-
// @ts-ignore definitions missing, see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/40133
68-
body: {
69-
labels: ["foo", "bar"],
70-
},
71-
}
72-
)
73-
.put(
74-
"https://patched.test/repos/octokit/rest.js/issues/1/labels",
75-
{},
76-
{
77-
// @ts-ignore definitions missing, see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/40133
78-
body: ["foo", "bar"],
79-
}
80-
);
81-
82-
const octokitOriginal = new Octokit({
83-
baseUrl: "https://original.test",
84-
request: {
85-
fetch: mock,
86-
},
87-
});
88-
const octokitPatched = new OctokitWithPlugin({
89-
baseUrl: "https://patched.test",
90-
request: {
91-
fetch: mock,
92-
},
93-
});
94-
95-
const options = {
96-
method: "PUT",
97-
url: "/repos/{owner}/{repo}/issues/{issue_number}/labels",
98-
owner: "octokit",
99-
repo: "rest.js",
100-
issue_number: 1,
101-
labels: ["foo", "bar"],
102-
};
103-
104-
return Promise.all([
105-
// @ts-ignore no idea why TypeScript is complaining about "POST" not being compatible with RequestMethod, which is an enum including "POST"
106-
octokitOriginal.request(options),
107-
// @ts-ignore
108-
octokitPatched.request(options),
109-
]);
110-
});
111-
});
112-
1137
describe("GET /repos/{owner}/{repo}/issues/{issue_number}/labels", () => {
1148
it("has no effect on GET methods", async () => {
1159
const mock = fetchMock

test/octokit-rest.test.ts

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -13,101 +13,3 @@ describe("side effects", () => {
1313
expect(octokit.issues.get.endpoint).toBeTruthy();
1414
});
1515
});
16-
17-
describe("octokit.issues.addLabels() & octokit.issues.setLabels()", () => {
18-
it("octokit.issues.addLabels() sends labels in request body", () => {
19-
const mock = fetchMock
20-
.sandbox()
21-
.post(
22-
"https://original.test/repos/octokit/rest.js/issues/1/labels",
23-
{},
24-
{
25-
// @ts-ignore definitions missing, see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/40133
26-
body: {
27-
labels: ["foo", "bar"],
28-
},
29-
}
30-
)
31-
.post(
32-
"https://patched.test/repos/octokit/rest.js/issues/1/labels",
33-
{},
34-
{
35-
// @ts-ignore definitions missing, see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/40133
36-
body: ["foo", "bar"],
37-
}
38-
);
39-
40-
const octokitOriginal = new Octokit({
41-
baseUrl: "https://original.test",
42-
request: {
43-
fetch: mock,
44-
},
45-
});
46-
const octokitPatched = new MyOctokit({
47-
baseUrl: "https://patched.test",
48-
request: {
49-
fetch: mock,
50-
},
51-
});
52-
53-
const options = {
54-
owner: "octokit",
55-
repo: "rest.js",
56-
issue_number: 1,
57-
labels: ["foo", "bar"],
58-
};
59-
60-
return Promise.all([
61-
octokitOriginal.issues.addLabels(options),
62-
octokitPatched.issues.addLabels(options),
63-
]);
64-
});
65-
66-
it("octokit.issues.setLabels() sends labels in request body", () => {
67-
const mock = fetchMock
68-
.sandbox()
69-
.put(
70-
"https://original.test/repos/octokit/rest.js/issues/1/labels",
71-
{},
72-
{
73-
// @ts-ignore definitions missing, see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/40133
74-
body: {
75-
labels: ["foo", "bar"],
76-
},
77-
}
78-
)
79-
.put(
80-
"https://patched.test/repos/octokit/rest.js/issues/1/labels",
81-
{},
82-
{
83-
// @ts-ignore definitions missing, see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/40133
84-
body: ["foo", "bar"],
85-
}
86-
);
87-
88-
const octokitOriginal = new Octokit({
89-
baseUrl: "https://original.test",
90-
request: {
91-
fetch: mock,
92-
},
93-
});
94-
const octokitPatched = new MyOctokit({
95-
baseUrl: "https://patched.test",
96-
request: {
97-
fetch: mock,
98-
},
99-
});
100-
101-
const options = {
102-
owner: "octokit",
103-
repo: "rest.js",
104-
issue_number: 1,
105-
labels: ["foo", "bar"],
106-
};
107-
108-
return Promise.all([
109-
octokitOriginal.issues.setLabels(options),
110-
octokitPatched.issues.setLabels(options),
111-
]);
112-
});
113-
});

0 commit comments

Comments
 (0)