func branchInURL(branch *github.Branch) string { parts := strings.Split(branch.ShortName(), "/") newPath := make([]string, len(parts)) for i, s := range parts { newPath[i] = url.QueryEscape(s) } return strings.Join(newPath, "/") }
/* $ gh compare refactor > open https://github.com/CURRENT_REPO/compare/refactor $ gh compare 1.0..1.1 > open https://github.com/CURRENT_REPO/compare/1.0...1.1 $ gh compare -u other-user patch > open https://github.com/other-user/REPO/compare/patch */ func compare(command *Command, args *Args) { localRepo := github.LocalRepo() var ( branch *github.Branch project *github.Project r string err error ) branch, project, err = localRepo.RemoteBranchAndProject("") utils.Check(err) if args.IsParamsEmpty() { master := localRepo.MasterBranch() if master.ShortName() == branch.ShortName() { err = fmt.Errorf(command.FormattedUsage()) utils.Check(err) } else { r = branch.ShortName() } } else { r = parseCompareRange(args.RemoveParam(args.ParamsSize() - 1)) if args.IsParamsEmpty() { project, err = localRepo.CurrentProject() utils.Check(err) } else { project = github.NewProject(args.RemoveParam(args.ParamsSize()-1), "", "") } } r = strings.Replace(r, "/", ";", -1) subpage := utils.ConcatPaths("compare", r) url := project.WebURL("", "", subpage) launcher, err := utils.BrowserLauncher() utils.Check(err) if flagCompareURLOnly { args.Replace("echo", url) } else { args.Replace(launcher[0], "", launcher[1:]...) args.AppendParams(url) } }