Skip to content

fix: resolve pr number via branch fallback when pull_requests is empty#24

Merged
calebephrem merged 3 commits into
open-devhub:mainfrom
calebephrem:main
Jun 25, 2026
Merged

fix: resolve pr number via branch fallback when pull_requests is empty#24
calebephrem merged 3 commits into
open-devhub:mainfrom
calebephrem:main

Conversation

@calebephrem

Copy link
Copy Markdown
Member

No description provided.

@vercel

vercel Bot commented Jun 25, 2026

Copy link
Copy Markdown

@calebephrem is attempting to deploy a commit to the calebephrem's projects Team on Vercel.

A member of the Team first needs to authorize it.

@devhub-bot devhub-bot Bot added the fix Bug fix label Jun 25, 2026
@beetle-ai

beetle-ai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary by Beetle

This PR removes the visual glow effect from the header text by eliminating the box-shadow styling. The change simplifies the visual design by removing both the CSS custom property for accent glow and its application as a text-shadow on the header element. This is a focused UI refinement that reduces visual complexity and potentially improves rendering performance.

📁 File Changes Summary (Consolidated across all commits):

File Status Changes Description
src/index.html Modified +0/-3 Removed --accent-glow CSS custom property definition and eliminated text-shadow styling from header element to remove the glow effect

Total Changes: 1 file changed, +0 additions, -3 deletions

🎯 Key Changes:

  • Removed CSS custom property: Deleted --accent-glow: rgba(139, 141, 255, 0.35); from the root CSS variables, eliminating the unused color definition
  • Removed text-shadow effect: Eliminated text-shadow: 0 0 30px var(--accent-glow); from the header styling, removing the visual glow effect around header text
  • Visual simplification: The header now displays with clean, crisp text without any shadow or glow effects

📊 Impact Assessment:

  • Security: No security implications. This is a purely cosmetic CSS change with no impact on application security or data handling.
  • Performance: Minor positive impact. Removing text-shadow effects can slightly improve rendering performance, especially on lower-end devices or when multiple elements are rendered. Text-shadow with blur radius requires additional GPU processing, so its removal reduces rendering overhead.
  • Maintainability: Positive impact. The change removes unused CSS variables and simplifies the styling code. This makes the codebase cleaner and easier to maintain by eliminating unnecessary visual effects and their associated configuration.
  • Testing: Low testing requirements. This is a visual-only change that should be verified through:
  • Visual regression testing to ensure the header appears as intended without the glow
  • Cross-browser testing to confirm consistent appearance
  • No functional testing required as no behavior changes are introduced
⚙️ Settings

Severity Threshold: Medium — Balanced feedback — medium and high severity issues only.Change in Settings
Custom Rules: Define your own review rules — Set Custom Rules
PR Summary: Configure PR summary — Change in Settings

📖 User Guide
  • Once repos are connected, PR analysis is automatically enabled. You can disable analysis for this repo from beetleai.dev/analysis
  • Comment @beetle on any PR to start analysis manually
  • Comment @beetle stop to stop any ongoing analysis

Follow us: Beetle · X · LinkedIn

@beetle-ai

beetle-ai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

✅ You're good to merge this PR! No issues found. Great job!

Settings
⚙️ Settings

Severity Threshold: Medium — Balanced feedback — medium and high severity issues only.Change in Settings
Custom Rules: Define your own review rules — Set Custom Rules
PR Summary: Configure PR summary — Change in Settings

📖 User Guide
  • Once repos are connected, PR analysis is automatically enabled. You can disable analysis for this repo from beetleai.dev/analysis
  • Comment @beetle on any PR to start analysis manually
  • Comment @beetle stop to stop any ongoing analysis

@beetle-ai

beetle-ai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary by Beetle

This PR fixes a critical issue in the workflow run completion handler for linting checks. When the pull_requests array is empty in the workflow run payload (which can occur in certain GitHub Actions scenarios), the bot now falls back to resolving the PR number by querying open PRs matching the workflow's head branch and SHA. This ensures the bot can reliably post linting status comments even when the direct PR association is unavailable.

📁 File Changes Summary (Consolidated across all commits):

File Status Changes Description
src/events/workflow_run.completed/checklint.ts Modified +36/-13 Refactored PR number resolution logic by extracting a new resolvePullNumber() helper function that implements a fallback mechanism. When pull_requests array is empty, the function queries the GitHub API to find matching open PRs by branch name and SHA. Also restructured the main handler to resolve PR number once at the beginning, eliminating duplicate code blocks.

Total Changes: 1 file changed, +36 additions, -13 deletions

🎯 Key Changes:

  • New Fallback Resolution Logic: Introduced resolvePullNumber() helper function that attempts to resolve PR numbers through multiple strategies:
  1. First checks the direct pull_requests array from workflow run payload
  2. Falls back to querying open PRs by head_branch and matching against head_sha
  3. Returns null if no PR can be resolved, allowing graceful early exit
  • Code Deduplication: Eliminated duplicate PR number resolution logic that previously appeared twice in the handler (once for success case, once for failure case)
  • Early Exit Pattern: Moved PR number resolution to the top of the handler, enabling early return if no PR is found, improving code flow and readability
  • Minor Text Fix: Corrected apostrophe encoding in success message ("You're" instead of "You\u2019re")

📊 Impact Assessment:

  • Security: ✅ Positive - The fallback mechanism includes proper validation by matching both branch name and SHA, preventing incorrect PR associations. The function safely handles null/undefined values and returns null when resolution fails.
  • Performance: ⚠️ Minor Impact - Introduces an additional API call (pulls.list) when pull_requests is empty. However, this is a necessary trade-off for reliability and only occurs in edge cases. The query is filtered by branch name and limited to open PRs, keeping the overhead minimal.
  • Maintainability: ✅ Improved - Significantly better code organization through:
  • Extraction of resolution logic into a dedicated, testable function
  • Elimination of code duplication (DRY principle)
  • Clear separation of concerns (resolution vs. comment posting)
  • Better type safety with explicit return type Promise<number | null>
  • Testing: ⚠️ Needs Attention - The new fallback logic should be covered by tests for scenarios including:
  • Empty pull_requests array with valid branch/SHA
  • Multiple PRs matching the branch (ensures correct SHA matching)
  • No matching PRs found (null return case)
  • Missing head_branch in workflow run payload
⚙️ Settings

Severity Threshold: Medium — Balanced feedback — medium and high severity issues only.Change in Settings
Custom Rules: Define your own review rules — Set Custom Rules
PR Summary: Configure PR summary — Change in Settings

📖 User Guide
  • Once repos are connected, PR analysis is automatically enabled. You can disable analysis for this repo from beetleai.dev/analysis
  • Comment @beetle on any PR to start analysis manually
  • Comment @beetle stop to stop any ongoing analysis

Follow us: Beetle · X · LinkedIn

@calebephrem calebephrem changed the title fix: remove box shadow from header fix: resolve pr number via branch fallback when pull_requests is empty Jun 25, 2026
Comment thread src/events/workflow_run.completed/checklint.ts Outdated
@beetle-ai

beetle-ai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @beetle command.

⚙️ Settings

Severity Threshold: Medium — Balanced feedback — medium and high severity issues only.Change in Settings
Custom Rules: Define your own review rules — Set Custom Rules
PR Summary: Configure PR summary — Change in Settings

📖 User Guide
  • Once repos are connected, PR analysis is automatically enabled. You can disable analysis for this repo from beetleai.dev/analysis
  • Comment @beetle on any PR to start analysis manually
  • Comment @beetle stop to stop any ongoing analysis

Follow us: Beetle · X · LinkedIn

Co-authored-by: beetle-ai[bot] <221859081+beetle-ai[bot]@users.noreply.github.com>
@beetle-ai

beetle-ai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary by Beetle

This PR addresses two distinct issues: a visual styling fix and a critical bug fix for PR number resolution in workflow automation. The main focus is on improving the reliability of the checklint workflow handler by implementing a robust fallback mechanism to resolve PR numbers when the direct pull_requests array is empty. Additionally, it removes unnecessary visual effects from the header styling.

📁 File Changes Summary (Consolidated across all commits):

File Status Changes Description
src/index.html Modified +0/-3 Removed --accent-glow CSS variable and its associated text-shadow effect from the header, simplifying the visual design by eliminating the glow effect
src/events/workflow_run.completed/checklint.ts Modified +37/-14 Enhanced PR number resolution logic by extracting a new resolvePullNumber helper function that implements a fallback strategy: first attempts to use direct PR references, then falls back to querying open PRs by branch name and SHA matching when the direct reference is unavailable

Total Changes: 2 files changed, +37 additions, -17 deletions

🗺️ Walkthrough:

sequenceDiagram
participant WF as Workflow Run Event
participant Handler as checklint Handler
participant Resolver as resolvePullNumber
participant GitHub as GitHub API
participant PR as Pull Request
WF->>Handler: workflow_run.completed event
Handler->>Resolver: Request PR number resolution
alt Direct PR reference exists
Resolver->>Resolver: Check pull_requests array
Resolver-->>Handler: Return PR number
else Fallback to branch lookup
Resolver->>Resolver: Extract head_branch & head_sha
Resolver->>GitHub: List open PRs for branch
GitHub-->>Resolver: Return matching PRs
Resolver->>Resolver: Find PR by SHA match
Resolver-->>Handler: Return PR number or null
end
alt PR number resolved
Handler->>Handler: Check workflow conclusion
alt Success
Handler->>PR: Post success comment
else Failure
Handler->>PR: Post failure comment with logs
end
else No PR found
Handler->>Handler: Exit silently
end
Loading

🎯 Key Changes:

  • Robust PR Resolution: Introduced resolvePullNumber helper function that implements a two-tier resolution strategy, significantly improving reliability when workflow_run.pull_requests is empty
  • Fallback Mechanism: When direct PR references are unavailable, the system now queries GitHub's API for open PRs matching the workflow's branch and SHA, ensuring comments are posted even in edge cases
  • Early Exit Pattern: Refactored the handler to resolve the PR number once at the beginning, enabling early exit if no PR is found and eliminating code duplication
  • Code Organization: Extracted PR resolution logic into a dedicated function with proper TypeScript typing, improving maintainability and testability
  • Visual Cleanup: Removed unnecessary glow effects from the header, resulting in a cleaner, more professional appearance
  • Precise Matching: The fallback mechanism prioritizes exact SHA matches over simple branch name matches, preventing comments from being posted to the wrong PR

📊 Impact Assessment:

  • Security: ✅ Positive Impact - The SHA-based matching in the fallback mechanism ensures comments are only posted to the correct PR, preventing potential information leakage to wrong PRs. The removal of the prs[0] fallback in the final commit eliminates the risk of posting to an arbitrary PR when no SHA match is found.
  • Performance: ⚡ Minor Impact - The fallback mechanism introduces an additional API call (pulls.list) only when the direct PR reference is unavailable. This is acceptable as it's a rare edge case. The early exit pattern when no PR is found prevents unnecessary processing, slightly improving performance in failure scenarios.
  • Maintainability: ✅ Significant Improvement - The extraction of resolvePullNumber as a separate function with clear responsibility boundaries greatly improves code organization. The function is well-typed, self-contained, and easier to test in isolation. The elimination of duplicate PR resolution logic reduces maintenance burden and potential for bugs.
  • Testing: ⚠️ Testing Recommended - The new fallback logic should be tested with scenarios where:
  • pull_requests array is empty (primary use case)
  • Multiple PRs exist for the same branch
  • No matching PR is found by SHA
  • Branch name contains special characters
  • The workflow is triggered from a fork (edge case)
    Consider adding unit tests for resolvePullNumber to validate all code paths, especially the fallback mechanism.
⚙️ Settings

Severity Threshold: Medium — Balanced feedback — medium and high severity issues only.Change in Settings
Custom Rules: Define your own review rules — Set Custom Rules
PR Summary: Configure PR summary — Change in Settings

📖 User Guide
  • Once repos are connected, PR analysis is automatically enabled. You can disable analysis for this repo from beetleai.dev/analysis
  • Comment @beetle on any PR to start analysis manually
  • Comment @beetle stop to stop any ongoing analysis

Follow us: Beetle · X · LinkedIn

Comment on lines +93 to +98
const { data: prs } = await context.octokit.rest.pulls.list({
owner,
repo,
state: "open",
head: `${owner}:${headBranch}`,
});

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.

The context.octokit.rest.pulls.list() API call lacks error handling. If this call fails (network issues, rate limits, permission errors), the entire workflow handler will crash and no comment will be posted to the PR. This is a critical path that should handle failures gracefully.

Confidence: 5/5

Suggested Fix
Suggested change
const { data: prs } = await context.octokit.rest.pulls.list({
owner,
repo,
state: "open",
head: `${owner}:${headBranch}`,
});
try {
const { data: prs } = await context.octokit.rest.pulls.list({
owner,
repo,
state: "open",
head: `${owner}:${headBranch}`,
});
} catch (error) {
context.log.error("Failed to fetch pull requests", error);
return null;
}

Wrap the API call in a try-catch block to handle potential failures gracefully. This ensures the workflow handler doesn't crash and can return null to skip processing when the API is unavailable.

Prompt for AI

Copy this prompt to your AI IDE to fix this issue locally:

In src/events/workflow_run.completed/checklint.ts around line 93, the context.octokit.rest.pulls.list() API call lacks error handling and can cause the entire workflow handler to crash if the GitHub API fails; wrap the API call (lines 93-98) in a try-catch block that logs the error and returns null on failure, ensuring graceful degradation when the API is unavailable.

📍 This suggestion applies to lines 93-98

head: `${owner}:${headBranch}`,
});

const match = prs.find((pr) => pr.head.sha === headSha);

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.

The fallback logic ?? prs[0] is dangerous. If no PR matches the head_sha, it falls back to the first open PR with the same branch name, which could be a completely different PR. This could result in posting workflow comments to the wrong PR, confusing developers and potentially exposing information about one PR in another.

Confidence: 5/5

Suggested Fix
Suggested change
const match = prs.find((pr) => pr.head.sha === headSha);
const match = prs.find((pr) => pr.head.sha === headSha);
return match?.number ?? null;

Remove the ?? prs[0] fallback. If no PR matches the exact SHA, return null to skip processing rather than risk commenting on the wrong PR. This ensures comments are only posted to the correct PR.

Prompt for AI

Copy this prompt to your AI IDE to fix this issue locally:

In src/events/workflow_run.completed/checklint.ts at line 100, the fallback logic `?? prs[0]` can cause comments to be posted to the wrong PR if the SHA doesn't match; remove the `?? prs[0]` fallback and return null when no matching PR is found, ensuring comments are only posted to the correct PR with the matching SHA.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ehh

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.

@calebephrem I encountered an error while generating a response. Please try again.

@calebephrem calebephrem merged commit 003c922 into open-devhub:main Jun 25, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant