Skip to content

octocrab を 0.49 に上げる#24

Merged
zaimy merged 3 commits into
masterfrom
bump-octocrab
Apr 24, 2026
Merged

octocrab を 0.49 に上げる#24
zaimy merged 3 commits into
masterfrom
bump-octocrab

Conversation

@zaimy
Copy link
Copy Markdown
Contributor

@zaimy zaimy commented Apr 24, 2026

Summary

octocrab 0.8.13 から 0.49.x へのバージョンアップです。前段の #23 のマージ後に適用することを想定しています。

Changes

依存関係

  • reqwest への直接依存を削除しました。octocrab が内部で reqwest を使わなくなり、 reqwest::Url を介して型を共有する必要がなくなったためです
  • url を features = ["serde"] で直接依存に追加しました
  • http 1 系を直接依存に追加しました ( Page::nextOption<http::Uri> 型になったため)

コード

  • models::Usermodels::Author に改名されたため、各 fetcher の import を Author as User でエイリアスしたり、直接 Author に切り替えたりして追従しました
  • UserId, IssueId, LabelId, CommentId, WorkflowId, JobId, RunId などの id フィールドが pub struct XxxId(pub u64) の newtype になったため、 from.id.0 as i64 のような形で既存レコードの i64 型との間を取り持っています
  • Issue::stateIssueState enum、 Issue::author_associationOption<AuthorAssociation> に変更されたので、 IssueRec 側もそれぞれ型を差し替えました
  • Job::status / Step::statusworkflows::Status enum、 Job::conclusion / Step::conclusionOption<Conclusion> enum に変更されたので、CSV 出力の snake_case 文字列を維持するため enum_to_string ヘルパ経由で変換しています
  • Step::started_atOption<DateTime> に変更されたので、 JobStepRec::started_at も Option 化しました
  • Job::check_run_urlUrl から String に変更されたので、 JobRec::check_run_urlJobStepRec::check_run_urlString にしました
  • OctocrabBuilder::base_url(&Url)base_uri(impl TryInto<Uri>) に改名されたので、 src/main.rs の呼び出しを差し替えました

Review points

  • CSV 出力のフォーマット互換を維持することを最優先にしています。数値 id は i64 のまま、enum は serde 経由で snake_case 文字列にしています
  • Cargo.lock の差分が大きいですが、hyper / rustls / tokio など依存グラフが大きく変わるためです
  • 既存テスト ( src/issues.rs::test_convert_issue_model ) が無改修で通過することを確認しました

Context

octx に GitHub App installation token 認証を追加する準備として、3 本に分割した PR のうちの 2 本目です。3 本目で App 認証を追加します。

本 PR では Cargo.toml の version は上げません。3 本マージ完了後にまとめて bump する想定です。

Follow-up to the route-string migration. Replace reqwest-based
dependencies with url + http direct deps, adapt to renamed and
newtyped models, and convert enum fields to strings where the
CSV output expected them.

Notable adjustments:
- reqwest dep dropped; url + http added as direct dependencies
- Octocrab::absolute_url() removed in favor of passing route
  strings to Octocrab::get(), already done in the previous PR
- models::User renamed to Author, id fields are now newtypes
  (UserId / IssueId / LabelId / WorkflowId / JobId / RunId / CommentId)
- Issue::state, Job::status and Step::status are now enums;
  they are serialized to snake_case strings via a small helper
- Issue::author_association is Option<AuthorAssociation>;
  record type updated accordingly
- Step::started_at is now Option<DateTime>; JobStepRec follows
- Job::check_run_url is now String, not Url
Base automatically changed from migrate-to-route-strings to master April 24, 2026 06:02
@zaimy zaimy marked this pull request as ready for review April 24, 2026 06:08
@n01e0
Copy link
Copy Markdown

n01e0 commented Apr 24, 2026

#23 では repos/{owner}/... のように先頭 / を付けない方針が正しかったと理解しています。あの時点では octocrab 0.8.13 の Octocrab::getabsolute_url(route) を呼び、その中で base_url.join(...) していました。

そのため、GHES の GITHUB_API_URL=https://git.example.com/api/v3/ のような base URL では、/repos/... にすると url::Url::join の semantics で /api/v3/ prefix が落ちる、という #23 のコメントは妥当です。

ただ、この PR で octocrab 0.49 に上がることで前提が変わっています。0.49.7 の Octocrab::getget_with_headers -> parameterized_uri 経由で、渡された route をまず http::Uri::from_str に通しています。

このため、repos/{owner}/{repo}/issues?...users?... は API リクエストに到達する前に InvalidUri(InvalidFormat) になります。ローカルでも IssueFetcher::fetch を呼ぶ最小テストで octocrab::Error::Uri が返ることを確認しました。

一方で、octocrab 0.49 の BaseUriLayer は base URI の path を保持して request path と結合する実装になっています。

なので、#23Url::join 前提では repos/... が正しく、#24 の octocrab 0.49 前提では /repos/... のような http::Uri として valid な path が必要、という整理だと思います。

#25bump-octocrab を base にした GitHub App 認証追加で、fetcher の route 生成には触れていないため、この問題は #25 では解消されません。この PR の段階で、手動生成している repos/...users?... の route を 0.49 向けに修正する必要がありそうです。

octocrab 0.49 passes the `route` argument to `http::Uri::from_str`
before the BaseUriLayer gets a chance to combine it with base_uri.
Path-only URIs must start with a slash per the http crate, so
without a leading slash the call fails with
`Error::Uri { source: InvalidUri { kind: InvalidFormat } }`
before reaching the network.

The BaseUriLayer preserves the base URI's path when joining, so
leading-slash routes like `/repos/...` work correctly against
GHES base URIs of the form `https://.../api/v3/` as well.
@zaimy
Copy link
Copy Markdown
Contributor Author

zaimy commented Apr 24, 2026

@n01e0
ご指摘ありがとうございます。調査いただいたとおり、octocrab 0.49 では Octocrab::get が内部で parameterized_uri 経由で http::Uri::from_str(route) を通していて、 path-only URI は先頭 / が無いと InvalidUri { kind: InvalidFormat } で失敗するため、 repos/... のままではランタイムで Error::Uri になることを確認しました。

BaseUriLayer は base URI の path を trim_end_matches('/') した上で request path に prepend するので、 path-only の /repos/... を渡しておけば GHES の /api/v3/ prefix も正しく保持されることが確認できました。

整理いただいたとおり、 #23 (octocrab 0.8.13) は base_url.join 経由で repos/... が正しく、 この PR では Uri::from_str + BaseUriLayer 経由になるため /repos/... が必要、という前提の違いがありました。
すべての fetcher の route リテラルに先頭 / を付ける修正を f5a8b6d にコミットしました。ご指摘助かりました。

Copy link
Copy Markdown

@n01e0 n01e0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Yosasou To Me

@zaimy zaimy merged commit ea4f4bc into master Apr 24, 2026
1 check passed
@zaimy zaimy deleted the bump-octocrab branch April 24, 2026 07:56
@zaimy
Copy link
Copy Markdown
Contributor Author

zaimy commented Apr 24, 2026

ありがとうございまsu!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants