コード例 #1
0
ファイル: utils.go プロジェクト: prsimp/gh
func browserCommand(url string) error {
	launcher, err := utils.BrowserLauncher()
	if err != nil {
		return err
	}

	launcher = append(launcher, url)
	c := cmd.NewWithArray(launcher)
	return c.Exec()
}
コード例 #2
0
ファイル: browse.go プロジェクト: jingweno/gh
/*
  $ gh browse
  > open https://github.com/YOUR_USER/CURRENT_REPO

  $ gh browse commit/SHA
  > open https://github.com/YOUR_USER/CURRENT_REPO/commit/SHA

  $ gh browse issues
  > open https://github.com/YOUR_USER/CURRENT_REPO/issues

  $ gh browse -p jingweno/gh
  > open https://github.com/jingweno/gh

  $ gh browse -p jingweno/gh commit/SHA
  > open https://github.com/jingweno/gh/commit/SHA

  $ gh browse -p resque
  > open https://github.com/YOUR_USER/resque

  $ gh browse -p resque network
  > open https://github.com/YOUR_USER/resque/network
*/
func browse(command *Command, args *Args) {
	var (
		project *github.Project
		branch  *github.Branch
		err     error
	)
	localRepo := github.LocalRepo()
	if flagBrowseProject != "" {
		// gh browse -p jingweno/gh
		// gh browse -p gh
		project = github.NewProject("", flagBrowseProject, "")
	} else {
		// gh browse
		branch, project, err = localRepo.RemoteBranchAndProject("")
		utils.Check(err)
	}

	if project == nil {
		err := fmt.Errorf(command.FormattedUsage())
		utils.Check(err)
	}

	master := localRepo.MasterBranch()
	if branch == nil {
		branch = master
	}

	var subpage string
	if !args.IsParamsEmpty() {
		subpage = args.RemoveParam(0)
	}

	if subpage == "commits" {
		subpage = fmt.Sprintf("commits/%s", branchInURL(branch))
	} else if subpage == "tree" || subpage == "" {
		if !reflect.DeepEqual(branch, master) && branch.IsRemote() {
			subpage = fmt.Sprintf("tree/%s", branchInURL(branch))
		}
	}

	pageUrl := project.WebURL("", "", subpage)
	launcher, err := utils.BrowserLauncher()
	utils.Check(err)

	if flagBrowseURLOnly {
		args.Replace("echo", pageUrl)
	} else {
		args.Replace(launcher[0], "", launcher[1:]...)
		args.AppendParams(pageUrl)
	}
}
コード例 #3
0
ファイル: compare.go プロジェクト: jonmorehouse/gh
/*
  $ 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)
	}
}
コード例 #4
0
ファイル: browse.go プロジェクト: johnbellone/gh
/*
  $ gh browse
  > open https://github.com/YOUR_USER/CURRENT_REPO

  $ gh browse commit/SHA
  > open https://github.com/YOUR_USER/CURRENT_REPO/commit/SHA

  $ gh browse issues
  > open https://github.com/YOUR_USER/CURRENT_REPO/issues

  $ gh browse -u jingweno -r gh
  > open https://github.com/jingweno/gh

  $ gh browse -u jingweno -r gh commit/SHA
  > open https://github.com/jingweno/gh/commit/SHA

  $ gh browse -r resque
  > open https://github.com/YOUR_USER/resque

  $ gh browse -r resque network
  > open https://github.com/YOUR_USER/resque/network
*/
func browse(command *Command, args *Args) {
	subpage := "tree"
	if !args.IsParamsEmpty() {
		subpage = args.RemoveParam(0)
	}

	project := github.CurrentProject()
	if subpage == "tree" || subpage == "commits" {
		repo := project.LocalRepo()
		subpage = utils.ConcatPaths(subpage, repo.Head)
	}

	url := project.WebURL(flagBrowseRepo, flagBrowseUser, subpage)
	launcher, err := utils.BrowserLauncher()
	if err != nil {
		utils.Check(err)
	}

	args.Replace(launcher[0], "", launcher[1:]...)
	args.AppendParams(url)
}
コード例 #5
0
ファイル: compare.go プロジェクト: johnvilsack/golang-stuff
/*
  $ 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) {
	project := github.CurrentProject()

	var r string
	if args.IsParamsEmpty() {
		repo := project.LocalRepo()
		r = repo.Head
	} else {
		r = args.FirstParam()
	}

	r = transformToTripleDots(r)
	subpage := utils.ConcatPaths("compare", r)
	url := project.WebURL("", flagCompareUser, subpage)
	launcher, err := utils.BrowserLauncher()
	if err != nil {
		utils.Check(err)
	}

	args.Replace(launcher[0], "", launcher[1:]...)
	args.AppendParams(url)
}