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


Golang utils.Check函数代码示例

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


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

示例1: PromptFor

func (c *Configs) PromptFor(host string) *Credentials {
	cc := c.find(host)
	if cc == nil {
		user := c.PromptForUser()
		pass := c.PromptForPassword(host, user)

		// Create Client with a stub Credentials
		client := Client{Credentials: &Credentials{Host: host}}
		token, err := client.FindOrCreateToken(user, pass, "")
		if err != nil {
			if ce, ok := err.(*ClientError); ok && ce.Is2FAError() {
				code := c.PromptForOTP()
				token, err = client.FindOrCreateToken(user, pass, code)
			}
		}
		utils.Check(err)

		cc = &Credentials{Host: host, User: user, AccessToken: token}
		c.Credentials = append(c.Credentials, *cc)
		err = saveTo(configsFile(), c)
		utils.Check(err)
	}

	return cc
}
开发者ID:jingweno,项目名称:gh,代码行数:25,代码来源:configs.go

示例2: FetchCredentials

func (c *Config) FetchCredentials() {
	var changed bool
	if c.User == "" {
		c.FetchUser()
		changed = true
	}

	if c.Token == "" {
		password := c.FetchPassword()
		token, err := findOrCreateToken(c.User, password, "")
		// TODO: return an two factor auth failure error
		if err != nil {
			re := regexp.MustCompile("two-factor authentication OTP code")
			if re.MatchString(fmt.Sprintf("%s", err)) {
				code := c.FetchTwoFactorCode()
				token, err = findOrCreateToken(c.User, password, code)
			}
		}

		utils.Check(err)

		c.Token = token
		changed = true
	}

	if changed {
		err := SaveConfig(c)
		utils.Check(err)
	}
}
开发者ID:johnbellone,项目名称:gh,代码行数:30,代码来源:config.go

示例3: ciStatus

/*
  $ gh ci-status
  > (prints CI state of HEAD and exits with appropriate code)
  > One of: success (0), error (1), failure (1), pending (2), no status (3)

  $ gh ci-status -v
  > (prints CI state of HEAD, the URL to the CI build results and exits with appropriate code)
  > One of: success (0), error (1), failure (1), pending (2), no status (3)

  $ gh ci-status BRANCH
  > (prints CI state of BRANCH and exits with appropriate code)
  > One of: success (0), error (1), failure (1), pending (2), no status (3)

  $ gh ci-status SHA
  > (prints CI state of SHA and exits with appropriate code)
  > One of: success (0), error (1), failure (1), pending (2), no status (3)
*/
func ciStatus(cmd *Command, args *Args) {
	ref := "HEAD"
	if !args.IsParamsEmpty() {
		ref = args.RemoveParam(0)
	}

	localRepo := github.LocalRepo()
	project, err := localRepo.MainProject()
	utils.Check(err)

	sha, err := git.Ref(ref)
	if err != nil {
		err = fmt.Errorf("Aborted: no revision could be determined from '%s'", ref)
	}
	utils.Check(err)

	if args.Noop {
		fmt.Printf("Would request CI status for %s\n", sha)
	} else {
		state, targetURL, exitCode, err := fetchCiStatus(project, sha)
		utils.Check(err)
		if flagCiStatusVerbose && targetURL != "" {
			fmt.Printf("%s: %s\n", state, targetURL)
		} else {
			fmt.Println(state)
		}

		os.Exit(exitCode)
	}
}
开发者ID:jingweno,项目名称:gh,代码行数:47,代码来源:ci_status.go

示例4: ciStatus

/*
  $ gh ci-status
  > (prints CI state of HEAD and exits with appropriate code)
  > One of: success (0), error (1), failure (1), pending (2), no status (3)

  $ gh ci-status BRANCH
  > (prints CI state of BRANCH and exits with appropriate code)
  > One of: success (0), error (1), failure (1), pending (2), no status (3)

  $ gh ci-status SHA
  > (prints CI state of SHA and exits with appropriate code)
  > One of: success (0), error (1), failure (1), pending (2), no status (3)
*/
func ciStatus(cmd *Command, args *Args) {
	ref := "HEAD"
	if !args.IsParamsEmpty() {
		ref = args.RemoveParam(0)
	}

	ref, err := git.Ref(ref)
	utils.Check(err)

	args.Replace("", "")
	if args.Noop {
		fmt.Printf("Would request CI status for %s\n", ref)
	} else {
		state, targetURL, desc, exitCode, err := fetchCiStatus(ref)
		utils.Check(err)
		fmt.Println(state)
		if targetURL != "" {
			fmt.Println(targetURL)
		}
		if desc != "" {
			fmt.Println(desc)
		}

		os.Exit(exitCode)
	}
}
开发者ID:johnbellone,项目名称:gh,代码行数:39,代码来源:ci_status.go

示例5: parseOwnerAndName

func parseOwnerAndName() (name, remote string) {
	remote, err := git.Remote()
	utils.Check(err)

	url, err := mustMatchGitHubURL(remote)
	utils.Check(err)

	return url[1], url[2]
}
开发者ID:prsimp,项目名称:gh,代码行数:9,代码来源:project.go

示例6: create

/*
  $ gh create
  ... create repo on github ...
  > git remote add -f origin [email protected]:YOUR_USER/CURRENT_REPO.git

  # with description:
  $ gh create -d 'It shall be mine, all mine!'

  $ gh create recipes
  [ repo created on GitHub ]
  > git remote add origin [email protected]:YOUR_USER/recipes.git

  $ gh create sinatra/recipes
  [ repo created in GitHub organization ]
  > git remote add origin [email protected]:sinatra/recipes.git
*/
func create(command *Command, args *Args) {
	_, err := git.Dir()
	if err != nil {
		err = fmt.Errorf("'create' must be run from inside a git repository")
		utils.Check(err)
	}

	var newRepoName string
	if args.IsParamsEmpty() {
		newRepoName, err = utils.DirName()
		utils.Check(err)
	} else {
		reg := regexp.MustCompile("^[^-]")
		if !reg.MatchString(args.FirstParam()) {
			err = fmt.Errorf("invalid argument: %s", args.FirstParam())
			utils.Check(err)
		}
		newRepoName = args.FirstParam()
	}

	configs := github.CurrentConfigs()
	credentials := configs.DefaultCredentials()

	owner := credentials.User
	if strings.Contains(newRepoName, "/") {
		split := strings.SplitN(newRepoName, "/", 2)
		owner = split[0]
		newRepoName = split[1]
	}

	project := github.NewProject(owner, newRepoName, credentials.Host)
	gh := github.NewClient(project.Host)

	var action string
	if gh.IsRepositoryExist(project) {
		fmt.Printf("%s already exists on %s\n", project, project.Host)
		action = "set remote origin"
	} else {
		action = "created repository"
		if !args.Noop {
			repo, err := gh.CreateRepository(project, flagCreateDescription, flagCreateHomepage, flagCreatePrivate)
			utils.Check(err)
			project = github.NewProject(repo.FullName, "", project.Host)
		}
	}

	remote, _ := github.OriginRemote()
	if remote == nil {
		url := project.GitURL("", "", true)
		args.Replace("git", "remote", "add", "-f", "origin", url)
	} else {
		args.Replace("git", "remote", "-v")
	}

	args.After("echo", fmt.Sprintf("%s:", action), project.String())
}
开发者ID:jingweno,项目名称:gh,代码行数:72,代码来源:create.go

示例7: alias

func alias(command *Command, args *Args) {
	var shell string
	if args.ParamsSize() > 0 {
		shell = args.FirstParam()
	} else {
		shell = os.Getenv("SHELL")
	}

	if shell == "" {
		utils.Check(fmt.Errorf("Unknown shell"))
	}

	shells := []string{"bash", "zsh", "sh", "ksh", "csh", "fish"}
	shell = filepath.Base(shell)
	var validShell bool
	for _, s := range shells {
		if s == shell {
			validShell = true
			break
		}
	}

	if !validShell {
		err := fmt.Errorf("Unsupported shell. Supported shell: %s.", strings.Join(shells, ", "))
		utils.Check(err)
	}

	if flagAliasScript {
		fmt.Println("alias git=gh")
		if "zsh" == shell {
			fmt.Println("if type compdef > /dev/null; then")
			fmt.Println("  compdef gh=git")
			fmt.Println("fi")
		}
	} else {
		var profile string
		switch shell {
		case "bash":
			profile = "~/.bash_profile"
		case "zsh":
			profile = "~/.zshrc"
		case "ksh":
			profile = "~/.profile"
		default:
			profile = "your profile"
		}

		msg := fmt.Sprintf("# Wrap git automatically by adding the following to %s\n", profile)
		fmt.Println(msg)
		fmt.Println("eval  \"$(gh alias -s)\"")
	}

	os.Exit(0)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:54,代码来源:alias.go

示例8: report

func report(reportedError error, stack string) {
	title, body, err := reportTitleAndBody(reportedError, stack)
	utils.Check(err)

	project := NewProject(ghProjectOwner, ghProjectName, GitHubHost)

	gh := NewClient(project.Host)

	issue, err := gh.CreateIssue(project, title, body, []string{"Crash Report"})
	utils.Check(err)

	fmt.Println(issue.HTMLURL)
}
开发者ID:jingweno,项目名称:gh,代码行数:13,代码来源:crash_report.go

示例9: 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

示例10: issue

/*
  $ gh issue
*/
func issue(cmd *Command, args *Args) {

	gh := github.New()

	// list all issues

	if args.Noop {
		fmt.Printf("Would request list of issues for %s\n", gh.Project)
	} else {
		issues, err := gh.Issues()
		utils.Check(err)
		for _, issue := range issues {
			var url string
			// use the pull request URL if we have one
			if issue.PullRequest.HTMLURL != "" {
				url = issue.PullRequest.HTMLURL
			} else {
				url = issue.HTMLURL
			}
			// "nobody" should have more than 1 million github issues
			fmt.Printf("% 7d] %s ( %s )\n", issue.Number, issue.Title, url)
		}
	}

	os.Exit(0)
}
开发者ID:johnbellone,项目名称:gh,代码行数:29,代码来源:issue.go

示例11: tranformFetchArgs

func tranformFetchArgs(args *Args) {
	remotes, err := git.Remotes()
	utils.Check(err)

	names := parseRemoteNames(args)
	gh := github.New()
	projects := []github.Project{}
	ownerRegexp := regexp.MustCompile(OwnerRe)
	for _, name := range names {
		if ownerRegexp.MatchString(name) && !isRemoteExist(remotes, name) {
			project := github.NewProjectFromNameAndOwner("", name)
			repo, err := gh.Repository(project)
			if err != nil {
				continue
			}

			project = github.NewProjectFromNameAndOwner("", repo.FullName)
			projects = append(projects, project)
		}
	}

	for _, project := range projects {
		var isSSH bool
		if project.Owner == gh.Config.FetchUser() {
			isSSH = true
		}
		args.Before("git", "remote", "add", project.Owner, project.GitURL("", "", isSSH))
	}
}
开发者ID:rif,项目名称:golang-stuff,代码行数:29,代码来源:fetch.go

示例12: transformRemoteArgs

func transformRemoteArgs(args *Args) {
	ownerWithName := args.LastParam()
	owner, name, match := parseRepoNameOwner(ownerWithName)
	if !match {
		return
	}

	var err error
	if name == "" {
		name, err = utils.DirName()
		utils.Check(err)
	}

	isPriavte := parseRemotePrivateFlag(args)

	if owner == "origin" {
		owner = github.CurrentConfig().FetchUser()
	} else if args.ParamsSize() > 2 {
		// `git remote add jingweno foo/bar`
		args.RemoveParam(args.ParamsSize() - 1)
	}

	project := github.Project{Owner: owner, Name: name}
	url := project.GitURL(name, owner, isPriavte)

	args.AppendParams(url)
}
开发者ID:johnbellone,项目名称:gh,代码行数:27,代码来源:remote.go

示例13: CurrentProject

func CurrentProject() *Project {
	remote, err := git.OriginRemote()
	utils.Check(err)

	owner, name := parseOwnerAndName(remote.URL)

	return &Project{name, owner}
}
开发者ID:johnbellone,项目名称:gh,代码行数:8,代码来源:project.go

示例14: ci

func ci(cmd *Command, args []string) {
	ref := "HEAD"
	if len(args) > 0 {
		ref = args[0]
	}

	ref, err := git.Ref(ref)
	utils.Check(err)

	gh := github.New()
	status, err := gh.CiStatus(ref)
	utils.Check(err)

	var state string
	var targetURL string
	var desc string
	var exitCode int
	if status == nil {
		state = "no status"
	} else {
		state = status.State
		targetURL = status.TargetURL
		desc = status.Description
	}

	switch state {
	case "success":
		exitCode = 0
	case "failure", "error":
		exitCode = 1
	case "pending":
		exitCode = 2
	default:
		exitCode = 3
	}

	fmt.Println(state)
	if targetURL != "" {
		fmt.Println(targetURL)
	}
	if desc != "" {
		fmt.Println(desc)
	}

	os.Exit(exitCode)
}
开发者ID:prsimp,项目名称:gh,代码行数:46,代码来源:ci.go

示例15: detectContentType

func detectContentType(path string, fi os.FileInfo) string {
	file, err := os.Open(path)
	utils.Check(err)
	defer file.Close()

	fileHeader := &bytes.Buffer{}
	headerSize := int64(512)
	if fi.Size() < headerSize {
		headerSize = fi.Size()
	}

	// The content type detection only uses 512 bytes at most.
	// This way we avoid copying the whole content for big files.
	_, err = io.CopyN(fileHeader, file, headerSize)
	utils.Check(err)

	return http.DetectContentType(fileHeader.Bytes())
}
开发者ID:jingweno,项目名称:gh,代码行数:18,代码来源:release.go


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