diff --git a/commands/commands.go b/commands/commands.go index 3c8412f3..8aca1566 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -41,6 +41,7 @@ func (c *Command) List() bool { var All = []*Command{ cmdPull, + cmdFork, cmdCi, cmdBrowse, cmdCompare, diff --git a/commands/fork.go b/commands/fork.go new file mode 100644 index 00000000..6669741d --- /dev/null +++ b/commands/fork.go @@ -0,0 +1,29 @@ +package commands + +import ( + "github.com/jingweno/gh/github" +) + +var cmdFork = &Command{ + Run: fork, + Usage: "fork [--no-remote]", + Short: "Make a fork of a remote repository on GitHub and add as remote", + Long: `Forks the original project (referenced by "origin" remote) on GitHub and +adds a new remote for it under your username. +`, +} + +var flagForkNoRemote bool + +func init() { + cmdFork.Flag.BoolVar(&flagForkNoRemote, "no-remote", false, "") +} + +func fork(cmd *Command, args []string) { + gh := github.New() + project := gh.Project + + err := gh.ForkRepository(project.Name, project.Owner) + + +} diff --git a/github/github.go b/github/github.go index eeacda1f..b72e8c08 100644 --- a/github/github.go +++ b/github/github.go @@ -51,6 +51,17 @@ func (gh *GitHub) CiStatus(sha string) (*octokat.Status, error) { } } +func (gh *GitHub) ForkRepository(name, owner string) error { + client := gh.client() + _, err := client.Repository(octokat.Repo{name, owner}) + + if err != nil { + return err + } + + return nil +} + func (gh *GitHub) repo() octokat.Repo { project := gh.Project return octokat.Repo{project.Name, project.Owner}