当前位置: 首页>>代码示例>>Golang>>正文


Golang github.Branch类代码示例

本文整理汇总了Golang中github.com/jingweno/gh/github.Branch的典型用法代码示例。如果您正苦于以下问题:Golang Branch类的具体用法?Golang Branch怎么用?Golang Branch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Branch类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: branchInURL

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, "/")
}
开发者ID:jingweno,项目名称:gh,代码行数:8,代码来源:browse.go

示例2: browse

/*
  $ 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)
	}
}
开发者ID:jingweno,项目名称:gh,代码行数:73,代码来源:browse.go

示例3: compare

/*
  $ 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)
	}
}
开发者ID:jonmorehouse,项目名称:gh,代码行数:53,代码来源:compare.go


注:本文中的github.com/jingweno/gh/github.Branch类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。