Skip to content

refactor(github): extract the connection probe into an internal helper - #2723

Merged
merill merged 1 commit into
maester365:mainfrom
thetechgy:refactor/github-connection-probe-2674
Nov 8, 2026
Merged

merill merged 1 commit into
maester365:mainfrom
thetechgy:refactor/github-connection-probe-2674

Conversation

@thetechgy

@thetechgy thetechgy commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

This follows up on Merill's suggestion on #2633 to move the nested connection probe into its own internal GitHub helper.

Connect-MtGitHub now passes the request URI, authentication headers and shared rate-limit connection to Invoke-MtGitHubConnectionProbe. The request and response handling, 30-second connection and operation timeouts, error classification and cooldown transfer remain unchanged. Administration-probe failures still allow the connection to complete. There are no public API or authentication changes.

The existing connection and rate-limit tests cover the explicit inputs, shared connection identity, response/error handling and cooldowns at each probe.

Closes #2674.

Validation

On Linux / PowerShell 7.6.6 / Pester 5.7.1:

  • All 120 focused connection and rate-limit tests passed.
  • All 108 connection and rate-limit tests passed against the built module.
  • All 31 expanded rate-limit tests also passed against the unchanged base.
  • Changed-file PSScriptAnalyzer, module build and output validation passed.

The complete ./powershell/tests/pester.ps1 run reported 7,064 tests, including 93 skips and five failures. All five failures reproduced on unchanged base bb7a0e8cc: one console-colour assertion and four Azure request URI assertions. Those failures are outside this change. The GitHub transport tests, including the real loopback timeout fixtures, passed in the full run.

No live GitHub connection was used for validation. Network-dependent tests use mocks or local loopback fixtures.

Checks

  • My pull request adheres to the code style of this project.
  • My code requires changes to the documentation.
  • I have updated the documentation as required.
  • The build and unit tests pass after running /powershell/tests/pester.ps1 locally.

The helper includes comment-based help. The full-suite checkbox is left unchecked because of the baseline failures described above.

Summary by CodeRabbit

  • Bug Fixes
    • GitHub connection checks now consistently respect shared API rate limits across user, organization, membership, and Actions permissions checks.
    • When a connection check succeeds or fails, rate-limit information is retained. Requests remain blocked when the applicable limit is exhausted, helping prevent avoidable API calls.

@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The GitHub connection probe moved to an internal service helper. All four bootstrap probes now use it with shared headers and connection state. The helper checks rate limits, sends timed GET requests, records response or error state, and returns responses or rethrows errors.

Changes: GitHub connection probes

Layer / File(s) Summary
Extract the connection probe
powershell/internal/services/github/Invoke-MtGitHubConnectionProbe.ps1, powershell/tests/functions/Connect-MtGitHub.Tests.ps1
The helper checks rate limits before requests, sends GET requests with 30-second connection and operation timeouts, and records responses or errors. Tests cover request ordering, response handling, and error propagation.
Route bootstrap probes through the helper
powershell/public/connect/Connect-MtGitHub.ps1, powershell/tests/functions/Connect-MtGitHub.Tests.ps1, powershell/tests/functions/GitHubRateLimit.Tests.ps1
The user, organization, membership, and administration probes use the helper with shared headers and connection state. Tests cover helper usage and rate-limit outcomes across all four probes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Possibly related PRs

Suggested reviewers: merill, samerde

Merge Risk: Minimal · up to 6edfa

No actionable regression was identified in the connection-probe extraction. Merge readiness remains subject to normal validation.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title "refactor(github): extract the connection probe into an internal helper" matches the main change. The PR moves the nested connection probe out of Connect-MtGitHub into the internal helper In…
Description check Passed The description follows the repository template's main sections. It has a Description section that explains the helper extraction, the explicit inputs, the unchanged timeouts, error handling, and cool…
Linked Issues check Passed Issue #2674 is the only active direct target. Its coding requirements are met at head 6edfa3e:

1. Helper: powershell/internal/services/github/Invoke-MtGitHubConnectionProbe.ps1 defines one functi…
Out of Scope Changes check Passed All changed areas connect to #2674:

- Invoke-MtGitHubConnectionProbe.ps1 (new internal helper): the extracted probe logic that the issue requests.
- Connect-MtGitHub.ps1: the four call sites swit…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Title check

Explanation

The title "refactor(github): extract the connection probe into an internal helper" matches the main change. The PR moves the nested connection probe out of Connect-MtGitHub into the internal helper Invoke-MtGitHubConnectionProbe, and the title names that refactor and its scope. It is specific and concise, and it does not describe anything absent from the changeset.

Full details: Description check

Explanation

The description follows the repository template's main sections. It has a Description section that explains the helper extraction, the explicit inputs, the unchanged timeouts, error handling, and cooldown behavior. It has a Validation section with test results and baseline failures, and it has the Checks list. It also states the linked issue, #2674. Gaps: the 'Closes' line is filled in, but the template's introductory code-freeze notice is not addressed. The template's bug-fix-only code-freeze rule for Maester 3.0 (from 7 November 2026) applies to this PR, which is a refactor and not a bug fix. The author did not acknowledge that rule. The Additional Information section is also not used, and two checkboxes are unchecked, which the author explains. The description is mostly complete, so the check passes.

Full details: Linked Issues check

Explanation

Issue #2674 is the only active direct target. Its coding requirements are met at head 6edfa3e:

  1. Helper: powershell/internal/services/github/Invoke-MtGitHubConnectionProbe.ps1 defines one function with the approved verb Invoke and a GitHub-specific name. It takes explicit -Uri, -Headers and -Connection parameters.
  2. Routing: Connect-MtGitHub.ps1 sends the token identity, organization, membership and administration probes through the helper. The local nested Invoke-ConnectionProbe is removed. Each call passes $authHeaders and the same $rateLimitConnection.
  3. Behavior: the helper runs Invoke-MtGitHubRateLimitGuard before the GET request and after the response or error. It keeps -ConnectionTimeoutSeconds 30 and -OperationTimeoutSeconds 30. It rethrows errors. The admin-probe catch logic is not in the diff, so its non-blocking behavior is unchanged.
  4. Session state: the same $rateLimitConnection object is used across all probes, so cooldown state carries forward.
  5. Tests: Connect-MtGitHub.Tests.ps1 adds a test that asserts all four probes use the helper with the same connection object and auth headers. It also adds helper tests for guard order, GET options, response return and error rethrow. The summary reports that GitHubRateLimit.Tests.ps1 covers cooldown retention and blocking or non-blocking probe failures. I did not inspect that file directly.

Non-coding items (PSScriptAnalyzer run, module build, full-suite run, baseline failure reporting) are excluded from this verdict.

Full details: Out of Scope Changes check

Explanation

All changed areas connect to #2674:

  • Invoke-MtGitHubConnectionProbe.ps1 (new internal helper): the extracted probe logic that the issue requests.
  • Connect-MtGitHub.ps1: the four call sites switch to the helper and the local function is removed. The diff shows no other behavior change.
  • Connect-MtGitHub.Tests.ps1: tests for helper routing and helper behavior, which the issue requests.
  • GitHubRateLimit.Tests.ps1: per the summary, primary-exhaustion coverage across the four probes, including cooldown retention. This matches the issue's requested cooldown-retention coverage. The change replaces an earlier two-case test. I did not inspect this file directly.

The helper is internal and the PR reports no changes to exported declarations. No unrelated feature, refactor or documentation change was found in the reviewed diffs.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 0 files. (4 skipped: 4 unsupported.)

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 50ef692 and 6edfa3e.

Files selected for processing: 4

  • powershell/internal/services/github/Invoke-MtGitHubConnectionProbe.ps1
  • powershell/public/connect/Connect-MtGitHub.ps1
  • powershell/tests/functions/Connect-MtGitHub.Tests.ps1
  • powershell/tests/functions/GitHubRateLimit.Tests.ps1

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@thetechgy
thetechgy marked this pull request as ready for review November 8, 2026 00:27
@thetechgy
thetechgy requested a review from a team as a code owner November 8, 2026 00:27
Copilot AI balanced review requested due to automatic review settings November 8, 2026 00:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@merill merill left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome. LGTM

@merill
merill merged commit fe14a75 into maester365:main Nov 8, 2026
16 checks passed
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.

refactor(github): extract the connection probe into an internal helper

3 participants