annotations

package
v0.0.0-...-c8ce297 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package annotations defines a data model for a feature that allows users to add metadata to tasks.

Index

Constants

View Source
const (
	Collection            = "task_annotations"
	UIRequester           = "ui"
	APIRequester          = "api"
	WebhookRequester      = "webhook"
	MaxMetadataLinks      = 1
	MaxMetadataTextLength = 40
)

Variables

View Source
var (
	// bson fields for the TaskAnnotation struct
	IdKey              = bsonutil.MustHaveTag(TaskAnnotation{}, "Id")
	TaskIdKey          = bsonutil.MustHaveTag(TaskAnnotation{}, "TaskId")
	TaskExecutionKey   = bsonutil.MustHaveTag(TaskAnnotation{}, "TaskExecution")
	MetadataKey        = bsonutil.MustHaveTag(TaskAnnotation{}, "Metadata")
	NoteKey            = bsonutil.MustHaveTag(TaskAnnotation{}, "Note")
	IssuesKey          = bsonutil.MustHaveTag(TaskAnnotation{}, "Issues")
	SuspectedIssuesKey = bsonutil.MustHaveTag(TaskAnnotation{}, "SuspectedIssues")
	CreatedIssuesKey   = bsonutil.MustHaveTag(TaskAnnotation{}, "CreatedIssues")
	IssueLinkIssueKey  = bsonutil.MustHaveTag(IssueLink{}, "IssueKey")
	MetadataLinksKey   = bsonutil.MustHaveTag(TaskAnnotation{}, "MetadataLinks")
)

Functions

func AddCreatedTicket

func AddCreatedTicket(taskId string, execution int, ticket IssueLink, userDisplayName string) error

func AddSuspectedIssueToAnnotation

func AddSuspectedIssueToAnnotation(taskId string, execution int, issue IssueLink, username string) error

func ByTaskId

func ByTaskId(id string) bson.M

ByTaskId returns the query for a given Task Id

func ByTaskIdAndExecution

func ByTaskIdAndExecution(id string, execution int) bson.M

ByTaskIdAndExecution returns the query for a given Task Id and execution number

func ByTaskIds

func ByTaskIds(ids []string) db.Q

func CreateAnnotationUpdate

func CreateAnnotationUpdate(annotation *TaskAnnotation, userDisplayName string) bson.M

CreateAnnotationUpdate constructs a DB update to modify an existing task annotation.

func RemoveSuspectedIssueFromAnnotation

func RemoveSuspectedIssueFromAnnotation(taskId string, execution int, issue IssueLink) error
func SetAnnotationMetadataLinks(ctx context.Context, taskId string, execution int, username string, metadataLinks ...MetadataLink) error

SetAnnotationMetadataLinks sets the metadata links for a task annotation.

func UpdateAnnotationNote

func UpdateAnnotationNote(taskId string, execution int, originalMessage, newMessage, username string) error
func ValidateMetadataLinks(links ...MetadataLink) error

ValidateMetadataLinks will validate the given metadata links, ensuring that they are valid URLs, that their text is not too long, and that there are not more than MaxMetadataLinks links provided.

Types

type IssueLink struct {
	URL string `bson:"url" json:"url"`
	// Text to be displayed
	IssueKey        string  `bson:"issue_key,omitempty" json:"issue_key,omitempty"`
	Source          *Source `bson:"source,omitempty" json:"source,omitempty"`
	ConfidenceScore float64 `bson:"confidence_score,omitempty" json:"confidence_score,omitempty"`
}
type MetadataLink struct {
	// URL to link to
	URL string `bson:"url" json:"url"`
	// Text to be displayed
	Text   string  `bson:"text" json:"text"`
	Source *Source `bson:"source,omitempty" json:"source,omitempty"`
}

MetadataLink represents an arbitrary link to be associated with a task.

type Note

type Note struct {
	Message string  `bson:"message,omitempty" json:"message,omitempty"`
	Source  *Source `bson:"source,omitempty" json:"source,omitempty"`
}

type Source

type Source struct {
	Author    string    `bson:"author,omitempty" json:"author,omitempty"`
	Time      time.Time `bson:"time,omitempty" json:"time,omitempty"`
	Requester string    `bson:"requester,omitempty" json:"requester,omitempty"`
}

type TaskAnnotation

type TaskAnnotation struct {
	Id            string          `bson:"_id" json:"id"`
	TaskId        string          `bson:"task_id" json:"task_id"`
	TaskExecution int             `bson:"task_execution" json:"task_execution"`
	Metadata      *birch.Document `bson:"metadata,omitempty" json:"metadata,omitempty"`
	// comment about the failure
	Note *Note `bson:"note,omitempty" json:"note,omitempty"`
	// links to tickets definitely related.
	Issues []IssueLink `bson:"issues,omitempty" json:"issues,omitempty"`
	// links to tickets possibly related
	SuspectedIssues []IssueLink `bson:"suspected_issues,omitempty" json:"suspected_issues,omitempty"`
	// links to tickets created from the task using a custom web hook
	CreatedIssues []IssueLink `bson:"created_issues,omitempty" json:"created_issues,omitempty"`
	// links to be displayed in the UI metadata sidebar
	MetadataLinks []MetadataLink `bson:"metadata_links,omitempty" json:"metadata_links,omitempty"`
}

func Find

func Find(query db.Q) ([]TaskAnnotation, error)

Find gets every TaskAnnotation matching the given query.

func FindByTaskId

func FindByTaskId(id string) ([]TaskAnnotation, error)

func FindByTaskIds

func FindByTaskIds(ids []string) ([]TaskAnnotation, error)

func FindOne

func FindOne(query db.Q) (*TaskAnnotation, error)

FindOne gets one TaskAnnotation for the given query.

func FindOneByTaskIdAndExecution

func FindOneByTaskIdAndExecution(id string, execution int) (*TaskAnnotation, error)

func GetLatestExecutions

func GetLatestExecutions(annotations []TaskAnnotation) []TaskAnnotation

GetLatestExecutions returns only the latest execution for each task, and filters out earlier executions

func (*TaskAnnotation) Upsert

func (a *TaskAnnotation) Upsert() error

Upsert writes the task_annotation to the database.

type TaskData

type TaskData struct {
	TaskId    string `bson:"task_id" json:"task_id"`
	Execution int    `bson:"execution" json:"execution"`
}

type TaskUpdate

type TaskUpdate struct {
	TaskData   []TaskData     `bson:"task_data" json:"task_data"`
	Annotation TaskAnnotation `bson:"annotation" json:"annotation"`
}

Jump to

Keyboard shortcuts

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