devlake

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package devlake provides an HTTP client for the DevLake REST API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintState

func PrintState(state *State)

PrintState prints a human-readable summary of the state.

func SaveState

func SaveState(path string, state *State) error

SaveState writes state to disk.

func UpdateConnections

func UpdateConnections(path string, state *State, connections []StateConnection) error

UpdateConnections updates the connections in the state and saves to disk.

Types

type Blueprint

type Blueprint struct {
	ID          int                   `json:"id"`
	Name        string                `json:"name,omitempty"`
	Enable      bool                  `json:"enable,omitempty"`
	CronConfig  string                `json:"cronConfig,omitempty"`
	TimeAfter   string                `json:"timeAfter,omitempty"`
	Connections []BlueprintConnection `json:"connections,omitempty"`
}

Blueprint represents a DevLake blueprint (returned from project creation or GET).

type BlueprintConnection

type BlueprintConnection struct {
	PluginName   string           `json:"pluginName"`
	ConnectionID int              `json:"connectionId"`
	Scopes       []BlueprintScope `json:"scopes"`
}

BlueprintConnection associates a plugin connection with scopes in a blueprint.

type BlueprintPatch

type BlueprintPatch struct {
	Enable      *bool                 `json:"enable,omitempty"`
	CronConfig  string                `json:"cronConfig,omitempty"`
	TimeAfter   string                `json:"timeAfter,omitempty"`
	Connections []BlueprintConnection `json:"connections,omitempty"`
}

BlueprintPatch is the payload for PATCH /blueprints/:id.

type BlueprintScope

type BlueprintScope struct {
	ScopeID   string `json:"scopeId"`
	ScopeName string `json:"scopeName"`
}

BlueprintScope identifies a single scope within a blueprint connection.

type Client

type Client struct {
	BaseURL    string
	HTTPClient *http.Client
}

Client wraps HTTP calls to the DevLake backend API.

func NewClient

func NewClient(baseURL string) *Client

NewClient creates a Client for the given base URL.

func (*Client) CreateConnection

func (c *Client) CreateConnection(plugin string, req *ConnectionCreateRequest) (*Connection, error)

CreateConnection creates a new connection for the given plugin.

func (*Client) CreateProject

func (c *Client) CreateProject(project *Project) (*Project, error)

CreateProject creates a new DevLake project.

func (*Client) CreateScopeConfig

func (c *Client) CreateScopeConfig(plugin string, connID int, cfg *ScopeConfig) (*ScopeConfig, error)

CreateScopeConfig creates a scope config for a plugin connection.

func (*Client) FindConnectionByName

func (c *Client) FindConnectionByName(plugin, name string) (*Connection, error)

FindConnectionByName returns the first connection matching the given name, or nil.

func (*Client) GetPipeline

func (c *Client) GetPipeline(id int) (*Pipeline, error)

GetPipeline retrieves a pipeline by ID.

func (*Client) GetProject

func (c *Client) GetProject(name string) (*Project, error)

GetProject retrieves a project by name.

func (*Client) Health

func (c *Client) Health() (*HealthStatus, error)

Health returns the DevLake health status.

func (*Client) ListConnections

func (c *Client) ListConnections(plugin string) ([]Connection, error)

ListConnections returns all connections for a plugin (e.g. "github", "gh-copilot").

func (*Client) ListScopeConfigs

func (c *Client) ListScopeConfigs(plugin string, connID int) ([]ScopeConfig, error)

ListScopeConfigs returns all scope configs for a plugin connection.

func (*Client) PatchBlueprint

func (c *Client) PatchBlueprint(id int, patch *BlueprintPatch) (*Blueprint, error)

PatchBlueprint updates a blueprint by ID.

func (*Client) Ping

func (c *Client) Ping() error

Ping checks if the DevLake backend is reachable.

func (*Client) PutScopes

func (c *Client) PutScopes(plugin string, connID int, req *ScopeBatchRequest) error

PutScopes batch-upserts scopes for a plugin connection.

func (*Client) TestConnection

func (c *Client) TestConnection(plugin string, req *ConnectionTestRequest) (*ConnectionTestResult, error)

TestConnection tests connection parameters before creating.

func (*Client) TestSavedConnection

func (c *Client) TestSavedConnection(plugin string, connID int) (*ConnectionTestResult, error)

TestSavedConnection tests an already-created connection by ID.

func (*Client) TriggerBlueprint

func (c *Client) TriggerBlueprint(id int) (*Pipeline, error)

TriggerBlueprint triggers a blueprint to run and returns the pipeline.

func (*Client) TriggerMigration added in v0.2.0

func (c *Client) TriggerMigration() error

TriggerMigration triggers the DevLake database migration endpoint.

type Connection

type Connection struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Connection represents a DevLake plugin connection.

type ConnectionCreateRequest

type ConnectionCreateRequest struct {
	Name                  string `json:"name"`
	Endpoint              string `json:"endpoint"`
	Proxy                 string `json:"proxy,omitempty"`
	AuthMethod            string `json:"authMethod"`
	Token                 string `json:"token"`
	EnableGraphql         bool   `json:"enableGraphql,omitempty"`
	RateLimitPerHour      int    `json:"rateLimitPerHour"`
	Organization          string `json:"organization,omitempty"`
	Enterprise            string `json:"enterprise,omitempty"`
	TokenExpiresAt        string `json:"tokenExpiresAt,omitempty"`
	RefreshTokenExpiresAt string `json:"refreshTokenExpiresAt,omitempty"`
}

ConnectionCreateRequest is the payload for creating a GitHub or Copilot connection.

type ConnectionTestRequest

type ConnectionTestRequest struct {
	Endpoint         string `json:"endpoint"`
	AuthMethod       string `json:"authMethod"`
	Token            string `json:"token"`
	EnableGraphql    bool   `json:"enableGraphql,omitempty"`
	RateLimitPerHour int    `json:"rateLimitPerHour"`
	Proxy            string `json:"proxy"`
}

ConnectionTestRequest is the payload for testing a connection before creating.

type ConnectionTestResult

type ConnectionTestResult struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
}

ConnectionTestResult is the response from testing a connection.

type CopilotScope

type CopilotScope struct {
	ID           string `json:"id"`
	ConnectionID int    `json:"connectionId"`
	Organization string `json:"organization"`
	Name         string `json:"name"`
	FullName     string `json:"fullName"`
}

CopilotScope represents a Copilot organization scope entry.

type DiscoveryResult

type DiscoveryResult struct {
	URL        string
	GrafanaURL string
	Source     string // "parameter", "statefile", "localhost"
}

DiscoveryResult contains the discovered DevLake instance details.

func Discover

func Discover(explicitURL string) (*DiscoveryResult, error)

Discover finds a running DevLake instance by checking multiple sources. Priority: explicit URL → state files → well-known localhost ports.

type GitHubRepoScope

type GitHubRepoScope struct {
	GithubID      int    `json:"githubId"`
	ConnectionID  int    `json:"connectionId"`
	Name          string `json:"name"`
	FullName      string `json:"fullName"`
	HTMLURL       string `json:"htmlUrl"`
	CloneURL      string `json:"cloneUrl"`
	ScopeConfigID int    `json:"scopeConfigId,omitempty"`
}

GitHubRepoScope represents a GitHub repository scope entry for PUT /scopes.

type HealthStatus

type HealthStatus struct {
	Status string `json:"status"`
}

HealthStatus represents the response from /health or /ping.

type Pipeline

type Pipeline struct {
	ID            int    `json:"id"`
	Status        string `json:"status"`
	FinishedTasks int    `json:"finishedTasks"`
	TotalTasks    int    `json:"totalTasks"`
}

Pipeline represents a DevLake pipeline (returned from trigger or GET).

type Project

type Project struct {
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	Metrics     []ProjectMetric `json:"metrics,omitempty"`
	Blueprint   *Blueprint      `json:"blueprint,omitempty"`
}

Project represents a DevLake project.

type ProjectMetric

type ProjectMetric struct {
	PluginName string `json:"pluginName"`
	Enable     bool   `json:"enable"`
}

ProjectMetric enables a metric plugin for a project.

type RefdiffConfig

type RefdiffConfig struct {
	TagsPattern string `json:"tagsPattern"`
	TagsLimit   int    `json:"tagsLimit"`
	TagsOrder   string `json:"tagsOrder"`
}

RefdiffConfig holds refdiff tag-matching settings.

type ScopeBatchRequest

type ScopeBatchRequest struct {
	Data []any `json:"data"`
}

ScopeBatchRequest is the payload for PUT /scopes (batch upsert).

type ScopeConfig

type ScopeConfig struct {
	ID                int            `json:"id,omitempty"`
	Name              string         `json:"name"`
	ConnectionID      int            `json:"connectionId"`
	DeploymentPattern string         `json:"deploymentPattern,omitempty"`
	ProductionPattern string         `json:"productionPattern,omitempty"`
	IssueTypeIncident string         `json:"issueTypeIncident,omitempty"`
	Refdiff           *RefdiffConfig `json:"refdiff,omitempty"`
}

ScopeConfig represents a DevLake scope configuration (e.g., DORA settings).

type State

type State struct {
	DeployedAt              string            `json:"deployedAt"`
	Method                  string            `json:"method"`
	Endpoints               StateEndpoints    `json:"endpoints"`
	Connections             []StateConnection `json:"connections,omitempty"`
	ConnectionsConfiguredAt string            `json:"connectionsConfiguredAt,omitempty"`
	Project                 *StateProject     `json:"project,omitempty"`
	ScopesConfiguredAt      string            `json:"scopesConfiguredAt,omitempty"`
}

State represents the persisted deployment/connection state.

func FindStateFile

func FindStateFile(apiURL, grafanaURL string) (string, *State)

FindStateFile finds the first existing state file in the working directory. Returns the path and loaded state, or creates a new local state.

func LoadState

func LoadState(path string) (*State, error)

LoadState reads a state file from disk. Returns nil if not found.

type StateConnection

type StateConnection struct {
	Plugin       string `json:"plugin"`
	ConnectionID int    `json:"connectionId"`
	Name         string `json:"name"`
	Organization string `json:"organization,omitempty"`
	Enterprise   string `json:"enterprise,omitempty"`
}

StateConnection records a created connection.

type StateEndpoints

type StateEndpoints struct {
	Backend  string `json:"backend"`
	Grafana  string `json:"grafana,omitempty"`
	ConfigUI string `json:"configUi,omitempty"`
}

StateEndpoints contains service URLs.

type StateProject

type StateProject struct {
	Name         string   `json:"name"`
	BlueprintID  int      `json:"blueprintId"`
	Repos        []string `json:"repos,omitempty"`
	Organization string   `json:"organization,omitempty"`
}

StateProject records project and blueprint info after scope configuration.

Jump to

Keyboard shortcuts

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