feat(gmail): add history types filter to watch serve#168
feat(gmail): add history types filter to watch serve#168salmonumbrella wants to merge 5 commits intosteipete:mainfrom
Conversation
The commit 5137fcb added --history-types flag but changed the default behavior: when not specified, it now fetched ALL history types instead of just messageAdded (the previous hardcoded behavior). This fix ensures backward compatibility by defaulting to messageAdded when --history-types is not provided. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When messageDeleted history type is requested, deleted messages cannot be fetched from Gmail API (returns 404). Now collectHistoryMessageIDs returns a struct with separate FetchIDs and DeletedIDs lists, and the hook payload includes deletedMessageIds field for consumers. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add canonical forms to history type alias map for robustness - Add length assertion for FetchIDs in TestCollectHistoryMessageIDs - Clarify documentation that default is messageAdded - Add test for empty input edge case in parseHistoryTypes - Extract duplicate state update logic into updateStateAfterHistory helper Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Rename inner `err` to `updateErr` to avoid shadowing the outer variable, satisfying golangci-lint's govet shadow checker. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
niemesrw
left a comment
There was a problem hiding this comment.
PR Review: feat(gmail): add history types filter to watch serve
Summary
This PR adds a --history-types flag to gmail watch serve to filter which Gmail history event types are fetched. It addresses issue #165.
What it does
- Adds
--history-typesflag acceptingmessageAdded,messageDeleted,labelAdded,labelRemoved - Defaults to
messageAddedfor backward compatibility (previously hardcoded) - Separates deleted message IDs from fetchable messages to avoid 404 errors
- Adds
deletedMessageIdsfield in webhook payload for consumers tracking deletions
Code Quality
Positives:
- Good backward compatibility by defaulting to
messageAdded - Smart alias handling for history types (case-insensitive, plural forms like
messagesAdded) - Clean extraction of
updateStateAfterHistoryhelper to reduce duplication - Comprehensive test coverage including edge cases (empty input, add-then-delete ordering)
- Documentation updated in
docs/watch.md
Minor observations:
-
gmail_watch_server.go:177-180- The conditionif len(s.cfg.HistoryTypes) > 0is defensive but effectively always true sinceparseHistoryTypes()returns["messageAdded"]by default. Not a bug, just slightly redundant. -
The
collectHistoryMessageIDsfunction uses linear scan for removal (O(n) per deletion) which is fine for typical payload sizes. -
The handling of add-then-delete ordering is correct - if a message is added then later deleted in the same history response, it correctly ends up only in
DeletedIDs.
Test Coverage
TestCollectHistoryMessageIDs- verifies fetch/deleted separationTestCollectHistoryMessageIDs_DeletedRemovesFromFetch- verifies orderingTestCollectHistoryMessageIDs_EmptyResponse- nil/empty edge casesTestParseHistoryTypes*- parsing, defaults, and empty string handlingTestGmailWatchServer_ServeHTTP_HistoryTypes_NoMatch- integration test
Verdict
This is a well-implemented feature. The code is clean, follows existing patterns, has good test coverage, and maintains backward compatibility. Ready to merge.
Summary
--history-typesflag togmail watch servecommand to filter which Gmail history event types are fetchedmessageAddedfor backward compatibility (previously hardcoded)deletedMessageIdsfield in webhook payload for consumers that need to track deletionsCode Review Fixes
updateStateAfterHistoryhelperFixes #165
Test Plan
🤖 Generated with Claude Code