Categorygithub.com/fairwindsops/go-targetprocess
modulepackage
0.3.2-alpha.3
Repository: https://github.com/fairwindsops/go-targetprocess.git
Documentation: pkg.go.dev

# README

PkgGoDevGitHub release (latest SemVer) GitHub go.mod Go version CircleCI Code Coverage Go Report Card Apache 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

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 Slack or join the user group to get involved!

Usage

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))
}

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:

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))
}

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 method
logger.SetLevel(logrus.DebugLevel)
client, err := targetprocess.NewClient(accountName, token)
if err != 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.

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

Or check out the full list

# Functions

First is a QueryFilter that will only return a single Entity.
GenerateURL takes an account name and entityID and returns a URL that should work in a browser.
IsNotFound takes an error and returns true if the error is exactly a not-found error.
IsPermissionDenied takes an error and returns true if the error is exactly a permission-denied error.
MaxPerPage is how many results we will allow to return per page.
NewClient will create a new Targetprocess client account is the name of your Targetprocess account and will be the first part of your Targetprocess url.
NewFeature creates a Feature struct with the required fields of name, description, and project.
NewUserStory creates a new UserStory with the required fields of name, description, and project.
Result is a QueryFilter that represents the `result` parameter in a url query.
Select is a QueryFilter that represents the `select` parameter in a url query.
Where is a QueryFilter that represents the `where` parameter in a url query.

# Structs

AssignedUser is used in UserStories and potentially other places.
Assignment is a generic entity that lists a single assignment.
Assignments is a generic entity that lists assignments.
Client is the API client for Targetprocess.
CustomField are user defined in TargetProcess and are arbitrarily set for many different resource types.
CustomFieldResponse is a representation of the http response for a group of CustomField.
EntityState contains metadata for the state of an Entity.
EntityStateResponse is a representation of the http response for a group of EntityStates.
Feature matches up with a targetprocess Feature.
FeatureResponse is a representation of the http response for a group of Features.
Priority defines importance in targetprocess and can be assigned to multiple Assignable EntityTypes.
PriorityResponse is a representation of the http response for a group of Priority objects.
Process contains metadata for the state of a Process.
ProcessResponse is a representation of the http response for a group of Processs.
Project matches up with a targetprocess Project.
ProjectResponse is a representation of the http response for a group of Projects.
Team matches up with a targetprocess Team.
TeamAssignment has it's own unique Id and also includes a reference to the team, which also has an Id.
TeamResponse is a representation of the http response for a group of Teams.
User matches up with a targetprocess User.
UserAssignment has its own unique Id and also includes a reference to a user, which also has an Id.
UserResponse is a representation of the http response for a group of Users.
UserStory matches up with a targetprocess UserStory.
UserStoryList is a list of user stories.
UserStoryResponse is a representation of the http response for a group of UserStories.
Workflow contains metadata for the state of a Workflow.
WorkflowResponse is a representation of the http response for a group of Workflows.

# Type aliases

DateTime currently does nothing special but will represent the TP DateTime objects.
QueryFilter accepts a query and returns a query, modifying it in some way before sending.