Exemple #1
0
func main() {
	circleci := circleci.NewClient("<token>")

	projects, err := circleci.Projects()
	if err != nil {
		fmt.Println(err)
		return
	}

	for _, project := range projects {
		fmt.Println(project.VCSURL)
		for _, project := range projects {
			artifacts, err := project.Artifacts(circleci, "master")
			if err != nil {
				fmt.Println(err)
				return
			}
			for _, artifact := range artifacts {
				file, err := artifact.Download(circleci, ".")
				if err != nil {
					fmt.Println(err)
					return
				}
				err = os.Remove(file)
				if err != nil {
					fmt.Println(err)
					return
				}
			}
		}
	}

	recent_builds, err := circleci.RecentBuilds("", "", "", 30, 0)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("All builds", len(recent_builds))

	github_builds, err := circleci.RecentBuilds("github", "github", "", 30, 0)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("GitHub builds", len(github_builds))

	master_builds, err := circleci.RecentBuilds("github", "github", "master", 30, 0)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("Master builds", len(master_builds))

	details, err := circleci.BuildDetails("github", "github", master_builds[0].BuildNum)

	fmt.Println("Details", details)
}
func main() {
	circleci := circleci.NewClient("<token>")

	projects, err := circleci.Projects()
	if err != nil {
		fmt.Println(err)
		return
	}

	for _, project := range projects {
		fmt.Println(project.VCSURL)
	}

	recent_builds, err := circleci.RecentBuilds("", "", "", 30, 0)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("All builds", len(recent_builds))

	github_builds, err := circleci.RecentBuilds("github", "github", "", 30, 0)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("GitHub builds", len(github_builds))

	master_builds, err := circleci.RecentBuilds("github", "github", "master", 30, 0)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("Master builds", len(master_builds))

	details, err := circleci.BuildDetails("github", "github", master_builds[0].BuildNum)

	fmt.Println("Details", details)
}
// Render dashboard
func (d DashboardCircleCI) Render() (string, error) {
	var output bytes.Buffer
	t, err := template.New("Dashboard_CircleCI").
		ParseFiles("templates/circleci.html", "templates/circleci_error.html")
	if err != nil {
		return "", err
	}

	ci := circleci.NewClient(d.token)

	recentBuild, err := ci.RecentBuilds(d.user, d.project, d.branch, 1, 0)
	if err != nil {
		err = t.ExecuteTemplate(
			&output,
			"circleci_error.html",
			d.project+" - "+err.Error())
		if err != nil {
			return err.Error(), nil
		}
		return output.String(), nil
	}

	if len(recentBuild) != 1 {
		err = t.ExecuteTemplate(
			&output,
			"circleci_error.html",
			d.project+" - Recent build not found!")
		if err != nil {
			return err.Error(), nil
		}
		return output.String(), nil
	}

	err = t.ExecuteTemplate(&output, "circleci.html", recentBuild[0])
	if err != nil {
		return "", err
	}

	return output.String(), nil
}