Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove previews #538

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ jobs:
strategy:
matrix:
node_version:
- 14
- 16
- 18
- 20
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node_version }}
Expand Down
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: "main",
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@
]
},
"engines": {
"node": ">= 14"
"node": ">= 18"
}
}
2 changes: 1 addition & 1 deletion scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function main() {
outdir: "pkg/dist-node",
bundle: true,
platform: "node",
target: "node14",
target: "node18",
format: "cjs",
...sharedOptions,
}),
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