Skip to content

Conversation

@devin-ai-integration
Copy link

Summary

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

  1. String Literal Duplication (go:S1192): Fixed duplicate string literal "failed to get GitHub client: %w" that appeared 12 times across the file
  2. Cognitive Complexity (go:S3776): Reduced cognitive complexity of the ListCommits function from 23 to below the threshold by extracting handler logic

Changes

String Duplication Fix

  • Added constant errFailedToGetGitHubClient at package level
  • Replaced all 12 occurrences of the duplicated error message string with the constant
  • Affects functions: GetCommit, ListCommits, ListBranches, CreateOrUpdateFile, CreateRepository, GetFileContents, ForkRepository, DeleteFile, CreateBranch, PushFiles, ListTags, GetTag

Cognitive Complexity Fix

  • Extracted anonymous handler function from ListCommits into standalone listCommitsHandler helper function
  • ListCommits now delegates to listCommitsHandler, reducing nesting and complexity
  • No functional changes - behavior is identical

Testing

  • ✅ All existing unit tests pass
  • ✅ Linter passes with 0 issues

Review Checklist

  • Verify all 12 string literal replacements are correct and no occurrences were missed
  • Confirm listCommitsHandler maintains exact same behavior as original inline handler
  • Check if handler extraction pattern is consistent with codebase conventions
  • Consider if similar refactoring should be applied to other high-complexity functions for consistency

Notes

  • This addresses 1 issue from each SonarQube category as requested
  • Many other similar issues remain in the codebase that could benefit from the same treatment
  • SonarQube scan should be re-run to confirm these specific issues are resolved

Link to Devin run: https://app.devin.ai/sessions/7404ee489c2448e0a734739b9c018809
Requested by: Shawn Azman (shawn@cognition.ai) / @ShawnAzman

…complexity

- Added constant errFailedToGetGitHubClient to eliminate string literal duplication (go:S1192)
- Refactored ListCommits function by extracting handler logic to reduce cognitive complexity (go:S3776)
- All tests and linter checks pass
@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

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