Esempio n. 1
0
func (p *Project) WebURL(name, owner, path string) string {
	if owner == "" {
		owner = p.Owner
	}
	if name == "" {
		name = p.Name
	}

	ownerWithName := fmt.Sprintf("%s/%s", owner, name)
	if strings.Contains(ownerWithName, ".wiki") {
		ownerWithName = strings.TrimSuffix(ownerWithName, ".wiki")
		if path != "wiki" {
			if strings.HasPrefix(path, "commits") {
				path = "_history"
			} else if path != "" {
				path = fmt.Sprintf("_%s", path)
			}

			if path != "" {
				path = utils.ConcatPaths("wiki", path)
			} else {
				path = "wiki"
			}
		}
	}

	url := fmt.Sprintf("https://%s", utils.ConcatPaths(p.Host, ownerWithName))
	if path != "" {
		url = utils.ConcatPaths(url, path)
	}

	return url
}
Esempio n. 2
0
func (p *Project) WebURL(name, owner, path string) string {
	if owner == "" {
		owner = p.Owner
	}
	if name == "" {
		name = p.Name
	}

	url := fmt.Sprintf("https://%s", utils.ConcatPaths(GitHubHost, owner, name))
	if path != "" {
		url = utils.ConcatPaths(url, path)
	}

	return url
}
Esempio n. 3
0
func (p *Project) GitURL(name, owner string, isSSH bool) (url string) {
	if name == "" {
		name = p.Name
	}
	if owner == "" {
		owner = p.Owner
	}

	if isSSH {
		url = fmt.Sprintf("git@%s:%s/%s.git", GitHubHost, owner, name)
	} else {
		url = fmt.Sprintf("git://%s.git", utils.ConcatPaths(GitHubHost, owner, name))
	}

	return url
}
Esempio n. 4
0
File: browse.go Progetto: prsimp/gh
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)
}
Esempio n. 5
0
File: compare.go Progetto: prsimp/gh
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)
}
Esempio n. 6
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) {
	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)
	}
}
Esempio n. 7
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)
}
Esempio n. 8
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)
}