-
Couldn't load subscription status.
- Fork 10
Add context attribute to link TODOs with GitHub issues
#107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This PR introduces an optional `context` attribute for TODO comments that allows linking them to GitHub issues using the `issue()` function. This provides better traceability between code `TODO`s and their corresponding GitHub issues.
## Key Features
- **New `context` attribute**: Can be added to any `TODO` with an event trigger
- **`issue()` function**: Takes 3 parameters (org, repo, issue_number)
- **Rich context information**: When a `TODO` is triggered, the linked issue's title, state, and assignee are included in the notification
- **Works with all events**: Compatible with `date`, `gem_release`, `gem_bump`, and `ruby_version` events (not with `issue_close`/`pull_request_close` as they already reference issues/PRs)
## Example Usage
```ruby
# TODO(on: date('2025-02-01'), to: '[email protected]', context: issue('shopify', 'smart_todo', '108'))
# Implement the caching strategy discussed in the issue
```
## Implementation Details
- Context validation follows the same pattern as existing event validations
- The smart_todo_cop validates context syntax and arguments
- Context information is fetched only when the `TODO` event is triggered
- If the issue cannot be fetched, the `TODO` notification is still sent without context
Closes #108
🤖 Generated with Claude Code
issue_pin event to link TODOs with GitHub issuescontext attribute to link TODOs with GitHub issues
…nsidered valid with `issue_close` and `pull_request_close`
236b2b0 to
39ccf2b
Compare
lib/smart_todo_cop.rb
Outdated
| restricted_events = events.select { |e| [:issue_close, :pull_request_close].include?(e.method_name) } | ||
| if restricted_events.any? | ||
| return "Invalid context: context attribute cannot be used with #{restricted_events.first.method_name} event" | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract to a method called invalid_events_for_context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I built this utility as SmartTodo::Todo.event_can_use_context? in 2090a29 so it can be used from different modules without copy-pasta.
Let me know what you think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a great addition, but I have the feeling that this may try to over-engineer a solution. It also makes a todo definition very verbose and it becomes hard to read when looking at the TODO definition.
I wonder if a more simpler approach à la GitHub would be easier.
# TODO(on...)
# Part of the bigger cleanup
# Ref Shopify/super_repo#34When SmartTodo detects the Ref ... part, it would transfom it to a link to be sent along the slack message
Co-authored-by: Rafael Mendonça França <[email protected]>
At the same time, I refactored to avoid code duplication and added tests Ref: #107 (comment)
Thanks for the feedback ! Using Given I believe it's better to build What do you think ? |
|
I understand that building a structured context makes it easier for us to parse. But it comes with the downside of making it harder for humans to write and read. Writing a smart todo is already not the most user friendly (especially since its just a comment without any syntax highlighting), and I'm worried that adding a new programming syntax info to the TODO will clutter it even more. Ultimately a TODO should be written to be read by humans not machines which is why I suggested the standard I wouldn't want to dismiss the great work you already put in this PR and since Rafael is also ok with this approach I'll defer to his approval. At the very minimum if we go with the structured context, please consider |
|
I actually really like |
This PR introduces an optional
contextattribute forTODOcomments that allows linking them to GitHub issues using theissue()function. This provides better traceability between codeTODOs and their corresponding GitHub issues.Key Features
contextattribute: Can be added to anyTODOwith an event triggerissue()function: Takes 3 parameters (org, repo, issue_number)TODOis triggered, the linked issue's title, state, and assignee are included in the notificationdate,gem_release,gem_bump, andruby_versionevents (not withissue_close/pull_request_closeas they already reference issues/PRs)Example Usage
Implementation Details
TODOevent is triggeredTODOnotification is still sent without contextCloses #108
🤖 Generated with Claude Code