devlake

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 11 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 ExtractScopeID added in v0.4.0

func ExtractScopeID(raw json.RawMessage, fieldName string) string

ExtractScopeID extracts the scope ID from a raw JSON scope object using the given field name. It tries to decode the value as a string first, then as an integer (converted to its decimal string representation).

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, merging with any existing fields in the file (e.g. Azure deployment metadata) that the State struct doesn't model.

func UpdateConnections

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

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

Types

type ArgoCDAppScope added in v0.4.0

type ArgoCDAppScope struct {
	ConnectionID int    `json:"connectionId"`
	Name         string `json:"name"`
}

ArgoCDAppScope represents an ArgoCD application scope entry for PUT /scopes.

type BitbucketRepoScope added in v0.4.0

type BitbucketRepoScope struct {
	BitbucketID  string `json:"bitbucketId"`
	ConnectionID int    `json:"connectionId"`
	Name         string `json:"name"`
	FullName     string `json:"fullName"`
	CloneURL     string `json:"cloneUrl,omitempty"`
	HTMLURL      string `json:"htmlUrl,omitempty"`
}

BitbucketRepoScope represents a Bitbucket Cloud repository scope entry for PUT /scopes. BitbucketID holds the repository full name (workspace/repo-slug), which is the canonical scope identifier used by the DevLake Bitbucket plugin.

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"`
	Mode        string                `json:"mode,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 CircleCIProjectScope added in v0.4.0

type CircleCIProjectScope struct {
	ConnectionID   int    `json:"connectionId"`
	ID             string `json:"id"`
	Slug           string `json:"slug"`
	Name           string `json:"name"`
	OrganizationID string `json:"organizationId"`
}

CircleCIProjectScope represents a CircleCI project scope entry for PUT /scopes.

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) DeleteConnection added in v0.3.5

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

DeleteConnection deletes a plugin connection by ID.

func (*Client) DeleteProject added in v0.3.10

func (c *Client) DeleteProject(name string) error

DeleteProject deletes a project by name.

func (*Client) DeleteScope added in v0.3.10

func (c *Client) DeleteScope(plugin string, connID int, scopeID string) error

DeleteScope removes a scope from 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) GetConnection added in v0.3.5

func (c *Client) GetConnection(plugin string, connID int) (*Connection, error)

GetConnection retrieves a single connection by plugin and ID.

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) ListProjects added in v0.3.10

func (c *Client) ListProjects() ([]Project, error)

ListProjects returns all DevLake projects.

func (*Client) ListRemoteScopes added in v0.4.0

func (c *Client) ListRemoteScopes(plugin string, connID int, groupID, pageToken string) (*RemoteScopeResponse, error)

ListRemoteScopes queries the DevLake remote-scope API for a plugin connection. groupID and pageToken are optional (pass "" to omit).

func (*Client) ListScopeConfigs

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

ListScopeConfigs returns all scope configs for a plugin connection.

func (*Client) ListScopes added in v0.3.7

func (c *Client) ListScopes(plugin string, connID int) (*ScopeListResponse, error)

ListScopes returns the scopes configured on 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) SearchRemoteScopes added in v0.4.0

func (c *Client) SearchRemoteScopes(plugin string, connID int, search string, page, pageSize int) (*RemoteScopeResponse, error)

SearchRemoteScopes queries the DevLake search-remote-scopes API for a plugin connection. page and pageSize control pagination; pass 0 to use DevLake defaults.

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.

func (*Client) UpdateConnection added in v0.3.5

func (c *Client) UpdateConnection(plugin string, connID int, req *ConnectionUpdateRequest) (*Connection, error)

UpdateConnection patches an existing connection for the given plugin.

type Connection

type Connection struct {
	ID           int    `json:"id"`
	Name         string `json:"name"`
	Endpoint     string `json:"endpoint,omitempty"`
	Proxy        string `json:"proxy,omitempty"`
	Token        string `json:"token,omitempty"`
	Organization string `json:"organization,omitempty"`
	Enterprise   string `json:"enterprise,omitempty"`
}

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,omitempty"`
	Username              string `json:"username,omitempty"`
	Password              string `json:"password,omitempty"`
	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 plugin connection.

type ConnectionTestRequest

type ConnectionTestRequest struct {
	Name             string `json:"name"`
	Endpoint         string `json:"endpoint"`
	AuthMethod       string `json:"authMethod"`
	Token            string `json:"token,omitempty"`
	Username         string `json:"username,omitempty"`
	Password         string `json:"password,omitempty"`
	EnableGraphql    bool   `json:"enableGraphql,omitempty"`
	RateLimitPerHour int    `json:"rateLimitPerHour"`
	Proxy            string `json:"proxy"`
	Organization     string `json:"organization,omitempty"`
	Enterprise       string `json:"enterprise,omitempty"`
}

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 ConnectionUpdateRequest added in v0.3.5

type ConnectionUpdateRequest struct {
	Name         string `json:"name,omitempty"`
	Endpoint     string `json:"endpoint,omitempty"`
	Proxy        string `json:"proxy,omitempty"`
	AuthMethod   string `json:"authMethod,omitempty"`
	Token        string `json:"token,omitempty"`
	Organization string `json:"organization,omitempty"`
	Enterprise   string `json:"enterprise,omitempty"`
}

ConnectionUpdateRequest is the payload for PATCH /plugins/{plugin}/connections/{id}. Fields with omitempty are only included in the request when non-empty, enabling sparse updates (only changed fields are sent).

type CopilotScope

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

CopilotScope represents a Copilot organization or enterprise scope entry.

type DiscoveryResult

type DiscoveryResult struct {
	URL         string
	GrafanaURL  string
	ConfigUIURL 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 GitLabProjectScope added in v0.4.0

type GitLabProjectScope struct {
	GitlabID          int    `json:"gitlabId"`
	ConnectionID      int    `json:"connectionId"`
	Name              string `json:"name"`
	PathWithNamespace string `json:"pathWithNamespace"`
	HTTPURLToRepo     string `json:"httpUrlToRepo,omitempty"`
	SSHURLToRepo      string `json:"sshUrlToRepo,omitempty"`
	ScopeConfigID     int    `json:"scopeConfigId,omitempty"`
}

GitLabProjectScope represents a GitLab project scope entry for PUT /scopes.

type HealthStatus

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

HealthStatus represents the response from /health or /ping.

type JenkinsJobScope added in v0.4.0

type JenkinsJobScope struct {
	ConnectionID int    `json:"connectionId"`
	FullName     string `json:"fullName"`
	Name         string `json:"name"`
}

JenkinsJobScope represents a Jenkins job scope entry.

type JiraBoardScope added in v0.4.0

type JiraBoardScope struct {
	BoardID      uint64 `json:"boardId"`
	ConnectionID int    `json:"connectionId"`
	Name         string `json:"name"`
}

JiraBoardScope represents a Jira board scope entry for PUT /scopes.

type PagerDutyServiceScope added in v0.4.0

type PagerDutyServiceScope struct {
	ConnectionID int    `json:"connectionId"`
	ID           string `json:"id"`
	Name         string `json:"name"`
	URL          string `json:"url,omitempty"`
}

PagerDutyServiceScope represents a PagerDuty service scope entry for PUT /scopes.

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 ProjectListResponse added in v0.3.10

type ProjectListResponse struct {
	Count    int       `json:"count"`
	Projects []Project `json:"projects"`
}

ProjectListResponse is the response from GET /projects.

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 RemoteScopeChild added in v0.4.0

type RemoteScopeChild struct {
	Type     string          `json:"type"` // "group" or "scope"
	ID       string          `json:"id"`
	ParentID string          `json:"parentId"`
	Name     string          `json:"name"`
	FullName string          `json:"fullName"`
	Data     json.RawMessage `json:"data"`
}

RemoteScopeChild represents one item (group or scope) from the remote-scope API.

type RemoteScopeResponse added in v0.4.0

type RemoteScopeResponse struct {
	Children      []RemoteScopeChild `json:"children"`
	NextPageToken string             `json:"nextPageToken"`
}

RemoteScopeResponse is the response from GET /plugins/{plugin}/connections/{id}/remote-scopes.

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 ScopeListResponse added in v0.3.7

type ScopeListResponse struct {
	Scopes []ScopeListWrapper `json:"scopes"`
	Count  int                `json:"count"`
}

ScopeListResponse is the response from GET /plugins/{plugin}/connections/{id}/scopes.

type ScopeListWrapper added in v0.3.7

type ScopeListWrapper struct {
	RawScope json.RawMessage `json:"scope"`
	// contains filtered or unexported fields
}

ScopeListWrapper wraps a scope object as returned by the DevLake GET scopes API. The API nests each scope inside a "scope" key: { "scope": { ... } }. RawScope preserves the full plugin-specific payload for generic ID extraction.

func (*ScopeListWrapper) ScopeFullName added in v0.4.0

func (w *ScopeListWrapper) ScopeFullName() string

ScopeFullName returns the "fullName" field from the raw scope JSON, or "". An empty string value is treated as absent (returns "").

func (*ScopeListWrapper) ScopeName added in v0.4.0

func (w *ScopeListWrapper) ScopeName() string

ScopeName returns the display name from the raw scope JSON (checks "fullName" then "name"). Empty string values are skipped so the next candidate key is tried. Parsing is cached via parseScope() so calling ScopeName and ScopeFullName on the same instance only unmarshals the JSON once.

type SonarQubeProjectScope added in v0.4.0

type SonarQubeProjectScope struct {
	ConnectionID int    `json:"connectionId"`
	ProjectKey   string `json:"projectKey"`
	Name         string `json:"name"`
}

SonarQubeProjectScope represents a SonarQube project scope entry for PUT /scopes.

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.

func LoadStateFromCwd added in v0.3.8

func LoadStateFromCwd() (*State, error)

LoadStateFromCwd loads the first known state file from the current directory. Returns nil,nil when no state file exists.

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