### ParseDiff Function (Go) Source: https://context7.com/suree33/gh-pr-todo/llms.txt The `ParseDiff` function from the `internal` package parses unified diff output and extracts TODO-style comments from newly added lines (lines starting with `+`). It returns a slice of structs, each containing the filename, line number, comment text, and type of the TODO comment. It ignores deleted and unchanged lines. ```go package main import ( "fmt" "github.com/Suree33/gh-pr-todo/internal" ) func main() { // Sample unified diff output diffOutput := `diff --git a/main.go b/main.go index 1234567..abcdefg 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,6 @@ package main +// TODO: Add error handling +// FIXME: Memory leak in connection pool +# NOTE: Requires Go 1.21+ func main() {}` todos := internal.ParseDiff(diffOutput) for _, todo := range todos { fmt.Printf("File: %s, Line: %d, Type: %s\n", todo.Filename, todo.Line, todo.Type) fmt.Printf("Comment: %s\n\n", todo.Comment) } // Output: // File: main.go, Line: 3, Type: TODO // Comment: // TODO: Add error handling // // File: main.go, Line: 4, Type: FIXME // Comment: // FIXME: Memory leak in connection pool // // File: main.go, Line: 5, Type: NOTE // Comment: # NOTE: Requires Go 1.21+ } ``` -------------------------------- ### Comment Style Detection (Regex) Source: https://context7.com/suree33/gh-pr-todo/llms.txt Demonstrates the regex pattern used to detect various TODO-style comments across multiple programming languages. It supports case-insensitive matching and works with or without a colon after the keyword. ```regex // Supported comment formats and their regex pattern: // Pattern: (?i)((?://|#| // Assembly/INI style ; BUG: Known issue with negative values // Supported keywords (case-insensitive): // - TODO : Tasks to be completed // - FIXME : Bugs or issues to fix // - HACK : Temporary workarounds // - NOTE : Important information // - XXX : Dangerous or problematic code // - BUG : Known bugs ``` -------------------------------- ### List Filenames with TODOs (Bash) Source: https://context7.com/suree33/gh-pr-todo/llms.txt Lists only the filenames that contain TODO-style comments, without displaying the actual comment content. This mode is helpful for quickly identifying which files require attention. Each filename is printed on a new line. ```bash # Show only filenames with TODOs gh pr-todo --name-only # Output: # src/api/users.go # components/Header.tsx # docs/setup.md ``` -------------------------------- ### Group TODO Comments by File or Type (Bash) Source: https://context7.com/suree33/gh-pr-todo/llms.txt Groups TODO comments either by the file they appear in or by their comment type (e.g., TODO, FIXME). This provides better organization when reviewing a large number of comments. The output format changes based on the grouping option. ```bash # Group by file gh pr-todo --group-by file # Output: # * src/api/users.go # 42: // TODO: Add input validation for email format # 58: // FIXME: Handle timeout errors # # * components/Header.tsx # 15: // FIXME: Memory leak in event listener cleanup # Group by type gh pr-todo --group-by type # Output: # [FIXME] # * src/api/users.go:58 # // FIXME: Handle timeout errors # # * components/Header.tsx:15 # // FIXME: Memory leak in event listener cleanup # # [TODO] # * src/api/users.go:42 # // TODO: Add input validation for email format ``` -------------------------------- ### Specify PR for TODO Extraction (Bash) Source: https://context7.com/suree33/gh-pr-todo/llms.txt Allows targeting a specific pull request for TODO comment extraction using its number, full URL, or branch name. This is useful for reviewing TODOs in PRs not currently checked out. The `-R owner/repo` flag can be used to specify a different repository. ```bash # Specify PR by number gh pr-todo 123 # Specify PR by URL gh pr-todo https://github.com/owner/repo/pull/789 # Specify PR by branch name gh pr-todo feature-branch # Specify PR from a different repository gh pr-todo 456 -R owner/repo # Specify a different repository for current branch gh pr-todo -R owner/repo ``` -------------------------------- ### Basic PR TODO Extraction (Bash) Source: https://context7.com/suree33/gh-pr-todo/llms.txt Extracts all TODO-style comments from the current branch's pull request using the `gh pr-todo` command. It outputs formatted results including file locations and line numbers. This command requires an active git repository with an open PR. ```bash # Basic usage - extract TODOs from current branch's PR gh pr-todo # Output: # ✔ Fetching PR diff... # # Found 3 TODO comment(s) # # * src/api/users.go:42 # // TODO: Add input validation for email format # # * components/Header.tsx:15 # // FIXME: Memory leak in event listener cleanup # # * docs/setup.md:8 # ``` -------------------------------- ### GroupBy Type Definition and Usage (Go) Source: https://context7.com/suree33/gh-pr-todo/llms.txt Implements an enum type for grouping TODO comments, satisfying the pflag.Value interface for command-line flag parsing. It supports 'file' and 'type' as valid grouping values and handles invalid input gracefully. ```go package main import ( "fmt" "github.com/Suree33/gh-pr-todo/pkg/types" ) func main() { var groupBy types.GroupBy // Set from string (as done by CLI flag parsing) err := groupBy.Set("file") if err != nil { fmt.Println("Error:", err) return } // Use in switch for conditional logic switch groupBy { case types.GroupByFile: fmt.Println("Grouping by file") case types.GroupByType: fmt.Println("Grouping by comment type") case types.GroupByNone: fmt.Println("No grouping") } // Invalid value handling err = groupBy.Set("invalid") fmt.Println(err) // Output: invalid value "invalid" for --group-by (allowed: "file", "type") } ``` -------------------------------- ### TODO Type Definition and Usage (Go) Source: https://context7.com/suree33/gh-pr-todo/llms.txt Defines the TODO struct to represent a TODO comment found in code diffs, including its location and metadata. It's used as the return type from the ParseDiff function and can be serialized to JSON for API responses or logging. ```go package main import ( "encoding/json" "fmt" "github.com/Suree33/gh-pr-todo/pkg/types" ) func main() { // TODO struct fields todo := types.TODO{ Filename: "src/handlers/auth.go", Line: 42, Comment: "// TODO: Implement OAuth2 flow", Type: "TODO", } // Serialize for API responses or logging data, _ := json.MarshalIndent(todo, "", " ") fmt.Println(string(data)) // Output: // { // "Filename": "src/handlers/auth.go", // "Line": 42, // "Comment": "// TODO: Implement OAuth2 flow", // "Type": "TODO" // } } ``` -------------------------------- ### Count TODO Comments (Bash) Source: https://context7.com/suree33/gh-pr-todo/llms.txt Returns only the count of TODO comments found in a pull request. This mode is useful for scripting and CI/CD pipelines to check for the existence of TODOs. The output is a single integer representing the total count. ```bash # Get count of TODO comments gh pr-todo -c # Output: 3 # Use in CI scripts if [ "$(gh pr-todo -c)" -gt 0 ]; then echo "Warning: PR contains TODO comments" fi ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.