Add GitHub file links with line numbers to Slack messages #114
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
human tldr: I wanted line numbers in our slack messages. This adds it.
Potentially this also adds github links, but I saw the comment here and it's possible that this won't work- tests seem to be fine but I'd like somebody who understands the issue better to weigh in on this code
The rest is summarised by Claude, seems good and i babysat him for this, read all code with my own human eyeballs etc.
Summary
This PR enhances Slack notifications to include clickable GitHub links with line numbers, making TODO notifications more actionable.
Fixes #66
Changes:
GitUtilsmodule to detect GitHub repositories and generate file linkshttps://github.com/Shopify/smart_todo/blob/main/file.rb#L42)Examples
With GitHub repository:
Creates a clickable link in Slack that navigates directly to the line in GitHub
Without GitHub repository:
Falls back to human-readable line reference
Key Technical Improvement
Git Repository Detection Fix
The PR includes an important fix for how git repositories are detected. Previously, the code would use
Dir.pwd(the current working directory) to look for.git, which could fail when:Solution: The new
find_git_rootmethod walks up the directory tree from the actual file being processed to find the.gitdirectory. This ensures correct behavior regardless of where the command is run from.This addresses the concern raised in #94 (comment) about
base_pathpotentially being incorrect.Test Coverage
Updated Tests
OutputTest#test_dispatch_with_github_link- Verifies GitHub links in git reposOutputTest#test_dispatch_without_github_link- Verifies readable fallback formatNew Tests (GitUtilsTest)
find_git_rootwalking up directory tree from files/subdirectoriesAll tests passing: 192 runs, 442 assertions, 0 failures
Performance
The implementation includes caching for git repository information:
git_root_cache- Caches git root lookups per directorygit_info_cache- Caches GitHub repository infoThis ensures efficient operation even when processing hundreds of files, as each directory is only scanned once.
🤖 Generated with Claude Code