Skip to content

feat: リポジトリ追加時に初回 crawl を自動 trigger (#274)#284

Merged
coji merged 1 commit intomainfrom
feat/auto-crawl-on-repo-add
Apr 7, 2026
Merged

feat: リポジトリ追加時に初回 crawl を自動 trigger (#274)#284
coji merged 1 commit intomainfrom
feat/auto-crawl-on-repo-add

Conversation

@coji
Copy link
Copy Markdown
Owner

@coji coji commented Apr 7, 2026

Summary

  • リポジトリ追加直後に該当 repo 限定の crawl を fire-and-forget で trigger し、既存 PR データが自動で表示されるようにする
  • concurrencyKey は per-repo (crawl:${orgId}:${repoId}) + coalesce: 'skip'。連続追加時に異なる repo の crawl が drop されず、同一 repo の重複クリックは安全に skip
  • crawl.server.ts で repositoryId 不一致時を throw → step.log.warn + 早期 return に緩和。追加直後に削除された race でジョブが失敗しない

Closes #274

変更点

  • app/services/jobs/concurrency-keys.server.ts: crawlRepoConcurrencyKey(orgId, repoId) を追加
  • app/services/jobs/crawl.server.ts: repositoryId 不一致を warn + 早期 return
  • app/routes/$orgSlug/settings/repositories.add/+functions/mutations.server.ts: addRepository.returning('id') で挿入 id を返す
  • app/routes/$orgSlug/settings/repositories.add/index.tsx: add 成功後に crawl trigger(fire-and-forget、失敗は Sentry へ)

Test plan

  • リポジトリ追加後、既存 PR データが自動で取得されることを確認
  • 同一リポを連続クリック時、2 回目以降の trigger が skip されることを確認
  • 異なる 2 リポを連続追加時、両方 crawl が走ることを確認
  • 追加直後に repo を削除しても crawl ジョブがエラーにならないことを確認

🤖 Generated with Claude Code

Summary by CodeRabbit

リリースノート

  • 新機能

    • リポジトリ追加後、自動的にスキャンが開始されるようになりました。
  • バグ修正

    • リポジトリ追加時のエラーハンドリングが改善されました。
    • リポジトリが見つからない場合の処理がより堅牢になりました。

リポ追加直後にデータが表示されるよう、該当 repo 限定の crawl を
fire-and-forget で trigger する。concurrencyKey は per-repo
(`crawl:${orgId}:${repoId}`) + coalesce: 'skip' で、連続追加時に
異なる repo の crawl が drop されないようにする。

併せて crawl.server.ts の repositoryId 不一致時を throw → warn + 早期
return に緩和。追加直後に削除された場合の race でジョブが失敗しない。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7b80f34f-d5e5-4c0e-a4d3-6458f0ca912a

📥 Commits

Reviewing files that changed from the base of the PR and between a673288 and 938f00e.

📒 Files selected for processing (4)
  • app/routes/$orgSlug/settings/repositories.add/+functions/mutations.server.ts
  • app/routes/$orgSlug/settings/repositories.add/index.tsx
  • app/services/jobs/concurrency-keys.server.ts
  • app/services/jobs/crawl.server.ts

📝 Walkthrough

Walkthrough

リポジトリ追加時に初回の自動crawlをトリガーする機能を追加しました。リポジトリID取得の仕様強化、crawlトリガーロジック、並行性キー生成、エラーハンドリングの緩和を実装しています。

Changes

Cohort / File(s) Summary
Database Query Enforcement
app/routes/$orgSlug/settings/repositories.add/+functions/mutations.server.ts
addRepositoryの戻り値を.returning('id').executeTakeFirstOrThrow()で確実に取得し、IDなしの結果を防止。
Repository Add Action Flow
app/routes/$orgSlug/settings/repositories.add/index.tsx
リポジトリ追加成功後にdurably.jobs.crawl.triggerをファイア・アンド・フォーゲットで実行。エラー時はSentryに報告し、per-repoの並行性制御を適用。
Concurrency Key Generation
app/services/jobs/concurrency-keys.server.ts
crawlRepoConcurrencyKey(orgId, repoId)エクスポート関数を追加。crawl:${orgId}:${repoId}パターンで並行実行を制御。
Crawl Error Handling
app/services/jobs/crawl.server.ts
リポジトリID指定時に対応レポが見つからない場合、エラースロー(失敗)から警告ログと早期成功終了に変更。一時的不一致を許容。

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Action as Repository Add Action
    participant DB as Database
    participant JobSystem as Job System
    participant CrawlJob as Crawl Job
    participant Sentry as Sentry (Error Tracking)

    User->>Action: Add new repository
    Action->>DB: Insert/Update repository
    DB-->>Action: Return repository (with id)
    
    Action->>JobSystem: Trigger crawl job<br/>(fire-and-forget)
    JobSystem-->>Action: Job queued
    Action-->>User: Success response
    
    par Background Processing
        JobSystem->>CrawlJob: Execute crawl<br/>(concurrencyKey: per-repo)
        CrawlJob->>DB: Fetch repository by id
        alt Repository exists
            CrawlJob->>DB: Fetch PRs and metadata
            DB-->>CrawlJob: Data
            CrawlJob-->>JobSystem: Success
        else Repository not found
            CrawlJob->>CrawlJob: Log warning (transient)
            CrawlJob-->>JobSystem: Success (early exit)
        end
    and Error Path
        JobSystem->>Sentry: If crawl trigger fails
        Sentry-->>JobSystem: Error recorded
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 リポを追加すりゃ、ひとりでに
crawlが走って、データ集め。
エラーはっ軽く「スキップ」だよ、
並行処理も、キーで統制。
ウサギのシステム、かしこくなった!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PRタイトルが主要な変更内容を正確に反映しており、リポジトリ追加時の初回crawlの自動トリガー機能を明確に示しています。
Linked Issues check ✅ Passed すべてのコード変更が#274の要件(自動crawlトリガー、concurrencyKey設定、repositoryId不一致時の警告への変更)を満たしています。
Out of Scope Changes check ✅ Passed すべての変更が#274で定義されたスコープ内であり、リポジトリ追加時のcrawl自動トリガー機能の実装に関連する変更のみです。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/auto-crawl-on-repo-add

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coji coji merged commit 6ccc827 into main Apr 7, 2026
7 checks passed
@coji coji deleted the feat/auto-crawl-on-repo-add branch April 7, 2026 04:06
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.

リポジトリ追加時に初回 crawl を自動 trigger する

1 participant