Skip to content

Commit

Permalink
📝 update quickstart docs
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Oct 8, 2024
1 parent 78d953b commit 5558799
Show file tree
Hide file tree
Showing 12 changed files with 447 additions and 260 deletions.
5 changes: 5 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MD013: false # line-length
MD024: # no-duplicate-heading
siblings_only: true
MD033: false # no-inline-html
MD046: false # code-block-style
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- markdownlint-disable MD033 MD041 -->
<!-- markdownlint-disable MD041 -->
<div align="center">

[![githubkit](https://socialify.git.ci/yanyongyu/githubkit/image?description=1&descriptionEditable=%E2%9C%A8%20GitHub%20SDK%20for%20Python%20%E2%9C%A8&font=Bitter&language=1&pattern=Circuit%20Board&theme=Light)](https://github.com/yanyongyu/githubkit)
Expand Down
2 changes: 0 additions & 2 deletions docs/contributing.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<!-- markdownlint-disable MD046 -->

# Contributing

We welcome contributions to the project. Thank you in advance for your contribution to githubkit!
Expand Down
2 changes: 0 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<!-- markdownlint-disable MD033 MD041 -->

# githubkit {: .hidden }

<div align="center" markdown>
Expand Down
44 changes: 22 additions & 22 deletions docs/quickstart/call-api-with-pat.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@

First, you need to create a PAT at [GitHub Personal Access Token](https://github.com/settings/personal-access-tokens/new). Then, copy the token and replace `<your_token_here>` in the following code.

## Sync Example
=== "Sync"

```python
from githubkit import GitHub
from githubkit.versions.latest.models import PublicUser, PrivateUser
```python
from githubkit import GitHub
from githubkit.versions.latest.models import PublicUser, PrivateUser

github = GitHub("<your_token_here>")
github = GitHub("<your_token_here>")

# call GitHub rest api
resp = github.rest.users.get_authenticated()
user: PublicUser | PrivateUser = resp.parsed_data
# call GitHub rest api
resp = github.rest.users.get_authenticated()
user: PublicUser | PrivateUser = resp.parsed_data

# call GitHub graphql api
data: dict = github.graphql("{ viewer { login } }")
```
# call GitHub graphql api
data: dict = github.graphql("{ viewer { login } }")
```

## Async Example
=== "Async"

```python
from githubkit import GitHub
from githubkit.versions.latest.models import PublicUser, PrivateUser
```python
from githubkit import GitHub
from githubkit.versions.latest.models import PublicUser, PrivateUser

github = GitHub("<your_token_here>")
github = GitHub("<your_token_here>")

# call GitHub rest api
resp = await github.rest.users.async_get_authenticated()
user: PublicUser | PrivateUser = resp.parsed_data
# call GitHub rest api
resp = await github.rest.users.async_get_authenticated()
user: PublicUser | PrivateUser = resp.parsed_data

# call GitHub graphql api
data: dict = await github.async_graphql("{ viewer { login } }")
```
# call GitHub graphql api
data: dict = await github.async_graphql("{ viewer { login } }")
```
136 changes: 70 additions & 66 deletions docs/quickstart/github-app.md
Original file line number Diff line number Diff line change
@@ -1,93 +1,97 @@
# Develop a GitHub APP

## Sync Example
## Authenticating as an installation by repository name

Authenticating as a installation by repository name:
=== "Sync"

```python
from githubkit import GitHub, AppAuthStrategy
from githubkit.versions.latest.models import Issue, Installation
```python
from githubkit import GitHub, AppAuthStrategy
from githubkit.versions.latest.models import Installation, IssueComment

github = GitHub(
AppAuthStrategy("your_app_id", "your_private_key", "client_id", "client_secret")
)
github = GitHub(
AppAuthStrategy("your_app_id", "your_private_key", "client_id", "client_secret")
)

resp = github.rest.apps.get_repo_installation("owner", "repo")
repo_installation: Installation = resp.parsed_data
resp = github.rest.apps.get_repo_installation("owner", "repo")
repo_installation: Installation = resp.parsed_data

installation_github = github.with_auth(
github.auth.as_installation(repo_installation.id)
)
installation_github = github.with_auth(
github.auth.as_installation(repo_installation.id)
)

# create a comment on an issue
resp = installation_github.rest.issues.create_comment("owner", "repo", 1, body="Hello")
issue: IssueComment = resp.parsed_data
```
# create a comment on an issue
resp = installation_github.rest.issues.create_comment("owner", "repo", 1, body="Hello")
issue: IssueComment = resp.parsed_data
```

Authenticating as a installation by username:
=== "Async"

```python
from githubkit import GitHub, AppAuthStrategy
from githubkit.versions.latest.models import Installation, IssueComment
```python
from githubkit import GitHub, AppAuthStrategy
from githubkit.versions.latest.models import Installation, IssueComment

github = GitHub(
AppAuthStrategy("your_app_id", "your_private_key", "client_id", "client_secret")
)
github = GitHub(
AppAuthStrategy("your_app_id", "your_private_key", "client_id", "client_secret")
)

resp = github.rest.apps.get_user_installation("username")
user_installation: Installation = resp.parsed_data
resp = await github.rest.apps.async_get_repo_installation("owner", "repo")
repo_installation: Installation = resp.parsed_data

installation_github = github.with_auth(
github.auth.as_installation(user_installation.id)
)
installation_github = github.with_auth(
github.auth.as_installation(repo_installation.id)
)

# create a comment on an issue
resp = installation_github.rest.issues.create_comment("owner", "repo", 1, body="Hello")
issue: IssueComment = resp.parsed_data
```
# create a comment on an issue
resp = await installation_github.rest.issues.async_create_comment(
"owner", "repo", 1, body="Hello"
)
issue: IssueComment = resp.parsed_data
```

## Async Example
## Authenticating as an installation by username

Authenticating as a installation by repository name:
=== "Sync"

```python
from githubkit import GitHub, AppAuthStrategy
from githubkit.versions.latest.models import Issue, Installation
```python
from githubkit import GitHub, AppAuthStrategy
from githubkit.versions.latest.models import Installation, IssueComment

github = GitHub(
AppAuthStrategy("your_app_id", "your_private_key", "client_id", "client_secret")
)
github = GitHub(
AppAuthStrategy("your_app_id", "your_private_key", "client_id", "client_secret")
)

resp = await github.rest.apps.async_get_repo_installation("owner", "repo")
repo_installation: Installation = resp.parsed_data
resp = github.rest.apps.get_user_installation("username")
user_installation: Installation = resp.parsed_data

installation_github = github.with_auth(
github.auth.as_installation(repo_installation.id)
)
installation_github = github.with_auth(
github.auth.as_installation(user_installation.id)
)

# create a comment on an issue
resp = await installation_github.rest.issues.async_create_comment("owner", "repo", 1, body="Hello")
issue: IssueComment = resp.parsed_data
```
# create a comment on an issue
resp = installation_github.rest.issues.create_comment("owner", "repo", 1, body="Hello")
issue: IssueComment = resp.parsed_data
```

Authenticating as a installation by username:
=== "Async"

```python
from githubkit import GitHub, AppAuthStrategy
from githubkit.versions.latest.models import Installation, IssueComment
```python
from githubkit import GitHub, AppAuthStrategy
from githubkit.versions.latest.models import Installation, IssueComment

github = GitHub(
AppAuthStrategy("your_app_id", "your_private_key", "client_id", "client_secret")
)
github = GitHub(
AppAuthStrategy("your_app_id", "your_private_key", "client_id", "client_secret")
)

resp = await github.rest.apps.async_get_user_installation("username")
user_installation: Installation = resp.parsed_data
resp = await github.rest.apps.async_get_user_installation("username")
user_installation: Installation = resp.parsed_data

installation_github = github.with_auth(
github.auth.as_installation(user_installation.id)
)
installation_github = github.with_auth(
github.auth.as_installation(user_installation.id)
)

# create a comment on an issue
resp = await installation_github.rest.issues.async_create_comment("owner", "repo", 1, body="Hello")
issue: IssueComment = resp.parsed_data
```
# create a comment on an issue
resp = await installation_github.rest.issues.async_create_comment(
"owner", "repo", 1, body="Hello"
)
issue: IssueComment = resp.parsed_data
```
8 changes: 3 additions & 5 deletions docs/quickstart/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<!-- markdownlint-disable MD033 MD041 -->

# Quick Start

Here are some common use cases to help you get started quickly. For more detailed usage, please refer to the [Usage](../usage/authentication.md) section.
Expand All @@ -22,19 +20,19 @@ Here are some common use cases to help you get started quickly. For more detaile

---

Develop an [OAuth APP](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/creating-an-oauth-app) ([GitHub APP](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app)) with web flow
Develop an [OAuth APP](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/creating-an-oauth-app) ([GitHub APP](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app)) with web flow and act on behalf of a user

- :octicons-file-code-16: [OAuth APP Device Flow](./oauth-device-flow.md)

---

Develop an [OAuth APP](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/creating-an-oauth-app) ([GitHub APP](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app)) with device flow
Develop an [OAuth APP](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/creating-an-oauth-app) ([GitHub APP](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app)) with device flow and act on behalf of a user

- :octicons-file-code-16: [GitHub APP](./github-app.md)

---

Develop a [GitHub APP](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app)
Develop a [GitHub APP](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app) and act on behalf of an installation or a user.

<!-- prettier-ignore-end -->

Expand Down
Loading

0 comments on commit 5558799

Please sign in to comment.