Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.

Repository files navigation

PkgGoDevGitHub release (latest SemVer)GitHub go.mod Go versionCircleCICode CoverageGo Report CardApache 2.0 license

Go-Targetprocess

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

Usage

package main
import (
"encoding/json""fmt""os""github.com/sirupsen/logrus"
tp "github.com/FairwindsOps/go-targetprocess"
)
funcmain() {
logger:=logrus.New()
tpClient, err:=tp.NewClient("exampleCompany", "superSecretToken")
iferr!=nil {
fmt.Println(err)
os.Exit(1)
}
tpClient.Logger=loggeruserStories, err:=tpClient.GetUserStories(
// we set paging to false so we only get the first page of resultsfalse,
// The Where() filter function takes in any queries the targetprocess API accepts// Read about those here: https://dev.targetprocess.com/docs/sorting-and-filterstp.Where("EntityState.Name != 'Done'"),
tp.Where("EntityState.Name != 'Backlog'"),
// Simlar to Where(), the Include() function will limit the// response to a given list of fieldstp.Include("Team", "Name", "ModifyDate"),
)
iferr!=nil {
fmt.Println(err)
os.Exit(1)
}
jsonBytes, _:=json.Marshal(userStories)
fmt.Print(string(jsonBytes))
}

Custom structs for queries

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:

funcmain() {
out:=struct {
NextstringPrevstringItems []interface{}
}{}
tpClient, err:=tp.NewClient("exampleCompany", "superSecretToken")
iferr!=nil {
fmt.Println(err)
os.Exit(1)
}
err:=tpClient.Get(&out, "Users", nil)
iferr!=nil {
fmt.Println(err)
os.Exit(1)
}
jsonBytes, _:=json.Marshal(out)
fmt.Print(string(jsonBytes))
}

Debug Logging

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 methodlogger.SetLevel(logrus.DebugLevel)
client, err:=targetprocess.NewClient(accountName, token)
iferr!=nil {
fmt.Println(err)
os.Exit(1)
}
client.Logger=logger

Contributing

PRs welcome! Check out the Contributing Guidelines and Code of Conduct for more information.

Join the Fairwinds Open Source Community

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 Slackjoin the user group to get involved!

Love Fairwinds Open Source? Share your business email and job title and we'll send you a free Fairwinds t-shirt!

Other Projects from Fairwinds

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

About

Go library for interacting with the TargetProcess API

Topics

Resources

Code of conduct

Contributing

Stars

4 stars

Watchers

7 watching

Forks

Releases

Contributors

Languages