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

Feature: introduce api versioning, lazy loading and webhook namespace #73

Merged
merged 19 commits into from
Dec 28, 2023

Conversation

yanyongyu
Copy link
Owner

@yanyongyu yanyongyu commented Dec 27, 2023

New Features

Webhook Namespace

Webhook payload parsing can now be done with both function and GitHub class.

from githubkit import GitHub
from githubkit.webhooks import parse_obj

parse_obj("event", payload)  # defaults to latest stable schema
GitHub.webhooks.parse_obj("event", payload)  # defaults to latest stable schema
GitHub.webhooks("2022-11-28").parse_obj("event", payload)

webhook parsing with event name supports type infer with overload.

from githubkit import GitHub
from githubkit.versions.latest.webhooks import PullRequestEvent

event: PullRequestEvent = GitHub.webhooks.parse_obj("pull_request", payload)

Warning

webhook models cannot be imported from githubkit.webhooks now,
use githubkit.versions.latest.models instead.
webhook types cannot be imported from githubkit.webhooks.types now,
use githubkit.versions.latest.webhooks instead.

API Versioning

API usage:

from githubkit import GitHub

g = GitHub()

# for rest api
# use latest stable version
g.rest.repos.get("owner", "repo")
# use specific version
g.rest("2022-11-28").repos.get("owner", "repo")

# for webhooks
# use latest stable version
g.webhooks.parse_obj("event", payload)
# use specific version
g.webhooks("2022-11-28").parse_obj("event", payload)

model schema usage:

# import from specific version
from githubkit.versions.v2022_11_28.models import FullRepository
# latest module always links to latest stable schema
from githubkit.versions.latest.models import FullRepository

Breakings

  • Webhook models and types should be imported from githubkit.versions.latest.* due to the schema migrated to openapi description

Refs

fix #9
fix #10
fix #67
related to #11
related to #54

@yanyongyu yanyongyu added the enhancement New feature or request label Dec 27, 2023
@yanyongyu yanyongyu merged commit 9449b1a into master Dec 28, 2023
2 checks passed
@yanyongyu yanyongyu deleted the feat/codegen-refactor branch December 28, 2023 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
1 participant