Skip to content

refactor: extract createSession helper in Linear bot#536

Merged
ColeMurray merged 1 commit intomainfrom
pre-step-6/linear-extract-createSession
Apr 22, 2026
Merged

refactor: extract createSession helper in Linear bot#536
ColeMurray merged 1 commit intomainfrom
pre-step-6/linear-extract-createSession

Conversation

@ColeMurray
Copy link
Copy Markdown
Owner

@ColeMurray ColeMurray commented Apr 22, 2026

Summary

  • Extracts the inline fetch("https://internal/sessions", ...) in handleNewSession into a dedicated createSession helper
  • Returns a discriminated union ({ ok: true, sessionId } | { ok: false, status, body }) so the caller retains full error context for activity messages and logging
  • The Linear bot was the only bot without a createSession helper — Slack and GitHub bots already had one

Pre-step 6 of the unified user model migration (pre-steps doc). The main migration will add actor* identity parameters to this helper's interface — having the function already extracted keeps that PR focused on identity resolution logic.

Test plan

  • npm run typecheck -w @open-inspect/linear-bot passes
  • npm test -w @open-inspect/linear-bot — all 90 tests pass

Summary by CodeRabbit

  • Refactor
    • Improved internal session creation and error handling with unified error reporting patterns for better reliability and maintainability.

The inline fetch to create sessions was the only bot without a
dedicated helper. Extract it so the main migration can add identity
parameters to the helper interface without restructuring the
function in the same change.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1ecfea16-af84-4957-b795-184543b36a5f

📥 Commits

Reviewing files that changed from the base of the PR and between 95707dd and 3ac2b4d.

📒 Files selected for processing (1)
  • packages/linear-bot/src/webhook-handler.ts

📝 Walkthrough

Walkthrough

A new createSession helper function was introduced to centralize control-plane session creation logic, including authentication header generation, spawnSource injection, and unified error handling. The handleNewSession function was refactored to use this helper instead of inline fetch operations, with auth headers now fetched after session creation.

Changes

Cohort / File(s) Summary
Session Creation Refactoring
packages/linear-bot/src/webhook-handler.ts
Extracted createSession helper function with unified error handling (returns { ok: false, status, body } or { ok: true, sessionId }). Refactored handleNewSession to use the helper, reordering auth header retrieval to occur after session creation and adjusting error logging to use sessionResult.status and sessionResult.body.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • open-inspect

Poem

🐰 A helper bunny hops in to play,
Extracting sessions in a cleaner way,
Auth headers shuffle, then flow reordered,
Errors unified, boundaries bordered,
Code now tidier—hip hip hooray! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: extract createSession helper in Linear bot' directly and clearly describes the main change: extracting a createSession helper function from inline code in the Linear bot webhook handler.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 pre-step-6/linear-extract-createSession

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.

@github-actions
Copy link
Copy Markdown

Terraform Validation Results

Step Status
Format
Init
Validate

Note: Terraform plan was skipped because secrets are not configured. This is expected for external contributors. See docs/GETTING_STARTED.md for setup instructions.

Pushed by: @ColeMurray, Action: pull_request

Copy link
Copy Markdown
Contributor

@open-inspect open-inspect Bot left a comment

Choose a reason for hiding this comment

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

Summary

Extracts the Linear bot session creation request into a dedicated helper and preserves the existing error reporting shape at the call site. I reviewed the single-file refactor against the surrounding handler flow and did not find correctness, security, performance, or maintainability regressions.

  • PR Title and number: refactor: extract createSession helper in Linear bot (#536)
  • Author: @ColeMurray
  • Files changed: 1
  • Additions/deletions: +52 / -22

Critical Issues

None.

Suggestions

None.

Nitpicks

None.

Positive Feedback

  • The extracted helper keeps the spawnSource wiring centralized, which should make the upcoming identity-related follow-up change narrower and easier to review.
  • Returning a discriminated union preserves the caller ability to surface the control-plane HTTP status and truncated body without pushing Linear-specific logging concerns into the helper.
  • Verification looks solid for a refactor of this scope: npm run typecheck -w @open-inspect/linear-bot passed and all 90 Linear bot tests passed.

Questions

None.

Verdict

Approve

@ColeMurray ColeMurray merged commit 309fc4c into main Apr 22, 2026
18 checks passed
@ColeMurray ColeMurray deleted the pre-step-6/linear-extract-createSession branch April 22, 2026 06:38
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.

1 participant