예제 #1
0
파일: ci_status.go 프로젝트: johnbellone/gh
/*
  $ 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)
	}
}
예제 #2
0
파일: ci_status.go 프로젝트: jingweno/gh
/*
  $ 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)
	}
}
예제 #3
0
파일: ci.go 프로젝트: prsimp/gh
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)
}