Package targetprocess is a go library to make using the Targetprocess API easier. Some public types are included to ease in json -> struct unmarshaling. A lot of inspiration for this package comes from https://github.com/adlio/trello
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/sirupsen/logrus"
tp "github.com/FairwindsOps/go-targetprocess"
)
func main() {
logger := logrus.New()
tpClient, err := tp.NewClient("exampleCompany", "superSecretToken")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
tpClient.Logger = logger
userStories, err := tpClient.GetUserStories(
// we set paging to false so we only get the first page of results
false,
// The Where() filter function takes in any queries the targetprocess API accepts
// Read about those here: https://dev.targetprocess.com/docs/sorting-and-filters
tp.Where("EntityState.Name != 'Done'"),
tp.Where("EntityState.Name != 'Backlog'"),
// Simlar to Where(), the Include() function will limit the
// response to a given list of fields
tp.Include("Team", "Name", "ModifyDate"),
)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
jsonBytes, _ := json.Marshal(userStories)
fmt.Print(string(jsonBytes))
}
go-targetprocess includes some built-in structs that can be used for Users, Projects, Teams, and UserStories. You don't
have to use those though and can use the generic Get()
method with a custom struct as the output for a response to be
JSON decoded into. Filtering functions (Where()
, Include()
, etc.) can be used in Get()
just like they can in
any of the helper functions.
Ex:
func main() {
out := struct {
Next string
Prev string
Items []interface{}
}{}
tpClient, err := tp.NewClient("exampleCompany", "superSecretToken")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err := tpClient.Get(&out, "Users", nil)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
jsonBytes, _ := json.Marshal(out)
fmt.Print(string(jsonBytes))
}
This idea was taken directly from the https://github.com/adlio/trello package. To add a debug logger, do the following:
logger := logrus.New()
// Also supports logrus.InfoLevel but that is default if you leave out the SetLevel method
logger.SetLevel(logrus.DebugLevel)
client, err := targetprocess.NewClient(accountName, token)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
client.Logger = logger
PRs welcome! Check out the Contributing Guidelines and Code of Conduct for more information.
The goal of the Fairwinds Community is to exchange ideas, influence the open source roadmap, and network with fellow Kubernetes users. Chat with us on Slack join the user group to get involved!
Enjoying go-targetprocess? Check out some of our other projects:
- Polaris - Audit, enforce, and build policies for Kubernetes resources, including over 20 built-in checks for best practices
- Goldilocks - Right-size your Kubernetes Deployments by compare your memory and CPU settings against actual usage
- Pluto - Detect Kubernetes resources that have been deprecated or removed in future versions
- Nova - Check to see if any of your Helm charts have updates available
- rbac-manager - Simplify the management of RBAC in your Kubernetes clusters