common

package
v0.0.0-...-6a2b81c Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContentTypeApplicationJSON ...
	ContentTypeApplicationJSON string = "application/json"
	// ContentTypeApplicationXWWWFormURLEncoded ...
	ContentTypeApplicationXWWWFormURLEncoded string = "application/x-www-form-urlencoded"
	// DefaultTriggeredBy ...
	DefaultTriggeredBy = "webhook"
)

Variables

This section is empty.

Functions

func GenerateTriggeredBy

func GenerateTriggeredBy(providerID, username string) string

GenerateTriggeredBy ...

func IsSkipBuildByCommitMessage

func IsSkipBuildByCommitMessage(commitMsg string) bool

IsSkipBuildByCommitMessage ...

func OriginalTrigger

func OriginalTrigger(webhookType, webhookAction string) string

OriginalTrigger ...

Types

type Action

type Action string

Action ...

const (
	// PushPushedAction represents a push event.
	PushPushedAction Action = "pushed"
	// PushForcedAction represents a force push event.
	PushForcedAction Action = "forced"
	// PushCreatedAction represents a push event which created a ref.
	PushCreatedAction Action = "created"
	// PushDeletedAction represents a push event which deleted a ref.
	PushDeletedAction Action = "deleted"

	// PullRequestOpenedAction ...
	PullRequestOpenedAction Action = "opened"
	// PullRequestUpdatedAction ...
	PullRequestUpdatedAction Action = "updated"
	// PullRequestClosedAction ...
	PullRequestClosedAction Action = "closed"
	// PullRequestCommentAction ...
	PullRequestCommentAction Action = "comment"
)

type DefaultResponseProvider

type DefaultResponseProvider struct {
}

DefaultResponseProvider ...

func (DefaultResponseProvider) TransformErrorMessageResponse

func (hp DefaultResponseProvider) TransformErrorMessageResponse(errMsg string) TransformResponseModel

TransformErrorMessageResponse ...

func (DefaultResponseProvider) TransformResponse

TransformResponse ...

func (DefaultResponseProvider) TransformSuccessMessageResponse

func (hp DefaultResponseProvider) TransformSuccessMessageResponse(msg string) TransformResponseModel

TransformSuccessMessageResponse ...

type DefaultTransformResponseModel

type DefaultTransformResponseModel struct {
	Errors                       []string                             `json:"errors,omitempty"`
	DidNotWaitForTriggerResponse bool                                 `json:"did_not_wait_for_trigger_response,omitempty"`
	SuccessTriggerResponses      []bitriseapi.TriggerAPIResponseModel `json:"success_responses"`
	FailedTriggerResponses       []bitriseapi.TriggerAPIResponseModel `json:"failed_responses,omitempty"`
	SkippedTriggerResponses      []SkipAPIResponseModel               `json:"skipped_responses,omitempty"`
}

DefaultTransformResponseModel ...

type Event

type Event string

Event ...

const (
	// PushEvent ...
	PushEvent Event = "git_push"
	// PullRequestEvent ...
	PullRequestEvent Event = "pull_request"
)

type GeneralMetrics

type GeneralMetrics struct {
	ProviderType    string     `json:"provider_type,omitempty"`
	Repository      string     `json:"repository,omitempty"` // org/repo
	TimeStamp       time.Time  `json:"timestamp,omitempty"`
	EventTimestamp  *time.Time `json:"event_timestamp,omitempty"`
	AppSlug         string     `json:"app_slug,omitempty"`
	OriginalTrigger string     `json:"original_trigger,omitempty"`
	Username        string     `json:"user_name,omitempty"`
	GitRef          string     `json:"git_ref,omitempty"`
}

GeneralMetrics ...

func NewGeneralMetrics

func NewGeneralMetrics(providerType string, repository string, currentTime time.Time, eventTimestamp *time.Time, appSlug string, originalTrigger string, username string, gitRef string) GeneralMetrics

NewGeneralMetrics ...

type GeneralPullRequestMetrics

type GeneralPullRequestMetrics struct {
	PullRequestTitle string `json:"pull_request_title,omitempty"`
	PullRequestID    string `json:"pull_request_id,omitempty"` // PR number
	PullRequestURL   string `json:"pull_request_url,omitempty"`
	TargetBranch     string `json:"target_branch,omitempty"`
	CommitID         string `json:"commit_id,omitempty"`
	ChangedFiles     int    `json:"changed_files_count"`
	Additions        int    `json:"addition_count"`
	Deletions        int    `json:"deletion_count"`
	Commits          int    `json:"commit_count"`
	MergeCommitSHA   string `json:"merge_commit_sha,omitempty"`
	Status           string `json:"status,omitempty"`
}

GeneralPullRequestMetrics ...

type Metrics

type Metrics interface {
	Serialise() ([]byte, error)
}

Metrics ...

type MetricsProvider

type MetricsProvider interface {
	GatherMetrics(r *http.Request, appSlug string) ([]Metrics, error)
}

MetricsProvider ...

type Provider

type Provider interface {
	// TransformRequest should transform the hook into a bitriseapi.TriggerAPIParamsModel
	//  which can then be called.
	// It might still decide to skip the actual call - for more info
	//  check the docs of TransformResultModel
	TransformRequest(r *http.Request) TransformResultModel
}

Provider ...

type PullRequestCommentMetrics

type PullRequestCommentMetrics struct {
	Event  Event  `json:"event,omitempty"`
	Action Action `json:"action,omitempty"`

	GeneralMetrics
	PullRequestID string `json:"pull_request_id,omitempty"` // PR number
}

PullRequestCommentMetrics ...

func NewPullRequestCommentMetrics

func NewPullRequestCommentMetrics(generalMetrics GeneralMetrics, pullRequestID string) PullRequestCommentMetrics

NewPullRequestCommentMetrics ...

func (PullRequestCommentMetrics) Serialise

func (m PullRequestCommentMetrics) Serialise() ([]byte, error)

Serialise ...

func (PullRequestCommentMetrics) String

func (m PullRequestCommentMetrics) String() string

String ...

type PullRequestMetrics

type PullRequestMetrics struct {
	Event  Event  `json:"event,omitempty"`
	Action Action `json:"action,omitempty"`

	GeneralMetrics
	GeneralPullRequestMetrics
}

PullRequestMetrics ...

func NewPullRequestClosedMetrics

func NewPullRequestClosedMetrics(generalMetrics GeneralMetrics, generalPullRequestMetrics GeneralPullRequestMetrics) PullRequestMetrics

NewPullRequestClosedMetrics ...

func NewPullRequestOpenedMetrics

func NewPullRequestOpenedMetrics(generalMetrics GeneralMetrics, generalPullRequestMetrics GeneralPullRequestMetrics) PullRequestMetrics

NewPullRequestOpenedMetrics ...

func NewPullRequestUpdatedMetrics

func NewPullRequestUpdatedMetrics(generalMetrics GeneralMetrics, generalPullRequestMetrics GeneralPullRequestMetrics) PullRequestMetrics

NewPullRequestUpdatedMetrics ...

func (PullRequestMetrics) Serialise

func (m PullRequestMetrics) Serialise() ([]byte, error)

Serialise ...

func (PullRequestMetrics) String

func (m PullRequestMetrics) String() string

String ...

type PushMetrics

type PushMetrics struct {
	Event  Event  `json:"event,omitempty"`
	Action Action `json:"action,omitempty"`

	GeneralMetrics

	CommitIDAfter         string     `json:"commit_id_after,omitempty"`
	CommitIDBefore        string     `json:"commit_id_before,omitempty"`
	OldestCommitTimestamp *time.Time `json:"oldest_commit_timestamp,omitempty"`
	LatestCommitTimestamp *time.Time `json:"latest_commit_timestamp,omitempty"`
	MasterBranch          string     `json:"master_branch,omitempty"`
	// Prefer setting these fields on a PullRequestMetrics
	ChangedFiles int `json:"changed_files_count"`
	Additions    int `json:"addition_count"`
	Deletions    int `json:"deletion_count"`
}

PushMetrics ...

func NewPushCreatedMetrics

func NewPushCreatedMetrics(generalMetrics GeneralMetrics, commitIDAfter string, commitIDBefore string, oldestCommitTimestamp *time.Time, latestCommitTimestamp *time.Time, masterBranch string) PushMetrics

NewPushCreatedMetrics ...

func NewPushDeletedMetrics

func NewPushDeletedMetrics(generalMetrics GeneralMetrics, commitIDAfter string, commitIDBefore string, oldestCommitTimestamp *time.Time, latestCommitTimestamp *time.Time, masterBranch string) PushMetrics

NewPushDeletedMetrics ...

func NewPushForcedMetrics

func NewPushForcedMetrics(generalMetrics GeneralMetrics, commitIDAfter string, commitIDBefore string, oldestCommitTimestamp *time.Time, latestCommitTimestamp *time.Time, masterBranch string) PushMetrics

NewPushForcedMetrics ...

func NewPushMetrics

func NewPushMetrics(generalMetrics GeneralMetrics, commitIDAfter string, commitIDBefore string, oldestCommitTimestamp *time.Time, latestCommitTimestamp *time.Time, masterBranch string) PushMetrics

NewPushMetrics ...

func (PushMetrics) Serialise

func (m PushMetrics) Serialise() ([]byte, error)

Serialise ...

func (PushMetrics) String

func (m PushMetrics) String() string

String ...

type ResponseTransformer

type ResponseTransformer interface {
	// TransformResponse is called when the hook was successfully
	//  transformed into Bitrise API call(s); both if the actual
	//  Build Trigger was successful or failed.
	TransformResponse(input TransformResponseInputModel) TransformResponseModel
	// TransformErrorMessageResponse is called if an error prevents
	//  any Trigger call (missing parameter, un-transformable hook, ...)
	// If a Build Trigger can be called then `TransformResponse` will be
	//  called, even if the call fails.
	TransformErrorMessageResponse(errMsg string) TransformResponseModel
	// TransformSuccessMessageResponse is called if no Bitrise Trigger API
	//  call(s) can be initiated, but the response is still considered as
	//  success (e.g. if the hook should be skipped, with a success response,
	//   which is the case for GitHub's "ping" hook).
	TransformSuccessMessageResponse(msg string) TransformResponseModel
}

ResponseTransformer ...

type SingleErrorRespModel

type SingleErrorRespModel struct {
	Error string `json:"error"`
}

SingleErrorRespModel ...

type SkipAPIResponseModel

type SkipAPIResponseModel struct {
	Message       string `json:"message"`
	CommitHash    string `json:"commit_hash"`
	CommitMessage string `json:"commit_message"`
	Branch        string `json:"branch"`
}

SkipAPIResponseModel ...

type SuccessRespModel

type SuccessRespModel struct {
	Message string `json:"message"`
}

SuccessRespModel ...

type TimeProvider

type TimeProvider interface {
	CurrentTime() time.Time
}

TimeProvider ...

func NewDefaultTimeProvider

func NewDefaultTimeProvider() TimeProvider

NewDefaultTimeProvider ...

type TransformResponseInputModel

type TransformResponseInputModel struct {
	// Errors include the errors if the build could not trigger
	Errors []string

	// DidNotWaitForTriggerResponse if true it means that the TriggerResponses were not populated,
	//  as the provider requested to skip waiting for the Trigger API call's response/result.
	DidNotWaitForTriggerResponse bool

	// SuccessTriggerResponses include the successful trigger call responses
	SuccessTriggerResponses []bitriseapi.TriggerAPIResponseModel
	// FailedTriggerResponses include the trigger calls which were performed,
	//  but the response had a non success HTTP status code
	FailedTriggerResponses []bitriseapi.TriggerAPIResponseModel
	// SkippedTriggerResponses include responses for the trigger calls
	//  that were skipped
	SkippedTriggerResponses []SkipAPIResponseModel
}

TransformResponseInputModel ...

type TransformResponseModel

type TransformResponseModel struct {
	// Data will be transformed into JSON, and returned as the response.
	Data interface{}
	// HTTPStatusCode if specified (!= 0) will be used as the respone's
	//  HTTP response status code.
	HTTPStatusCode int
}

TransformResponseModel ...

type TransformResultModel

type TransformResultModel struct {
	// TriggerAPIParams is the transformed Bitrise Trigger API params
	TriggerAPIParams []bitriseapi.TriggerAPIParamsModel
	// ShouldSkip if true then no build should be started for this webhook
	//  but we should respond with a succcess HTTP status code
	ShouldSkip bool
	// Error in transforming the hook. If ShouldSkip=true this is
	//  the reason why the hook should be skipped.
	Error error
	// DontWaitForTriggerResponse if true the Trigger API request will be sent,
	//  but the handler won't wait for the response from the Trigger API,
	//  it'll respond immediately after calling the Trigger API
	DontWaitForTriggerResponse bool
	// Used for logging if only pull request description contains [skip ci] or
	//  [ci skip] but title doesn't
	SkippedByPrDescription bool
}

TransformResultModel ...

Jump to

Keyboard shortcuts

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