Documentation
¶
Overview ¶
Package devlake provides an HTTP client for the DevLake REST API.
Index ¶
- func ExtractScopeID(raw json.RawMessage, fieldName string) string
- func PrintState(state *State)
- func SaveState(path string, state *State) error
- func UpdateConnections(path string, state *State, connections []StateConnection) error
- type ArgoCDAppScope
- type BitbucketRepoScope
- type Blueprint
- type BlueprintConnection
- type BlueprintPatch
- type BlueprintScope
- type CircleCIProjectScope
- type Client
- func (c *Client) CreateConnection(plugin string, req *ConnectionCreateRequest) (*Connection, error)
- func (c *Client) CreateProject(project *Project) (*Project, error)
- func (c *Client) CreateScopeConfig(plugin string, connID int, cfg *ScopeConfig) (*ScopeConfig, error)
- func (c *Client) DeleteConnection(plugin string, connID int) error
- func (c *Client) DeleteProject(name string) error
- func (c *Client) DeleteScope(plugin string, connID int, scopeID string) error
- func (c *Client) FindConnectionByName(plugin, name string) (*Connection, error)
- func (c *Client) GetConnection(plugin string, connID int) (*Connection, error)
- func (c *Client) GetPipeline(id int) (*Pipeline, error)
- func (c *Client) GetProject(name string) (*Project, error)
- func (c *Client) Health() (*HealthStatus, error)
- func (c *Client) ListConnections(plugin string) ([]Connection, error)
- func (c *Client) ListProjects() ([]Project, error)
- func (c *Client) ListRemoteScopes(plugin string, connID int, groupID, pageToken string) (*RemoteScopeResponse, error)
- func (c *Client) ListScopeConfigs(plugin string, connID int) ([]ScopeConfig, error)
- func (c *Client) ListScopes(plugin string, connID int) (*ScopeListResponse, error)
- func (c *Client) PatchBlueprint(id int, patch *BlueprintPatch) (*Blueprint, error)
- func (c *Client) Ping() error
- func (c *Client) PutScopes(plugin string, connID int, req *ScopeBatchRequest) error
- func (c *Client) SearchRemoteScopes(plugin string, connID int, search string, page, pageSize int) (*RemoteScopeResponse, error)
- func (c *Client) TestConnection(plugin string, req *ConnectionTestRequest) (*ConnectionTestResult, error)
- func (c *Client) TestSavedConnection(plugin string, connID int) (*ConnectionTestResult, error)
- func (c *Client) TriggerBlueprint(id int) (*Pipeline, error)
- func (c *Client) TriggerMigration() error
- func (c *Client) UpdateConnection(plugin string, connID int, req *ConnectionUpdateRequest) (*Connection, error)
- type Connection
- type ConnectionCreateRequest
- type ConnectionTestRequest
- type ConnectionTestResult
- type ConnectionUpdateRequest
- type CopilotScope
- type DiscoveryResult
- type GitHubRepoScope
- type GitLabProjectScope
- type HealthStatus
- type JenkinsJobScope
- type JiraBoardScope
- type PagerDutyServiceScope
- type Pipeline
- type Project
- type ProjectListResponse
- type ProjectMetric
- type RefdiffConfig
- type RemoteScopeChild
- type RemoteScopeResponse
- type ScopeBatchRequest
- type ScopeConfig
- type ScopeListResponse
- type ScopeListWrapper
- type SonarQubeProjectScope
- type State
- type StateConnection
- type StateEndpoints
- type StateProject
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 ¶
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
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 ¶
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 ¶
Client wraps HTTP calls to the DevLake backend API.
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 ¶
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
DeleteConnection deletes a plugin connection by ID.
func (*Client) DeleteProject ¶ added in v0.3.10
DeleteProject deletes a project by name.
func (*Client) DeleteScope ¶ added in v0.3.10
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 ¶
GetPipeline retrieves a pipeline by ID.
func (*Client) GetProject ¶
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
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) 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 ¶
TriggerBlueprint triggers a blueprint to run and returns the pipeline.
func (*Client) TriggerMigration ¶ added in v0.2.0
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 ¶
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
ProjectListResponse is the response from GET /projects.
type ProjectMetric ¶
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 ¶
FindStateFile finds the first existing state file in the working directory. Returns the path and loaded state, or creates a new local state.
func LoadStateFromCwd ¶ added in v0.3.8
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.