Пример #1
0
func browse(command *Command, args []string) {
	subpage := "tree"
	if len(args) > 0 {
		subpage = args[0]
	}

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

	url := project.WebURL(flagBrowseRepo, flagBrowseUser, subpage)
	err := browserCommand(url)
	utils.Check(err)
}
Пример #2
0
func compare(command *Command, args []string) {
	project := github.CurrentProject()

	var r string
	if len(args) == 0 {
		repo := project.LocalRepo()
		r = repo.Head
	} else {
		r = args[0]
	}

	r = transformToTripleDots(r)
	subpage := utils.ConcatPaths("compare", r)
	url := project.WebURL("", flagCompareUser, subpage)
	err := browserCommand(url)
	utils.Check(err)
}
Пример #3
0
/*
  $ 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)
}
Пример #4
0
/*
  $ 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)
}
Пример #5
0
func parseCherryPickProjectAndSha(ref string) (project *github.Project, sha string) {
	url, err := github.ParseURL(ref)
	if err == nil {
		commitRegex := regexp.MustCompile("^commit\\/([a-f0-9]{7,40})")
		projectPath := url.ProjectPath()
		if commitRegex.MatchString(projectPath) {
			sha = commitRegex.FindStringSubmatch(projectPath)[1]
			project = &url.Project

			return
		}
	}

	ownerWithShaRegexp := regexp.MustCompile("^(%s)@([a-f0-9]{7,40})$")
	if ownerWithShaRegexp.MatchString(ref) {
		matches := ownerWithShaRegexp.FindStringSubmatch(ref)
		sha = matches[2]
		project = github.CurrentProject()
		project.Owner = matches[1]
	}

	return
}