Example #1
0
func main() {
	config.SetupConfig() // CRITICAL!

	// Examples then how to use the API
	_, err := apiclient.Default.Operations.GetPullRequests(operations.GetPullRequestsParams{Project: "<will-404>", Repo: "square"})
	fatalIfErrUnless404(err)
	// more detailed example to handle a 404.
	if err == nil {
		panic("expecting error for 404 not found")
	} else {
		spew.Dump(err)
		if apiErr, ok := err.(operations.APIError); !ok {
			log.Println(".. err not an APIError")
		} else {
			if apiErr.Code != 404 {
				panic("expecting 404")
			}

			if resp404, ok := apiErr.Response.(*operations.GetPullRequestsNotFound); !ok {
				log.Println(".. err response not GetPullRequestsNotFound")
			} else {
				log.Println("this err's response", resp404)
			}
		}
	}

	resp1, err := apiclient.Default.Operations.GetCommits(operations.GetCommitsParams{Project: "GO", Repo: "square"})
	fatalIfErrUnless404(err)
	fmt.Printf("%#v\n\n", resp1.Payload)

	resp2, err := apiclient.Default.Operations.GetPullRequests(operations.GetPullRequestsParams{Project: "GO", Repo: "square"})
	fatalIfErrUnless404(err)
	fmt.Printf("%#v\n\n", resp2.Payload)
	pullRequestId := resp2.Payload.Values[0].ID

	resp3, err := apiclient.Default.Operations.GetPullRequestActivities(
		operations.GetPullRequestActivitiesParams{Project: "GO", Repo: "square", PullRequestID: pullRequestId})
	fatalIfErrUnless404(err)
	fmt.Printf("%#v\n\n", resp3.Payload)
}
Example #2
0
func main() {
	var mode = flag.String("mode", "", "[remote|local] to use the local cache of data or re-fetch it")
	flag.Parse()

	var cache data.Cache
	switch *mode {
	case "remote":
		stashrestapiclientsetup.SetupConfig()
		cache = fetch.FetchData()
		// Fetching is slow, so store for playing with it later.
		cache.SaveGob("./pr-data-pull.dat")
		cache.SaveJson("../assets/pr-data-pull.json")
	case "local":
		cache = data.LoadGob("./pr-data-pull.dat")
		cache.SaveJson("../assets/pr-data-pull.json")
	case "":
		fallthrough
	default:
		flag.Usage()
		os.Exit(1)
	}
}