-
Notifications
You must be signed in to change notification settings - Fork 3
Add gi view command to open issues in default program #17
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,11 +29,8 @@ go.work.sum | |
| # env file | ||
| .env | ||
|
|
||
| # Editor/IDE | ||
| # .idea/ | ||
| # .vscode/ | ||
|
|
||
| # Editor/IDE | ||
| .claude/ | ||
|
|
||
| test/ | ||
| .DS_Store | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 21 | ||
| 22 |
33 changes: 33 additions & 0 deletions
33
.issues/closed/021-add-open-file-command-to-open-issue-markdown-in-de.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| --- | ||
| id: "021" | ||
| assignee: "" | ||
| labels: | ||
| - feature | ||
| created: 2026-02-06T14:27:24.912527+09:00 | ||
| updated: 2026-02-06T14:40:03.891202+09:00 | ||
| --- | ||
|
|
||
| # Add view command to open issue markdown in default program | ||
|
|
||
| ## Description | ||
|
|
||
| Add a new `gi view` command that opens an issue's markdown file using the system's default program associated with the `.md` extension. This allows users to quickly view or edit issues in their preferred markdown editor or viewer (e.g., Typora, VS Code, Obsidian). | ||
|
|
||
| Usage: `gi view 001` | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Accept an issue ID as argument (e.g., `gi view 001`) | ||
| - Look up the issue file in `.issues/open/` and `.issues/closed/` | ||
| - Open the file using the OS default program for `.md` files: | ||
| - macOS: use `open` command | ||
| - Linux: use `xdg-open` command | ||
| - Show an error if the issue ID is not found | ||
|
|
||
| ## Success Criteria | ||
|
|
||
| - [ ] `gi view <id>` opens the issue markdown in the default associated program | ||
| - [ ] Works on macOS (`open`) and Linux (`xdg-open`) | ||
| - [ ] Displays clear error when issue ID does not exist | ||
| - [ ] Unit tests for file lookup logic | ||
| - [ ] Update README file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os/exec" | ||
| "runtime" | ||
|
|
||
| "github.com/Allra-Fintech/git-issue/pkg" | ||
| "github.com/fatih/color" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var viewCmd = &cobra.Command{ | ||
| Use: "view <issue-id>", | ||
| Short: "Open an issue in the default program", | ||
| Long: `Open an issue's markdown file in the system's default program (e.g., Typora, VS Code, Obsidian).`, | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: runView, | ||
| } | ||
|
|
||
| func init() { | ||
| rootCmd.AddCommand(viewCmd) | ||
| } | ||
|
|
||
| func runView(cmd *cobra.Command, args []string) error { | ||
| issueID := args[0] | ||
|
|
||
| // Find the issue file | ||
| path, _, err := pkg.FindIssueFile(issueID) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to find issue: %w", err) | ||
| } | ||
|
|
||
| // Determine the OS-appropriate open command | ||
| var opener string | ||
| switch runtime.GOOS { | ||
| case "darwin": | ||
| opener = "open" | ||
| case "linux": | ||
| opener = "xdg-open" | ||
| default: | ||
| return fmt.Errorf("unsupported platform: %s", runtime.GOOS) | ||
| } | ||
|
|
||
| // Open the file in the default program (non-blocking) | ||
| if err := exec.Command(opener, path).Start(); err != nil { | ||
| return fmt.Errorf("failed to open file: %w", err) | ||
| } | ||
|
|
||
| color.New(color.FgGreen).Printf("✓ Opened issue #%s in default program\n", issueID) | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestViewMissingArgs(t *testing.T) { | ||
| cmd := viewCmd | ||
| err := cmd.Args(cmd, []string{}) | ||
| if err == nil { | ||
| t.Error("expected error for missing arguments") | ||
| } | ||
| } | ||
|
|
||
| func TestViewNonExistentIssue(t *testing.T) { | ||
| // runView should fail when the issue doesn't exist | ||
| err := runView(viewCmd, []string{"999"}) | ||
| if err == nil { | ||
| t.Error("expected error for non-existent issue") | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.