-
Notifications
You must be signed in to change notification settings - Fork 16
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
integrate github with tran
#9
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4307434
get the tran gh api, add `auth` and `gh-config` commands
david-tomson 852e06f
bump `abdfnx/gh` version, add `gh-repo` command to `tran`
david-tomson 19949cf
finally, add `tran sync` command to tran, add new go modules
david-tomson 89f28c2
update `tran` root command examples
abdfnx 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 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,3 +1,5 @@ | ||
tasks: | ||
- init: go get -d ./... | ||
command: curl -fsSL https://cutt.ly/tran-cli | bash | ||
command: | | ||
brew install go-task/tap/go-task | ||
curl -fsSL https://cutt.ly/tran-cli | bash |
This file contains 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 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,59 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/abdfnx/gh/pkg/cmdutil" | ||
aCmd "github.com/abdfnx/gh/pkg/cmd/auth" | ||
cCmd "github.com/abdfnx/gh/pkg/cmd/gh-config" | ||
rCmd "github.com/abdfnx/gh/pkg/cmd/gh-repo" | ||
"github.com/abdfnx/gh/context" | ||
"github.com/abdfnx/gh/api" | ||
"github.com/abdfnx/gh/core/ghrepo" | ||
) | ||
|
||
func Auth(f *cmdutil.Factory) *cobra.Command { | ||
cmd := aCmd.NewCmdAuth(f) | ||
return cmd | ||
} | ||
|
||
func GHConfig(f *cmdutil.Factory) *cobra.Command { | ||
cmd := cCmd.NewCmdConfig(f) | ||
return cmd | ||
} | ||
|
||
func Repo(f *cmdutil.Factory) *cobra.Command { | ||
repoResolvingCmdFactory := *f | ||
repoResolvingCmdFactory.BaseRepo = resolvedBaseRepo(f) | ||
|
||
cmd := rCmd.NewCmdRepo(&repoResolvingCmdFactory) | ||
|
||
return cmd | ||
} | ||
|
||
func resolvedBaseRepo(f *cmdutil.Factory) func() (ghrepo.Interface, error) { | ||
return func() (ghrepo.Interface, error) { | ||
httpClient, err := f.HttpClient() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
apiClient := api.NewClientFromHTTP(httpClient) | ||
|
||
remotes, err := f.Remotes() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
repoContext, err := context.ResolveRemotesToRepos(remotes, apiClient, "") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
baseRepo, err := repoContext.BaseRepo(f.IOStreams) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return baseRepo, nil | ||
} | ||
} |
This file contains 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,182 @@ | ||
package app | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
"runtime" | ||
|
||
"github.com/abdfnx/gosh" | ||
"github.com/spf13/cobra" | ||
"github.com/abdfnx/gh/utils" | ||
"github.com/briandowns/spinner" | ||
"github.com/MakeNowJust/heredoc" | ||
"github.com/abdfnx/tran/constants" | ||
git_config "github.com/david-tomson/tran-git" | ||
) | ||
|
||
var username = git_config.GitConfig() | ||
|
||
var ( | ||
NewCmdStart = &cobra.Command{ | ||
Use: "start", | ||
Aliases: []string{"."}, | ||
Example: "tran sync start", | ||
Short: "Start sync your tran config.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if username != ":username" { | ||
exCmd := constants.StartEX() | ||
|
||
gosh.RunMulti(constants.Start_ml(), constants.Start_w()) | ||
gosh.Run(exCmd) | ||
} else { | ||
utils.AuthMessage() | ||
} | ||
}, | ||
} | ||
|
||
NewCmdClone = &cobra.Command{ | ||
Use: "clone", | ||
Aliases: []string{"cn"}, | ||
Short: CloneHelp(), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if username != ":username" { | ||
cloneCmd := constants.Clone() | ||
|
||
gosh.Run(cloneCmd) | ||
gosh.RunMulti(constants.Clone_check_ml(), constants.Clone_check_w()) | ||
} else { | ||
utils.AuthMessage() | ||
} | ||
}, | ||
} | ||
|
||
NewCmdPush = &cobra.Command{ | ||
Use: "push", | ||
Aliases: []string{"ph"}, | ||
Short: "Push the new changes in tran config file.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if username != ":username" { | ||
gosh.RunMulti(constants.Push_ml(), constants.Push_w()) | ||
} else { | ||
utils.AuthMessage() | ||
} | ||
}, | ||
} | ||
|
||
NewCmdPull = &cobra.Command{ | ||
Use: "pull", | ||
Aliases: []string{"pl"}, | ||
Short: PullHelp(), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if username != ":username" { | ||
gosh.RunMulti(constants.Pull_ml(), constants.Pull_w()) | ||
} else { | ||
utils.AuthMessage() | ||
} | ||
}, | ||
} | ||
|
||
FetchClone = &cobra.Command{ | ||
Use: "fetchx", | ||
Short: "Special command for windows", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if username != ":username" { | ||
if runtime.GOOS == "windows" { | ||
gosh.PowershellCommand(constants.Clone()) | ||
} else { | ||
fmt.Println("This command isn't avaliable for this platform") | ||
} | ||
} else { | ||
utils.AuthMessage() | ||
} | ||
}, | ||
} | ||
) | ||
|
||
func Sync() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "sync <command>", | ||
Short: "Sync your tran config file.", | ||
Long: SyncHelp(), | ||
Example: heredoc.Doc(` | ||
tran sync start | ||
tran sync clone | ||
`), | ||
} | ||
|
||
cmd.AddCommand(NewCmdStart) | ||
cmd.AddCommand(NewCmdClone) | ||
cmd.AddCommand(NewCmdPush) | ||
cmd.AddCommand(NewCmdPull) | ||
cmd.AddCommand(FetchClone) | ||
|
||
return cmd | ||
} | ||
|
||
const tranConfigPath string = "/.tran" | ||
|
||
func PullHelp() string { | ||
return git_config.GitConfigWithMsg("Pull the new changes from ", tranConfigPath) | ||
} | ||
|
||
func SyncHelp() string { | ||
return git_config.GitConfigWithMsg("Sync your config file, by create a private repo at ", tranConfigPath) | ||
} | ||
|
||
func CloneHelp() string { | ||
return git_config.GitConfigWithMsg("Clone your .tran from your private repo at https://github.com/", tranConfigPath) | ||
} | ||
|
||
func PushSync() { | ||
const Syncing string = " 📮 Syncing..." | ||
|
||
if runtime.GOOS == "windows" { | ||
err, out, errout := gosh.PowershellOutput( | ||
` | ||
$directoyPath = "~/.config/tran/.git" | ||
|
||
if (Test-Path -path $directoyPath) { | ||
Write-Host "Reading from .tran folder..." | ||
} | ||
`) | ||
|
||
fmt.Print(out) | ||
|
||
if err != nil { | ||
log.Printf("error: %v\n", err) | ||
fmt.Print(errout) | ||
} else if out != "" { | ||
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) | ||
s.Suffix = Syncing | ||
s.Start() | ||
|
||
gosh.PowershellCommand(constants.Push_w()) | ||
|
||
s.Stop() | ||
} | ||
} else { | ||
err, out, errout := gosh.ShellOutput( | ||
` | ||
if [ -d ~/.config/tran/.git ]; then | ||
echo "📖 Reading from .tran folder..." | ||
fi | ||
`) | ||
|
||
fmt.Print(out) | ||
|
||
if err != nil { | ||
log.Printf("error: %v\n", err) | ||
fmt.Print(errout) | ||
} else if out != "" { | ||
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) | ||
s.Suffix = Syncing | ||
s.Start() | ||
|
||
gosh.ShellCommand(constants.Push_ml()) | ||
|
||
s.Stop() | ||
} | ||
} | ||
} | ||
|
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.
👍