Skip to content

Commit

Permalink
docs: context.github is now context.octokit
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Nov 20, 2020
1 parent e67b785 commit cea4318
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = ({ app }) => {
const issueComment = context.issue({
body: "Thanks for opening this issue!",
});
return context.github.issues.createComment(issueComment);
return context.octokit.issues.createComment(issueComment);
});
};
```
Expand Down
2 changes: 1 addition & 1 deletion README.pt-br.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = ({ app }) => {
const issueComment = context.issue({
body: "Obrigado por abrir esta issue!",
});
return context.github.issues.createComment(issueComment);
return context.octokit.issues.createComment(issueComment);
});
};
```
Expand Down
4 changes: 2 additions & 2 deletions docs/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = ({ app }) => {
// Type `/label foo, bar` in a comment box for an Issue or Pull Request
commands(app, "label", (context, command) => {
const labels = command.arguments.split(/, */);
return context.github.issues.addLabels(context.issue({ labels }));
return context.octokit.issues.addLabels(context.issue({ labels }));
});
};
```
Expand All @@ -41,7 +41,7 @@ module.exports = ({ app }) => {

app.on("issues.closed", async (context) => {
const edits = await metadata(context).get("edits");
context.github.issues.createComment(
context.octokit.issues.createComment(
context.issue({
body: `There were ${edits} edits to issues in this thread.`,
})
Expand Down
14 changes: 7 additions & 7 deletions docs/github-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Your app has access to an authenticated GitHub client that can be used to make A

## REST API

`context.github` is an instance of the [`@octokit/rest` Node.js module](https://github.com/octokit/rest.js), which wraps the [GitHub REST API](https://developer.github.com/v3/) and allows you to do almost anything programmatically that you can do through a web browser.
`context.octokit` is an instance of the [`@octokit/rest` Node.js module](https://github.com/octokit/rest.js), which wraps the [GitHub REST API](https://developer.github.com/v3/) and allows you to do almost anything programmatically that you can do through a web browser.

Here is an example of an autoresponder app that comments on opened issues:

Expand All @@ -23,7 +23,7 @@ module.exports = ({ app }) => {
const params = context.issue({ body: "Hello World!" });

// Post a comment on the issue
return context.github.issues.createComment(params);
return context.octokit.issues.createComment(params);
});
};
```
Expand All @@ -32,7 +32,7 @@ See the [full API docs](https://octokit.github.io/rest.js/) to see all the ways

## GraphQL API

Use `context.github.graphql` to make requests to the [GitHub GraphQL API](https://developer.github.com/v4/).
Use `context.octokit.graphql` to make requests to the [GitHub GraphQL API](https://developer.github.com/v4/).

Here is an example of the same autoresponder app from above that comments on opened issues, but this time with GraphQL:

Expand All @@ -49,7 +49,7 @@ const addComment = `
module.exports = ({ app }) => {
app.on("issues.opened", async (context) => {
// Post a comment on the issue
context.github.graphql(addComment, {
context.octokit.graphql(addComment, {
id: context.payload.issue.node_id,
body: "Hello World",
});
Expand All @@ -71,7 +71,7 @@ const pinIssue = `

module.exports = ({ app }) => {
app.on("issues.opened", async (context) => {
context.github.graphql(pinIssue, {
context.octokit.graphql(pinIssue, {
id: context.payload.issue.node_id,
headers: {
accept: "application/vnd.github.elektra-preview+json",
Expand All @@ -85,13 +85,13 @@ Check out the [GitHub GraphQL API docs](https://developer.github.com/v4/) to lea

## Unauthenticated Events

When [receiving webhook events](./webhooks.md), `context.github` is _usually_ an authenticated client, but there are a few events that are exceptions:
When [receiving webhook events](./webhooks.md), `context.octokit` is _usually_ an authenticated client, but there are a few events that are exceptions:

- [`installation.deleted`](https://developer.github.com/v3/activity/events/types/#installationevent) - The installation was _just_ deleted, so we can't authenticate as the installation.

- [`marketplace_purchase`](https://developer.github.com/v3/activity/events/types/#marketplacepurchaseevent) - The purchase happens before the app is installed on an account.

For these events, `context.github` will be [authenticated as the GitHub App](https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-a-github-app) instead of as a specific installation.
For these events, `context.octokit` will be [authenticated as the GitHub App](https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-a-github-app) instead of as a specific installation.

## GitHub Enterprise

Expand Down
4 changes: 2 additions & 2 deletions docs/hello-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = ({ app }) => {
};
```

The `context` passed to the event handler includes everything about the event that was triggered, as well as some helpful properties for doing something useful in response to the event. `context.github` is an authenticated GitHub client that can be used to [make API calls](./github-api.md), and allows you to do almost anything programmatically that you can do through a web browser on GitHub.
The `context` passed to the event handler includes everything about the event that was triggered, as well as some helpful properties for doing something useful in response to the event. `context.octokit` is an authenticated GitHub client that can be used to [make API calls](./github-api.md), and allows you to do almost anything programmatically that you can do through a web browser on GitHub.

Here is an example of an autoresponder app that comments on opened issues:

Expand All @@ -38,7 +38,7 @@ module.exports = ({ app }) => {
const params = context.issue({ body: "Hello World!" });

// Post a comment on the issue
return context.github.issues.createComment(params);
return context.octokit.issues.createComment(params);
});
};
```
Expand Down
14 changes: 7 additions & 7 deletions docs/pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Many GitHub API endpoints are paginated. The `github.paginate` method can be use
```js
module.exports = ({ app }) => {
app.on("issues.opened", (context) => {
context.github.paginate(
context.github.issues.list,
context.octokit.paginate(
context.octokit.issues.list,
context.repo(),
(res) => {
res.data.issues.forEach((issue) => {
Expand All @@ -29,8 +29,8 @@ The return value of the `github.paginate` callback will be used to accumulate re
```js
module.exports = ({ app }) => {
app.on("issues.opened", async (context) => {
const allIssues = await context.github.paginate(
context.github.issues.list,
const allIssues = await context.octokit.paginate(
context.octokit.issues.list,
context.repo(),
(res) => res.data
);
Expand All @@ -46,8 +46,8 @@ Sometimes it is desirable to stop fetching pages after a certain condition has b
```js
module.exports = ({ app }) => {
app.on("issues.opened", (context) => {
context.github.paginate(
context.github.issues.list,
context.octokit.paginate(
context.octokit.issues.list,
context.repo(),
(res, done) => {
for (const issue of res.data) {
Expand All @@ -71,7 +71,7 @@ If your runtime environment supports async iterators (such as Node 10+), you can
module.exports = ({ app }) => {
app.on("issues.opened", async (context) => {
for await (const response of octokit.paginate.iterator(
context.github.issues.list,
context.octokit.issues.list,
context.repo()
)) {
for (const issue of res.data) {
Expand Down
8 changes: 4 additions & 4 deletions docs/persistence.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module.exports = ({ app }) => {
});

// Post a comment on the issue
return context.github.issues.createComment(params);
return context.octokit.issues.createComment(params);
});
};
```
Expand Down Expand Up @@ -121,7 +121,7 @@ module.exports = ({ app }) => {
});

// Post a comment on the issue
return context.github.issues.createComment(params);
return context.octokit.issues.createComment(params);
});
};
```
Expand Down Expand Up @@ -162,7 +162,7 @@ module.exports = ({ app }) => {
});

// Post a comment on the issue
return context.github.issues.createComment(params);
return context.octokit.issues.createComment(params);
});
};
```
Expand Down Expand Up @@ -210,7 +210,7 @@ module.exports = ({ app }) => {
});

// Post a comment on the issue
return context.github.issues.createComment(params);
return context.octokit.issues.createComment(params);
});
};
```
2 changes: 1 addition & 1 deletion src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { State } from "./types";
/**
* Authenticate and get a GitHub client that can be used to make API calls.
*
* You'll probably want to use `context.github` instead.
* You'll probably want to use `context.octokit` instead.
*
* **Note**: `app.auth` is asynchronous, so it needs to be prefixed with a
* [`await`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await)
Expand Down
6 changes: 3 additions & 3 deletions test/application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe("Application", () => {
.reply(200, {});

app.on("installation.created", async (context) => {
await context.github.request("/");
await context.octokit.request("/");
});

await app.receive(event);
Expand All @@ -173,7 +173,7 @@ describe("Application", () => {
.reply(200, {});

app.on("installation.deleted", async (context) => {
await context.github.request("/");
await context.octokit.request("/");
});

await app.receive(event).catch(console.log);
Expand All @@ -196,7 +196,7 @@ describe("Application", () => {
.reply(200, {});

app.on("check_run", async (context) => {
await context.github.request("/");
await context.octokit.request("/");
});

await app.receive(event).catch(console.log);
Expand Down
2 changes: 1 addition & 1 deletion test/deprecations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ describe("Deprecations", () => {
);
});

it("context.github", () => {
it("context.octokit", () => {
const octokit = new ProbotOctokit({});
const context = new Context(
{ name: "push", id: "1", payload: pushEvent },
Expand Down
6 changes: 3 additions & 3 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ describe("Probot", () => {
.reply(200, {});

probot.on("installation.created", async (context) => {
await context.github.request("/");
await context.octokit.request("/");
});

await probot.receive(event);
Expand Down Expand Up @@ -756,7 +756,7 @@ describe("Probot", () => {
.reply(200, {});

probot.on("installation.deleted", async (context) => {
await context.github.request("/");
await context.octokit.request("/");
});

await probot.receive(event).catch(console.log);
Expand Down Expand Up @@ -784,7 +784,7 @@ describe("Probot", () => {
.reply(200, {});

probot.on("check_run", async (context) => {
await context.github.request("/");
await context.octokit.request("/");
});

await probot.receive(event).catch(console.log);
Expand Down

0 comments on commit cea4318

Please sign in to comment.