bluemantis

package module
v0.0.0-...-fa31813 Latest Latest
Warning

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

Go to latest
Published: May 9, 2021 License: MIT Imports: 10 Imported by: 0

README

BlueMantis

BlueMantis is a Go package in development that aim to make the process of sending issues and bugs in Go applications to the Open Source Bug Tracking software MantisBT.

This package came from my need to have a system that is more rubust than simply storing the logs locally in the server and simpler than using something like Sentry or DataDog. Also, it is always good to have the option to have the bug tracking software as part of your infrastructure instead of having it in a third party (specially if they are paid, like Sentry and DataDog are).

This is (at the moment at least) a one person small project. But I would love to have more people interested in participating in the development. First because I'm far from an expert in the subject, second because we all have a limited amount of hours in a day.

How to Contribute

Well, the first thing you need to know is that I manage the development of this using the Projects tab of this repository. Use it to know where to start focusing your development. If you wanto to have a more specific pain point to focus your help, the issues tab is a good point. I add things I notice that I might need or want help.

It is also a good point to check out the wiki tab to know how to setup your environment, because currently you will need to use Docker to run a local version of MantisBT to test BlueMantis.

Usage
...
    btClient := bluemantis.NewClient(   
        "http://localhost:8989",
        "AAaaBBbbCCccDDddEEeeFFffGGgg--__",
        "@every 15m",
    )

    btProject, err := bt.GetProject("Empty Project Alpha")
    if err != nil {
        panic(err)
    }

    issue, ok := bt.NewIssue(
        &bluemantis.BaseIssue{
            Summary:        "Empty Project",
            Description:    "This is an empty project, have you noticed that this is the only code in main?",
            Category:       "Critical",
            Project:        btProject,
        },
    ).Send().Retry().RetryLater()
...

*currently! This is in VERY early development, and no function naming or style has been set on stone yet.

Documentation

Index

Constants

View Source
const (

	// SAMPLETOKEN is a example of valid token
	SAMPLETOKEN = "7-EtgZGHhpONO7shfeZXxKEX66WXuE9-"
	// SAMPLESUMMARY is a example of a valid summary
	SAMPLESUMMARY = "This is a Summary"
	// SAMPLEDESCRIPTION is a example of a valid description
	SAMPLEDESCRIPTION = "This is a Description"
	// SAMPLECATEGORYNAME is a example of a valid category name
	SAMPLECATEGORYNAME = "This is a Category Name"
	// SAMPLEPROJECTNAME is a example of a valid project name
	SAMPLEPROJECTNAME = "This is a Project Name"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseIssue

type BaseIssue struct {
	// Summary: We recommend putting your err.Error() here
	Summary string `valid:"required" json:"summary"`
	// Description: We recommend you put the object transited at the moment
	// of the error here in a serialized format (JSON)
	Description string   `valid:"required" json:"description"`
	Category    *Rel     `valid:"required" json:"category"`
	Project     *Project `valid:"required" json:"project"`
}

BaseIssue represent the minimal information required to submit a valid issue report to MantisBT using the package BlueMantis. Please notice that all of the data must be set, including the minimal data from Category and Project.

type Client

type Client struct {
	*http.Client
	URL               string
	Token             string
	Scheduler         *cron.Cron
	SchedulerInterval string
}

Client represents the basic structure that contains the configuration needed for a valid communication with any given Mantis Bug Tracker instance. It should not be created directly, please make use of the function NewClient to create a valid and most importantly, tested, Client.

func NewClient

func NewClient(url, token string, delayInterval string) (*Client, error)

NewClient creates and test (including the connection) with a MantisBT server and returns a validated pointer to a Client struct for usage in your application. In case of a invalid URL, invalid Token, or communication failure with the MantisBT desired installation, it will return nil and a descriptive error with the problem.

func (*Client) NewIssue

func (c *Client) NewIssue(bascInfo *BaseIssue) *Issue

NewIssue will currently still being implemented, at the moment it creates only a basic pointer to a Issue struct, without any of the actual necessary data <- TODO

type ExtendedIssue

type ExtendedIssue struct {
	Status          *Status   `valid:"-" json:"status"`
	Reporter        *Reporter `valid:"-" json:"reporter"`
	Resolution      *Rel      `valid:"-" json:"resolution"`
	ViewState       *Rel      `valid:"-" json:"view_state"`
	Priority        *Rel      `valid:"-" json:"priority"`
	Severity        *Rel      `valid:"-" json:"severity"`
	Reproducibility *Rel      `valid:"-" json:"reproducibility"`
	Sticky          bool      `valid:"-" json:"sticky"`
	Meta
}

ExtendedIssue represent the complete (not including history atm) information recommended to submit a valid issue report to MantisBT using the package BlueMantis. Please notice that all of this data is optional, and Mantis will normally assign default values for all of this relations. You should use name if you don't know a object given ID. Do not use label for this.

type Issue

type Issue struct {
	Client *Client

	*BaseIssue
	*ExtendedIssue
	// contains filtered or unexported fields
}

Issue represents the basic structure that contains a client, the necessary data to create the issue in MantisBT and a request-response pair, that will hold the request sent/to be send to MantisBT and the response received/ to be received by the MantisBT application. It should not be manually created. It is preferred to be created with the NewIssue(), that receive the BaseIssue and the ExtendedIssue structs.

func (*Issue) Retry

func (i *Issue) Retry(err error) error

Retry do a second attempt of a immediate request to the MantisBT server using the same information used before. Best used together with Send, like: newIssue.Send().Retry().RetryLater()

func (*Issue) RetryLater

func (i *Issue) RetryLater(err error)

RetryLater will schedule using CRON a new execution of the function send, using as a delay value the configuration informed when creating a MantisBT client.

func (*Issue) Send

func (i *Issue) Send() error

Send do a immediate request to the MantisBT server using the information in Issue.Request and returns a confirmation if such request was successful or not. If anything other than 201 is returned, or if the connection fail for some reason, it will return an error.

type Meta

type Meta struct {
	CreatedAt time.Time `valid:"-" json:"created_at"`
	UpdatedAt time.Time `valid:"-" json:"updated_at"`
}

Meta stores time sensitive information, such as last time a given object was created, edited, deleted and by whom those operations have been done.

type Project

type Project struct {
	ID          uint64 `valid:"optional" json:"id"`
	Name        string `valid:"required" json:"name"`
	Description string `valid:"optional" json:"description"`
	Enabled     bool   `valid:"optional" json:"enabled"`
	Status      Status `valid:"-" json:"status"`
	ViewState   Rel    `valid:"-" json:"view_state"`
	FilePath    string `valid:"_" json:"file_path"`
}

Project represents a instance of a project, as a single MantisBT application can support logging bugs and errors from multiple projects at the same time.

type Rel

type Rel struct {
	ID    uint64 `valid:"optional" json:"id"`
	Name  string `valid:"required" json:"name"`
	Label string `valid:"optional" json:"label"`
}

Rel represent a generic relationship with a different object, such as Categories, Fields, Handlers, Status and etc. It is usually re-labeled to match the object name through the package.

type Reporter

type Reporter struct {
	Rel
	Email string `valid:"email,optional" json:"email"`
}

Reporter represents who is reporting a given error. It usually matches the user who generated the Authorization Token of the application, but may be different depending on the configuration on MantisBT.

type Status

type Status struct {
	Rel
	Color string `valid:"-" json:"color"`
}

Status holds a given status from MantisBT. Default Status are normally: "new", "feedback", "acknowledged", "confirmed", "assigned", "resolved" and "closed".

Jump to

Keyboard shortcuts

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