Skip to content

Conversation

@devin-ai-integration
Copy link

Summary

This PR addresses two High severity SonarQube issues in pkg/github/actions.go:

  1. String Literal Duplication (go:S1192): Eliminated duplicated error message strings by defining constants
  2. Cognitive Complexity (go:S3776): Reduced complexity of ListWorkflowRuns handler function by extracting parameter validation logic

Changes

1. String Literal Constants

  • Added ErrFailedToGetGitHubClient constant (replaced 14 occurrences)
  • Added ErrFailedToMarshalResponse constant (replaced 15 occurrences)

2. Cognitive Complexity Reduction

  • Created workflowRunParams struct to hold workflow run parameters
  • Extracted extractWorkflowRunParams() helper function to validate and extract all parameters
  • Refactored ListWorkflowRuns handler to use the helper, reducing from ~70 lines to ~35 lines

Testing

  • ✅ All tests pass (./script/test)
  • ✅ Linter passes with 0 issues (./script/lint)

Review Checklist

  • Verify parameter extraction logic maintains identical behavior (especially error handling)
  • Confirm error messages returned to users are unchanged
  • Check that struct field mapping to github.ListWorkflowRunsOptions is correct
  • Validate no hardcoded error strings remain (search for raw strings in file)

Tradeoffs

  • The extractWorkflowRunParams helper is currently single-use. This is acceptable for reducing cognitive complexity, but if similar parameter patterns emerge in other functions, consider a more general solution.

Link to Devin run: https://app.devin.ai/sessions/1923ed29469a4f47abb0e0d148237467
Requested by: Shawn Azman (@ShawnAzman)

- Define constants for duplicated string literals 'failed to get GitHub client: %w' and 'failed to marshal response: %w'
- Reduce cognitive complexity of ListWorkflowRuns function by extracting parameter validation into helper function
- All tests and linter pass successfully
@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
12.4% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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