-
Notifications
You must be signed in to change notification settings - Fork 9
Feature/GitHub issues #64
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
Open
Ericode254
wants to merge
16
commits into
SourcewareLab:dev
Choose a base branch
from
Ericode254:feature/githubIssues
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d4eb0ef
feat: add a github issue section where a user can locate the issues o…
Ericode254 9e70e8f
my modules update
Ericode254 10a3547
refactor: remove unnecessary comments
Ericode254 ab0130e
refactor: formatted the code using go format
Ericode254 3b4696e
refactor: make some changes
Ericode254 a3ff1f7
refactor: formatted the github.go file
Ericode254 3bfd8dc
refactor: removed the widgets and themes files
Ericode254 e35897a
refactor: removed unnecessary variables
Ericode254 7220983
refactor: fetch all open issues from all the repos for that user
Ericode254 6c613d5
refactor: fetch also assigned issues
Ericode254 c47ecd1
Merge branch 'dev' into feature/githubIssues
Ericode254 a77ea6b
refactor: formatted the code
Ericode254 0e4ea61
Merge branch 'origin/dev' into feature-branch
Ericode254 03c16fc
refactor: combined the tasks with github issues
Ericode254 2ed6b20
refactor: remove duplicate code
Ericode254 63882b3
refactor: removed the functionality for recurring tasks
Ericode254 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
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,149 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
"syscall" | ||
|
||
"github.com/SourcewareLab/Toney/internal/config" | ||
"github.com/SourcewareLab/Toney/internal/models/github" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"golang.org/x/term" | ||
) | ||
|
||
var githubCmd = &cobra.Command{ | ||
Use: "github", | ||
Short: "GitHub integration commands", | ||
Long: `Manage GitHub integration for syncing issues as structured notes.`, | ||
} | ||
|
||
var githubSetupCmd = &cobra.Command{ | ||
Use: "setup", | ||
Short: "Setup GitHub credentials and configuration", | ||
Long: `Interactive setup for GitHub integration including token, owner, and repository configuration.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := setupGitHub(); err != nil { | ||
fmt.Printf("Error setting up GitHub: %v\n", err) | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
var githubSyncCmd = &cobra.Command{ | ||
Use: "sync", | ||
Short: "Sync GitHub issues to notes", | ||
Long: `Fetch GitHub issues and convert them to structured notes in your notes directory.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := syncGitHubIssues(); err != nil { | ||
fmt.Printf("Error syncing GitHub issues: %v\n", err) | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
var githubStatusCmd = &cobra.Command{ | ||
Use: "status", | ||
Short: "Show GitHub integration status", | ||
Long: `Display current GitHub configuration and connection status.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
showGitHubStatus() | ||
}, | ||
} | ||
|
||
func setupGitHub() error { | ||
fmt.Println("🔧 GitHub Integration Setup") | ||
fmt.Println("===========================") | ||
|
||
if err := config.SetConfig(); err != nil { | ||
return fmt.Errorf("failed to load config: %w", err) | ||
} | ||
|
||
fmt.Print("Enter your GitHub Personal Access Token: ") | ||
tokenBytes, err := term.ReadPassword(int(syscall.Stdin)) | ||
if err != nil { | ||
return fmt.Errorf("failed to read token: %w", err) | ||
} | ||
token := strings.TrimSpace(string(tokenBytes)) | ||
fmt.Println() | ||
|
||
if token == "" { | ||
return fmt.Errorf("GitHub token is required") | ||
} | ||
|
||
viper.Set("github.enabled", true) | ||
viper.Set("github.token", token) | ||
// Clear owner/repo if previously set so we default to all repositories | ||
viper.Set("github.owner", "") | ||
viper.Set("github.repo", "") | ||
|
||
if err := viper.WriteConfig(); err != nil { | ||
return fmt.Errorf("failed to save config: %w", err) | ||
} | ||
|
||
fmt.Printf("✅ GitHub integration configured successfully!\n") | ||
fmt.Printf(" Scope: All repositories accessible by your token\n") | ||
fmt.Printf(" Status: Enabled\n") | ||
fmt.Println("\nYou can now use 'toney github sync' to fetch issues as notes.") | ||
|
||
return nil | ||
} | ||
|
||
func syncGitHubIssues() error { | ||
if err := config.SetConfig(); err != nil { | ||
return fmt.Errorf("failed to load config: %w", err) | ||
} | ||
|
||
if !config.AppConfig.GitHub.Enabled { | ||
return fmt.Errorf("GitHub integration is not enabled. Run 'toney github setup' first") | ||
} | ||
|
||
if config.AppConfig.GitHub.Token == "" { | ||
return fmt.Errorf("GitHub token not configured. Run 'toney github setup' first") | ||
} | ||
|
||
// Sync across all repositories | ||
fmt.Printf("🔄 Syncing issues from all repositories...\n") | ||
|
||
api := github.NewGitHubAPI() | ||
issues, err := api.FetchAllIssuesForUser() | ||
if err != nil { | ||
return fmt.Errorf("failed to fetch issues: %w", err) | ||
} | ||
|
||
fmt.Printf("📥 Found %d issues\n", len(issues)) | ||
|
||
return nil | ||
} | ||
|
||
func showGitHubStatus() { | ||
if err := config.SetConfig(); err != nil { | ||
fmt.Printf("Error loading config: %v\n", err) | ||
return | ||
} | ||
|
||
fmt.Println("📊 GitHub Integration Status") | ||
fmt.Println("============================") | ||
|
||
if config.AppConfig.GitHub.Enabled { | ||
fmt.Println("Status: ✅ Enabled") | ||
fmt.Println("Scope: All repositories") | ||
|
||
if config.AppConfig.GitHub.Token != "" { | ||
fmt.Println("Token: ✅ Configured") | ||
} else { | ||
fmt.Println("Token: ❌ Not configured") | ||
} | ||
} else { | ||
fmt.Println("Status: ❌ Disabled") | ||
fmt.Println("Run 'toney github setup' to enable GitHub integration") | ||
} | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(githubCmd) | ||
githubCmd.AddCommand(githubSetupCmd) | ||
githubCmd.AddCommand(githubSyncCmd) | ||
githubCmd.AddCommand(githubStatusCmd) | ||
} |
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
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
Oops, something went wrong.
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.
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.
removed createRecurring?