bitbucket

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ChangeTypes defines the possible types of changes in a pull request.
	// TODO: move to global config
	ChangeTypes = []string{"ADD", "MODIFY"}
)

Functions

func ExtractCloneLinks(clones []CloneLink) (httpLink, sshLink string)

ExtractCloneLinks parses the clone links from the repository information and returns the HTTP and SSH URLs.

Types

type Attachment

type Attachment struct {
	ID    string `json:"id"`
	URL   string `json:"url"`
	Links struct {
		Self       Link `json:"self,omitempty"`
		Attachment Link `json:"attachment,omitempty"`
	} `json:"links"`
}

Attachments represents an attachment with associated links.

type AttachmentRoot

type AttachmentRoot struct {
	Attachments []Attachment `json:"attachments"`
}

AttachmentRoot represents the root structure of the attachment's JSON response.

type AuthInfo

type AuthInfo struct {
	Username string // Username for Bitbucket access
	Token    string // Token for basic authentication
}

AuthInfo holds authentication details for Bitbucket access.

type Change

type Change struct {
	ContentID        string                   `json:"contentId"`
	FromContentID    string                   `json:"fromContentId"`
	Path             *File                    `json:"path,omitempty"`
	Executable       bool                     `json:"executable,omitempty"`
	Type             string                   `json:"type"`
	NodeType         string                   `json:"nodeType"`
	PercentUnchanged int                      `json:"percentUnchanged,omitempty"`
	Links            Links                    `json:"links,omitempty"`
	Properties       *ChangesPropertiesValues `json:"properties"`
}

Change details a single file change within a repository, providing metadata about the modification.

type ChangesProperties

type ChangesProperties struct {
	ChangeScope string `json:"changeScope"`
}

ChangesProperties defines properties associated with a set of changes, typically related to the scope.

type ChangesPropertiesValues

type ChangesPropertiesValues struct {
	ChangeScope string `json:"changeScope"`
}

ChangesPropertiesValues holds detailed values for properties associated with a single change.

type ChangesResponse

type ChangesResponse[T any] struct {
	Response[T]
	FromHash   string             `json:"fromHash"`
	ToHash     string             `json:"toHash"`
	Properties *ChangesProperties `json:"properties"`
}

ChangesResponse represents a collection of change details within a git context.

type Client

type Client struct {
	HTTPClient   *httpclient.Client
	BaseURL      string
	Logger       hclog.Logger
	Repositories RepositoriesService
	Projects     ProjectsService
	PullRequests PullRequestsService
}

Client configures and manages access to the API, holding service implementations and an HTTP client.

func New

func New(globalConfig *config.Config, logger hclog.Logger, domain string, auth AuthInfo) (*Client, error)

New initializes a new API client with configured services.

type CloneLink struct {
	Href string `json:"href"`
	Name string `json:"name"`
}

CloneLink represents a link to clone the repository.

type Error

type Error struct {
	Context       string `json:"context"`
	Message       string `json:"message"`
	ExceptionName string `json:"exceptionName"`
}

Error provides detailed information about an error occurred during API interactions.

type ErrorList

type ErrorList struct {
	Errors []Error `json:"errors"`
}

ErrorList encapsulates potential API error responses.

type File

type File struct {
	Components []string `json:"components"`
	Parent     string   `json:"parent"`
	Name       string   `json:"name"`
	Extension  string   `json:"extension"`
	ToString   string   `json:"toString"`
}

File represents a file within a repository showing its structure and metadata.

type Link struct {
	Href string `json:"href,omitempty"`
}

Link represents a direct link to the resource itself.

type Links struct {
	Clone []CloneLink `json:"clone,omitempty"`
	Self  []Link      `json:"self,omitempty"`
}

Links stores URLs for accessing related resources.

type MergeResult

type MergeResult struct {
	Outcome string `json:"outcome"`
	Current bool   `json:"current"`
}

MergeResult encapsulates the result of a merge attempt in a pull request.

type Project

type Project struct {
	Key         string `json:"key"`
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Public      bool   `json:"public,omitempty"`
	Type        string `json:"type"`
	Links       Links  `json:"links"`
}

Project represents a project within Bitbucket, providing a container for repositories.

type ProjectsService

type ProjectsService interface {
	List() (*[]Project, error)
}

ProjectsService defines the interface for project-related operations.

func NewProjectsService

func NewProjectsService(client *Client, limit int) ProjectsService

NewProjectsService initializes a new projects service with a given pagination limit.

type PullRequest

type PullRequest struct {
	ID            int        `json:"id"`
	Version       int        `json:"version"`
	Title         string     `json:"title"`
	Description   string     `json:"description"`
	State         string     `json:"state"`
	Open          bool       `json:"open,omitempty"`
	Closed        bool       `json:"closed,omitempty"`
	CreatedDate   int64      `json:"createdDate"`
	UpdatedDate   int64      `json:"updatedDate"`
	FromReference Reference  `json:"fromRef"`
	ToReference   Reference  `json:"toRef"`
	Locked        bool       `json:"locked,omitempty"`
	Author        *UserData  `json:"author,omitempty"`
	Reviewers     []UserData `json:"reviewers"`
	Participants  []UserData `json:"participants,omitempty"`
	Properties    struct {
		MergeResult       MergeResult `json:"mergeResult"`
		ResolvedTaskCount int         `json:"resolvedTaskCount"`
		OpenTaskCount     int         `json:"openTaskCount"`
	} `json:"properties"`
	Links Links `json:"links"`
	// contains filtered or unexported fields
}

PullRequest defines the basic structure of a pull request within Bitbucket.

func (*PullRequest) AddComment

func (pr *PullRequest) AddComment(commentText string, paths []string) (*PullRequest, error)

AddComment adds a comment to a specific pull request along with optional file attachments.

func (*PullRequest) AddRole

func (pr *PullRequest) AddRole(role, login string) (*UserData, error)

AddRole adds a user to a pull request with a specified role.

func (*PullRequest) AttachFileToRepository

func (pr *PullRequest) AttachFileToRepository(path string) (*Attachment, string, error)

AttachFileToRepository uploads a file to a specific repository and returns the attachment details and file name.

func (*PullRequest) GetChanges

func (pr *PullRequest) GetChanges() (*[]Change, error)

GetChanges retrieves the changes for a pull request.

func (*PullRequest) SetStatus

func (pr *PullRequest) SetStatus(status, login string) (*PullRequest, error)

SetStatus sets the status of a specified pull request.

type PullRequestsService

type PullRequestsService interface {
	Get(project, repository string, id int) (*PullRequest, error)
}

PullRequestsService defines the interface for pull request-related operations.

func NewPullRequestsService

func NewPullRequestsService(client *Client, limit int) PullRequestsService

NewPullRequestsService initializes a new pull requests service with a given pagination limit.

type Reference

type Reference struct {
	ID           string     `json:"id"`
	DisplayID    string     `json:"displayId"`
	LatestCommit string     `json:"latestCommit"`
	Repository   Repository `json:"repository"`
}

Reference represents a specific state or reference point in a repository.

type RepositoriesService

type RepositoriesService interface {
	List(project string) (*[]Repository, error)
	ListUserRepos(username string) (*[]Repository, error)
}

RepositoriesService defines the interface for repository-related operations.

func NewRepositoriesService

func NewRepositoriesService(client *Client, limit int) RepositoriesService

NewRepositoriesService initializes a new repositories service with a given pagination limit.

type Repository

type Repository struct {
	Slug          string      `json:"slug"`
	ID            int         `json:"id"`
	Name          string      `json:"name"`
	Description   string      `json:"description"`
	HierarchyID   string      `json:"hierarchyId"`
	ScmID         string      `json:"scmId"`
	State         string      `json:"state"`
	StatusMessage string      `json:"statusMessage"`
	Forkable      bool        `json:"forkable,omitempty"`
	Project       *Project    `json:"project,omitempty"`
	Public        bool        `json:"public"`
	Archived      bool        `json:"archived,omitempty"`
	Links         Links       `json:"links"`
	Origin        *Repository `json:"origin,omitempty"`
}

Repository represents a repository in Bitbucket, including its project container and metadata.

type Response

type Response[T any] struct {
	NextPageStart *int `json:"nextPageStart"`
	IsLastPage    bool `json:"isLastPage"`
	Limit         int  `json:"limit"`
	Size          int  `json:"size"`
	Start         int  `json:"start"`
	Values        []T  `json:"values"`
}

Response wraps API responses that include pagination details.

type User

type User struct {
	Name         string `json:"name,omitempty"`
	EmailAddress string `json:"emailAddress,omitempty"`
	ID           int    `json:"id,omitempty"`
	DisplayName  string `json:"displayName,omitempty"`
	Active       bool   `json:"active,omitempty"`
	Slug         string `json:"slug,omitempty"`
	Type         string `json:"type,omitempty"`
	Links        Links  `json:"links,omitempty"`
}

User represents a user within Bitbucket.

type UserData

type UserData struct {
	User               User   `json:"user,omitempty"`
	Role               string `json:"role,omitempty"`
	Approved           bool   `json:"approved,omitempty"`
	Status             string `json:"status,omitempty"`
	LastReviewedCommit string `json:"lastReviewedCommit,omitempty"`
}

UserData holds information about a user.

Jump to

Keyboard shortcuts

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