tracker

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Github

type Github struct {
	// contains filtered or unexported fields
}

Github implements Interface over the github issues tracker.

func NewGithub

func NewGithub(params GithubParams) (*Github, error)

NewGithub makes new instance of Github tracker.

func (*Github) Call

func (g *Github) Call(ctx context.Context, req Request) (Response, error)

Call handles the incoming request.

func (*Github) HandleWebhook

func (g *Github) HandleWebhook(w http.ResponseWriter, r *http.Request)

HandleWebhook handles webhooks from github.

func (*Github) Listen

func (g *Github) Listen(ctx context.Context, h Handler) error

Listen does nothing and waits until the context is dead.

func (*Github) Name

func (g *Github) Name() string

Name returns the name of the tracker.

func (*Github) Subscribe

func (g *Github) Subscribe(ctx context.Context, req SubscribeReq) (SubscribeResp, error)

Subscribe sends a request to github for webhook and sets a handler for that webhook.

func (*Github) Unsubscribe

func (g *Github) Unsubscribe(ctx context.Context, req UnsubscribeReq) error

Unsubscribe removes the webhook from github and removes the handler for that webhook.

type GithubParams

type GithubParams struct {
	Name   string
	Vars   lib.Vars
	Client *http.Client
	Logger logx.Logger
}

GithubParams describes parameters to initialize Github.

type Handler

type Handler interface {
	Handle(ctx context.Context, upd store.Update)
}

Handler handles the update, received from the Tracker.

type HandlerFunc

type HandlerFunc func(context.Context, store.Update)

HandlerFunc is an adapter to use ordinary functions as Handler.

func (HandlerFunc) Handle

func (f HandlerFunc) Handle(ctx context.Context, upd store.Update)

Handle calls the wrapped function.

type Interface

type Interface interface {
	// Name returns the name of the tracker to match in the configuration.
	Name() string

	// Call makes a request to the tracker with specified method name,
	// variables and dastracker's ID. Response should contain the
	// ID of the ticket in the tracker.
	Call(ctx context.Context, req Request) (Response, error)

	// Subscribe makes a trigger with specified parameters and returns the
	// channel, to which updates will be published.
	Subscribe(ctx context.Context, req SubscribeReq) (SubscribeResp, error)

	// Unsubscribe removes the trigger from the tracker.
	Unsubscribe(ctx context.Context, req UnsubscribeReq) error

	// HandleWebhook handles the update, received from the tracker.
	// It must parse the received request and call the provided to Listen
	// Handler.
	HandleWebhook(w http.ResponseWriter, r *http.Request)

	// Listen runs the tracker's listener.
	// When the app is shutting down (ctx is canceled),
	// all trackers must unset all webhooks.
	Listen(ctx context.Context, h Handler) error
}

Interface defines methods that each task tracker must implement.

type InterfaceMock

type InterfaceMock struct {
	// CallFunc mocks the Call method.
	CallFunc func(ctx context.Context, req Request) (Response, error)

	// HandleWebhookFunc mocks the HandleWebhook method.
	HandleWebhookFunc func(w http.ResponseWriter, r *http.Request)

	// ListenFunc mocks the Listen method.
	ListenFunc func(ctx context.Context, h Handler) error

	// NameFunc mocks the Name method.
	NameFunc func() string

	// SubscribeFunc mocks the Subscribe method.
	SubscribeFunc func(ctx context.Context, req SubscribeReq) (SubscribeResp, error)

	// UnsubscribeFunc mocks the Unsubscribe method.
	UnsubscribeFunc func(ctx context.Context, req UnsubscribeReq) error
	// contains filtered or unexported fields
}

InterfaceMock is a mock implementation of Interface.

func TestSomethingThatUsesInterface(t *testing.T) {

	// make and configure a mocked Interface
	mockedInterface := &InterfaceMock{
		CallFunc: func(ctx context.Context, req Request) (Response, error) {
			panic("mock out the Call method")
		},
		HandleWebhookFunc: func(w http.ResponseWriter, r *http.Request)  {
			panic("mock out the HandleWebhook method")
		},
		ListenFunc: func(ctx context.Context, h Handler) error {
			panic("mock out the Listen method")
		},
		NameFunc: func() string {
			panic("mock out the Name method")
		},
		SubscribeFunc: func(ctx context.Context, req SubscribeReq) (SubscribeResp, error) {
			panic("mock out the Subscribe method")
		},
		UnsubscribeFunc: func(ctx context.Context, req UnsubscribeReq) error {
			panic("mock out the Unsubscribe method")
		},
	}

	// use mockedInterface in code that requires Interface
	// and then make assertions.

}

func (*InterfaceMock) Call

func (mock *InterfaceMock) Call(ctx context.Context, req Request) (Response, error)

Call calls CallFunc.

func (*InterfaceMock) CallCalls

func (mock *InterfaceMock) CallCalls() []struct {
	Ctx context.Context
	Req Request
}

CallCalls gets all the calls that were made to Call. Check the length with:

len(mockedInterface.CallCalls())

func (*InterfaceMock) HandleWebhook

func (mock *InterfaceMock) HandleWebhook(w http.ResponseWriter, r *http.Request)

HandleWebhook calls HandleWebhookFunc.

func (*InterfaceMock) HandleWebhookCalls

func (mock *InterfaceMock) HandleWebhookCalls() []struct {
	W http.ResponseWriter
	R *http.Request
}

HandleWebhookCalls gets all the calls that were made to HandleWebhook. Check the length with:

len(mockedInterface.HandleWebhookCalls())

func (*InterfaceMock) Listen

func (mock *InterfaceMock) Listen(ctx context.Context, h Handler) error

Listen calls ListenFunc.

func (*InterfaceMock) ListenCalls

func (mock *InterfaceMock) ListenCalls() []struct {
	Ctx context.Context
	H   Handler
}

ListenCalls gets all the calls that were made to Listen. Check the length with:

len(mockedInterface.ListenCalls())

func (*InterfaceMock) Name

func (mock *InterfaceMock) Name() string

Name calls NameFunc.

func (*InterfaceMock) NameCalls

func (mock *InterfaceMock) NameCalls() []struct {
}

NameCalls gets all the calls that were made to Name. Check the length with:

len(mockedInterface.NameCalls())

func (*InterfaceMock) Subscribe

func (mock *InterfaceMock) Subscribe(ctx context.Context, req SubscribeReq) (SubscribeResp, error)

Subscribe calls SubscribeFunc.

func (*InterfaceMock) SubscribeCalls

func (mock *InterfaceMock) SubscribeCalls() []struct {
	Ctx context.Context
	Req SubscribeReq
}

SubscribeCalls gets all the calls that were made to Subscribe. Check the length with:

len(mockedInterface.SubscribeCalls())

func (*InterfaceMock) Unsubscribe

func (mock *InterfaceMock) Unsubscribe(ctx context.Context, req UnsubscribeReq) error

Unsubscribe calls UnsubscribeFunc.

func (*InterfaceMock) UnsubscribeCalls

func (mock *InterfaceMock) UnsubscribeCalls() []struct {
	Ctx context.Context
	Req UnsubscribeReq
}

UnsubscribeCalls gets all the calls that were made to Unsubscribe. Check the length with:

len(mockedInterface.UnsubscribeCalls())

type JSONRPC

type JSONRPC struct {
	// contains filtered or unexported fields
}

JSONRPC implements Interface in order to allow external services, described in the configuration file, extend the functionality of the dastracker.

func NewJSONRPC

func NewJSONRPC(name string, l logx.Logger, vars lib.Vars) (*JSONRPC, error)

NewJSONRPC makes new instance of JSONRPC.

func (*JSONRPC) Call

func (rpc *JSONRPC) Call(ctx context.Context, req Request) (Response, error)

Call makes a call to the remote JSONRPC server with given Request.

func (*JSONRPC) HandleWebhook

func (rpc *JSONRPC) HandleWebhook(w http.ResponseWriter, r *http.Request)

HandleWebhook handles webhook call from the remote JSONRPC server.

func (*JSONRPC) Listen

func (rpc *JSONRPC) Listen(ctx context.Context, h Handler) error

Listen starts updates listener.

func (*JSONRPC) Name

func (rpc *JSONRPC) Name() string

Name returns the name of the JSONRPC plugin tracker.

func (*JSONRPC) Subscribe

func (rpc *JSONRPC) Subscribe(ctx context.Context, req SubscribeReq) (SubscribeResp, error)

Subscribe sends subscribe call to the remote JSONRPC server.

func (*JSONRPC) Unsubscribe

func (rpc *JSONRPC) Unsubscribe(ctx context.Context, req UnsubscribeReq) error

Unsubscribe sends unsubscribe call to the remote JSONRPC server.

type Request

type Request struct {
	// TaskID in the target tracker, might be empty if the request is for creation
	TaskID string
	Method string
	Vars   lib.Vars
}

Request describes a requests to tracker's action.

type Response

type Response struct {
	Task store.Task
}

Response describes possible return values of the Interface.Call

type SubscribeReq

type SubscribeReq struct {
	Vars       lib.Vars
	WebhookURL string
}

SubscribeReq describes parameters of the subscription for task updates.

type SubscribeResp

type SubscribeResp struct {
	TrackerRef string
}

SubscribeResp describes response from tracker on subscription request.

type UnsubscribeReq

type UnsubscribeReq struct {
	TrackerRef string
}

UnsubscribeReq describes parameters for the unsubscription from task updates.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL