Skip to content

Commit

Permalink
feat: remove previews
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy1339 committed Jan 3, 2023
1 parent ba27faf commit f31f308
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 121 deletions.
35 changes: 0 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,41 +145,6 @@ const octokit = new Octokit({
});
```

</td></tr>
<tr>
<th>
<code>options.previews</code>
</th>
<td>
<code>Array of Strings</code>
</td>
<td>

Some REST API endpoints require preview headers to be set, or enable
additional features. Preview headers can be set on a per-request basis, e.g.

```js
octokit.request("POST /repos/{owner}/{repo}/pulls", {
mediaType: {
previews: ["shadow-cat"],
},
owner,
repo,
title: "My pull request",
base: "master",
head: "my-feature",
draft: true,
});
```

You can also set previews globally, by setting the `options.previews` option on the constructor. Example:

```js
const octokit = new Octokit({
previews: ["shadow-cat"],
});
```

</td></tr>
<tr>
<th>
Expand Down
5 changes: 0 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export class Octokit {
hook: hook.bind(null, "request"),
}),
mediaType: {
previews: [],
format: "",
},
};
Expand All @@ -97,10 +96,6 @@ export class Octokit {
requestDefaults.baseUrl = options.baseUrl;
}

if (options.previews) {
requestDefaults.mediaType.previews = options.previews;
}

if (options.timeZone) {
requestDefaults.headers["time-zone"] = options.timeZone;
}
Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export interface OctokitOptions {
authStrategy?: any;
auth?: any;
userAgent?: string;
previews?: string[];
baseUrl?: string;
log?: {
debug: (message: string) => unknown;
Expand Down
7 changes: 1 addition & 6 deletions test/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ describe("Authentication", () => {
{ id: 123 },
{
headers: {
accept: "application/vnd.github.machine-man-preview+json",
"user-agent": userAgent,
authorization: `bearer ${BEARER}`,
},
Expand All @@ -253,11 +252,7 @@ describe("Authentication", () => {
await octokit.request("GET /repos/octocat/hello-world");
await octokit.request("GET /repos/octocat/hello-world");

await octokit.request("GET /app", {
mediaType: {
previews: ["machine-man"],
},
});
await octokit.request("GET /app");

expect(mock.done()).toBe(true);
});
Expand Down
26 changes: 0 additions & 26 deletions test/constructor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,6 @@ import { Octokit } from "../src";
import fetchMock from "fetch-mock";

describe("Smoke test", () => {
it("previews option", () => {
const mock = fetchMock.sandbox().getOnce(
"https://api.github.com/",
{ ok: true },
{
headers: {
accept:
"application/vnd.github.jean-grey-preview+json,application/vnd.github.symmetra-preview+json",
},
}
);

const octokit = new Octokit({
previews: [
// test with & without -preview suffix
"jean-grey-preview",
"symmetra",
],
request: {
fetch: mock,
},
});

return octokit.request("/");
});

it("timeZone option", () => {
const mock = fetchMock.sandbox().getOnce(
"https://api.github.com/",
Expand Down
5 changes: 0 additions & 5 deletions test/hook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ describe("octokit.hook", () => {
"x-foo": "bar",
},
mediaType: {
previews: ["octicon"],
format: "rad",
},
bar: "daz",
Expand All @@ -77,7 +76,6 @@ describe("octokit.hook", () => {
"x-foo": "bar",
},
mediaType: {
previews: ["octicon"],
format: "rad",
},
});
Expand All @@ -104,7 +102,6 @@ describe("octokit.hook", () => {
"user-agent": userAgent,
},
mediaType: {
previews: [],
format: "",
},
request: {
Expand Down Expand Up @@ -145,7 +142,6 @@ describe("octokit.hook", () => {
"user-agent": userAgent,
},
mediaType: {
previews: [],
format: "",
},
request: {
Expand Down Expand Up @@ -178,7 +174,6 @@ describe("octokit.hook", () => {
"user-agent": userAgent,
},
mediaType: {
previews: [],
format: "",
},
request: {
Expand Down
43 changes: 0 additions & 43 deletions test/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,49 +94,6 @@ describe("octokit.request()", () => {
return octokit.request("GET /");
});

it("previews", async () => {
const mock = fetchMock
.sandbox()
.getOnce(
"https://api.github.com/",
{},
{
headers: {
accept:
"application/vnd.github.foo-preview+json,application/vnd.github.bar-preview+json",
"user-agent": userAgent,
},
}
)
.getOnce(
"https://api.github.com/",
{},
{
headers: {
accept:
"application/vnd.github.foo-preview.raw,application/vnd.github.bar-preview.raw,application/vnd.github.baz-preview.raw",
"user-agent": userAgent,
},
overwriteRoutes: false,
}
);

const octokit = new Octokit({
previews: ["foo", "bar-preview"],
request: {
fetch: mock,
},
});

await octokit.request("/");
await octokit.request("/", {
mediaType: {
previews: ["bar", "baz-preview"],
format: "raw",
},
});
});

it('octokit.request.endpoint("GET /")', () => {
const octokit = new Octokit();
const requestOptions = octokit.request.endpoint("GET /");
Expand Down

0 comments on commit f31f308

Please sign in to comment.