Created
June 21, 2019 05:31
-
-
Save maplebed/d9cb97961448dc02a641200b089e2f19 to your computer and use it in GitHub Desktop.
Sample code exercising the new endpoints to the go-circleci package introduced in a PR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
circleci "github.com/jszwedko/go-circleci" | |
) | |
func main() { | |
token, _ := os.LookupEnv("CIRCLE_API_TOKEN") | |
client := &circleci.Client{ | |
Token: token, | |
} | |
builds, err := client.ListRecentBuilds(10, 0) | |
fmt.Printf("error is %+v\n", err) | |
// spew.Dump(builds[0]) | |
for _, build := range builds { | |
fmt.Printf("build url is %s\n", build.BuildURL) | |
fmt.Printf("lifecylce is %s\n", build.Lifecycle) | |
fmt.Printf("workflow ID is %s\n", build.Workflows.WorkflowId) | |
} | |
fmt.Printf("builds are %+v\n", builds) | |
fmt.Println("---") | |
wfID := builds[1].Workflows.WorkflowId | |
workflow, err := client.GetWorkflowV2(wfID) | |
fmt.Printf("err is %+v\n", err) | |
fmt.Printf("Workflow is %+v\n", workflow) | |
wfJobs, more, err := client.ListWorkflowV2Jobs(wfID, nil) | |
for more != nil { | |
fmt.Printf("getting more jobs! next page is %s\n", *more) | |
var moreJobs []*circleci.WorkflowJob | |
moreJobs, more, err = client.ListWorkflowV2Jobs(wfID, nil) | |
wfJobs = append(wfJobs, moreJobs...) | |
} | |
fmt.Printf("err is %+v\n", err) | |
fmt.Printf("Workflow Jobs are %+v\n", wfJobs) | |
for _, job := range wfJobs { | |
fmt.Printf("job name: %s, %s\n", job.Name, job.Status) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment