git

package
v0.0.0-...-7112f6d Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: GPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package git contains the management of changes' pipelines as git abstractions It's the main actor on performing CRUD actions over remote

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreCompatible

func AreCompatible(chg, otherChg *Change) bool

AreCompatible checks if two changes could be joint to perform any action

func Overrides

func Overrides(chg, otherChg *Change) bool

Overrides check if changes are overridable by each other

Types

type Branch

type Branch struct {
	Id   int64  `json:"id,omitempty"`
	Name string `json:"name,omitempty"`

	Credentials credentials

	Index *Index `json:"index,omitempty"`

	IndexId int64 `json:"index_id,omitempty"`
}

Branch is the state-manager around indices

func BranchByName

func BranchByName(ctx context.Context, db *sqlx.DB, branchName integrity.BranchName) (*Branch, error)

BranchByName finds a branch in the DB given its name

func NewBranchWithIndex

func NewBranchWithIndex(ctx context.Context, db *sqlx.DB, name integrity.BranchName) (*Branch, error)

NewBranchWithIndex safety creates a new Branch entity and assigns a new index_id to it Notice it persists on the db and assigns the inserted id

func (*Branch) FetchIndex

func (b *Branch) FetchIndex(ctx context.Context, db *sqlx.DB) error

FetchIndex retrieves the Index by .IndexId and assigns it to .Index field

func (*Branch) GetId

func (b *Branch) GetId() int64

GetId wraps the id retrieval to implement Storable interface

func (*Branch) SQLColumns

func (b *Branch) SQLColumns() []string

SQLColumns returns the SQLColumns each field represent on db Notice the returned slice is the list of struct tags of exported fields It's done to avoid reflection

Testing: tested by using reflection at Columns_Test to check being the tags

func (*Branch) SQLTable

func (b *Branch) SQLTable() string

SQLTable returns the sql SQLTable name of the entity

Testing: tested by using naming conventions. See internal/name pkg

func (*Branch) SetId

func (b *Branch) SetId(id int64)

SetId wraps the id assignation to implement Storable interface

func (*Branch) UnmergedCommits

func (b *Branch) UnmergedCommits(ctx context.Context, db *sqlx.DB) ([]*Commit, error)

type Change

type Change struct {
	Id int64 `json:"id,omitempty"`

	TableName  integrity.TableName  `json:"table_name,omitempty"`
	ColumnName integrity.ColumnName `json:"column_name,omitempty"`

	StringValue  string  `json:"string_value,omitempty"`
	IntValue     int     `json:"int_value,omitempty"`
	Float32Value float32 `json:"float_32_value,omitempty"`
	Float64Value float64 `json:"float_64_value,omitempty"`
	BytesValue   []byte  `json:"bytes_value,omitempty"`

	EntityId integrity.Id `json:"entity_id,omitempty"`

	ValueType integrity.ValueType `json:"value_type,omitempty"`

	Type integrity.CRUD `json:"type,omitempty"`

	Options Options `json:"options,omitempty"`

	IndexId  int64 `json:"index_id,omitempty"`
	CommitId int64 `json:"commit_id,omitempty"`
}

A Change represents every purposed/lookup for difference

func Add

func Add(
	ctx context.Context,
	db *sqlx.DB,
	entityId integrity.Id,
	tableName integrity.TableName,
	columnName integrity.ColumnName,
	branchName integrity.BranchName,
	val interface{},
	Type integrity.CRUD,
	opts Options,
) (*Change, error)

Add wraps change adding from the inferred index

func NewChange

func NewChange(
	entityId integrity.Id,
	tableName integrity.TableName,
	columnName integrity.ColumnName,
	val interface{},
	Type integrity.CRUD,
	opts Options,
) (*Change, error)

NewChange safety creates a new Change entity Notice it doesn't saves it on the db

func Rm

func Rm(
	ctx context.Context,
	db *sqlx.DB,
	entityId integrity.Id,
	tableName integrity.TableName,
	columnName integrity.ColumnName,
	branchName integrity.BranchName,
	val interface{},
	Type integrity.CRUD,
	opts Options,
) (*Change, error)

Rm wraps change removal from the inferred index

func (*Change) Equals

func (chg *Change) Equals(otherChg *Change) bool

Equals checks if the given change will trigger the exactly same action as itself skips comparison in case of Id matching (and Id exists for both of 'em)

func (*Change) FromMap

func (chg *Change) FromMap(Map map[string]interface{}) error

FromMap decodes the commit from its map version Notice that FromMap() is reciprocal to ToMap(), so it doesn't assign a table

func (*Change) GetId

func (chg *Change) GetId() int64

GetId wraps the id retrieval to implement Storable interface

func (*Change) SQLColumns

func (chg *Change) SQLColumns() []string

SQLColumns returns the SQLColumns each field represent on db Notice the returned slice is the list of struct tags of exported fields It's done to avoid reflection

Testing: tested by using reflection at Columns_Test to check being the tags

func (*Change) SQLTable

func (chg *Change) SQLTable() string

SQLTable returns the sql SQLTable name of the entity

Testing: tested by using naming conventions. See internal/name pkg

func (*Change) SetId

func (chg *Change) SetId(id int64)

SetId wraps the id assignation to implement Storable interface

func (*Change) SetOption

func (chg *Change) SetOption(key integrity.OptionKey, val interface{}) error

SetOption assigns the given key to the given value. Returns an error if the key is not allowed for any option

func (*Change) SetValue

func (chg *Change) SetValue(val interface{}) (err error)

SetValue performs type assertion over the given value and sets the value over the given change In case of failure on all the possible type assertions, returns an error Notice that SetValue will ALWAYS tearDown the value set up before

func (*Change) ToMap

func (chg *Change) ToMap() map[string]interface{}

ToMap retrieves a map with the minimum required -not validable- data id est: {column_name: value}

func (*Change) Validate

func (chg *Change) Validate() (err error)

Validate self, wrapping up type validations and table assertion

func (*Change) Value

func (chg *Change) Value() interface{}

Value gives an interface handling the real value Used to perform comparisons

type Collaborator

type Collaborator interface {
	Init(context.Context) error

	Create(context.Context, *Commit) (*Commit, error)

	Retrieve(context.Context, *Commit) (*Commit, error)

	Update(context.Context, *Commit) (*Commit, error)

	Delete(context.Context, *Commit) (*Commit, error)
}

Collaborator is any agent which performs transactions

type Commit

type Commit struct {
	Id      int64     `json:"id,omitempty"`
	Changes []*Change `json:"changes,omitempty"`

	Reviewer Collaborator `json:"reviewer,omitempty"`

	BranchId int64 `json:"branch_id,omitempty"`

	Merged bool `json:"merged,omitempty"`

	Errored bool `json:"errored,omitempty"`
}

Commit is the git-like representation of a group of a ready-to-deliver signed changes

func Comm

func Comm(
	ctx context.Context,
	db *sqlx.DB,
	branchName integrity.BranchName,
) ([]*Commit, error)

func CommitById

func CommitById(ctx context.Context, db *sqlx.DB, id int64) (*Commit, error)

CommitById finds a commit in the DB given its id

func CommitFromCloser

func CommitFromCloser(body io.ReadCloser) (comm *Commit, err error)

CommitFromCloser takes a io.ReadCloser as the guideline of a new commit

func CommitFromMap

func CommitFromMap(Map map[string]interface{}) (comm *Commit, err error)

CommitFromMap decodes the commit from its map version Notice that Commit.FromMap() is reciprocal to ToMap(), so it doesn't assign a table

func NewCommit

func NewCommit(changes []*Change) *Commit

func (*Commit) Branch

func (comm *Commit) Branch(ctx context.Context, db *sqlx.DB) (*Branch, error)

func (*Commit) ColumnNames

func (comm *Commit) ColumnNames() (colNames []integrity.ColumnName)

ColumnNames retrieves all ColumnName for each change

func (*Commit) FetchChanges

func (comm *Commit) FetchChanges(ctx context.Context, db *sqlx.DB) (err error)

FetchChanges retrieves the changes from DB by its .ChangeIds and assigns them to .Changes field

func (*Commit) GetId

func (comm *Commit) GetId() int64

GetId wraps the id retrieval to implement Storable interface

func (*Commit) GroupBy

func (comm *Commit) GroupBy(strategy changesMatcher) (grpChanges [][]*Change)

GroupBy splits the commit's changes by the given comparator criteria See that strategy MUST define an equivalence relation (reflexive, transitive, symmetric)

func (*Commit) Options

func (comm *Commit) Options() (opts Options, err error)

Options checks the unification of the changes' Options, and returns an error if there are not shared Returns the representative Options of the changes

func (*Commit) SQLColumns

func (comm *Commit) SQLColumns() []string

SQLColumns returns the SQLColumns each field represent on db Notice the returned slice is the list of struct tags of exported fields It's done to avoid reflection

Testing: tested by using reflection at Columns_Test to check being the tags

func (*Commit) SQLTable

func (comm *Commit) SQLTable() string

SQLTable returns the sql SQLTable name of the entity

Testing: tested by using naming conventions. See internal/name pkg

func (*Commit) SetId

func (comm *Commit) SetId(id int64)

SetId wraps the id assignation to implement Storable interface

func (*Commit) TableName

func (comm *Commit) TableName() (tableName integrity.TableName, err error)

TableName checks the unification of the changes' TableNames, and returns an error if there are != 1 TableName Returns the representative tableName of the changes

func (*Commit) ToMap

func (comm *Commit) ToMap() map[string]interface{}

ToMap returns a map with the content of the commit, omitting unnecessary fields It takes every change.ToMap and merges onto the resultant map

func (*Commit) Type

func (comm *Commit) Type() (commType integrity.CRUD, err error)

Type checks the unification of the changes' Types, and returns an error if there are != 1 Type Returns the representative type of the changes

func (*Commit) Unmarshal

func (comm *Commit) Unmarshal(data interface{}, format string) error

Unmarshal the commit onto a given data structure through a given format ? Use reflection during unmarshal to take tags format

type Community

type Community []*Team

A Community delimits the teams whose can take a work

func (*Community) LookFor

func (community *Community) LookFor(schName integrity.SchemaName) (*Team, error)

LookFor searches for a team given the correspondent schema (id est: topic abstraction)

type History

type History struct {
	Commits []*Commit
}

type Index

type Index struct {
	Id      int64     `json:"id,omitempty"`
	Changes []*Change `json:"changes,omitempty"`
}

Index is the git-like representation of a group of a NON-ready-to-deliver changes

func (*Index) Add

func (idx *Index) Add(ctx context.Context, db *sqlx.DB, chg *Change) error

add will attach the given change to the index changes In case the change is invalid or is duplicated, it returns an error Its reciprocal to idx.Rm() -excepting for the generated id, obviously-

func (*Index) Commit

func (idx *Index) Commit(ctx context.Context, db *sqlx.DB) ([]*Commit, error)

Commit returns a persisted commit with the index's uncommitted changes.

func (*Index) FetchChanges

func (idx *Index) FetchChanges(ctx context.Context, db *sqlx.DB) (err error)

FetchChanges retrieves the changes from DB by its .ChangeIds and assigns them to .Changes field

func (*Index) FetchUncommittedChanges

func (idx *Index) FetchUncommittedChanges(ctx context.Context, db *sqlx.DB) (err error)

FetchUncommittedChanges retrieves the changes from DB by its .ChangeIds and assigns them to .Changes field It filters committed changes in query

func (*Index) GetId

func (idx *Index) GetId() int64

GetId wraps the id retrieval to implement Storable interface

func (*Index) Rm

func (idx *Index) Rm(ctx context.Context, db *sqlx.DB, chg *Change) error

Rm deletes the given change This action is irreversible Its reciprocal to idx.Add() -excepting for the generated Id, obviously-

func (*Index) SQLColumns

func (idx *Index) SQLColumns() []string

SQLColumns returns the SQLColumns each field represent on db Notice the returned slice is the list of struct tags of exported fields It's done to avoid reflection

Testing: tested by using reflection at Columns_Test to check being the tags

func (*Index) SQLTable

func (idx *Index) SQLTable() string

SQLTable returns the sql SQLTable name of the entity

Testing: tested by using naming conventions. See internal/name pkg

func (*Index) SetId

func (idx *Index) SetId(id int64)

SetId wraps the id assignation to implement Storable interface

type Member

type Member struct {
	AssignedTable integrity.TableName `json:"assigned_table,omitempty"`
	Collab        Collaborator        `json:"collab,omitempty"`
}

A Member is a Collaborator which has a table assigned

type Options

type Options map[integrity.OptionKey]interface{}

Options is a bunch of key-value pairs which must must be in accordance to the OptionKeys of the table that it belongs to. Options is a design error, and in future releases it should be rethinked.

func (Options) Keys

func (opts Options) Keys() (keys []integrity.OptionKey)

Keys returns the OptionKeys slice

type Owner

type Owner struct {
	Project *schema.Planisphere
	Summary chan *Result

	Waiter *sync.WaitGroup
	// contains filtered or unexported fields
}

Owner is the agent which coordinates any given action Notice that an Owner is a Collaborator The unique difference between an owner and a lower-level collaborator is that it stores any result of collaborator actions inside the .Summary

func NewOwner

func NewOwner(project *schema.Planisphere) (*Owner, error)

NewOwner returns a new instance of Owner, with needed initialization and validation

func (*Owner) Create

func (own *Owner) Create(ctx context.Context, comm *Commit) (*Commit, error)

Create will orchestrate the creations of any collaborator

func (*Owner) Delegate

func (own *Owner) Delegate(
	ctx context.Context,
	community *Community,
	schName integrity.SchemaName,
	pR *PullRequest,
) (*PullRequest, error)

Delegate creates a PullRequest and assigns a reviewer to the given commit

func (*Owner) Delete

func (own *Owner) Delete(ctx context.Context, comm *Commit) (*Commit, error)

Delete will orchestrate the deletions of any collaborator

func (*Owner) Merge

func (own *Owner) Merge(ctx context.Context, pR *PullRequest)

Merge performs the needed actions in order to merge the pullRequest

func (*Owner) Orchestrate

func (own *Owner) Orchestrate(
	ctx context.Context,
	community *Community,
	schName integrity.SchemaName,
	pR *PullRequest,
)

Orchestrate sends the order to all the collaborators available to execute the needed actions in order to achieve the commitment, creating a new PullRequest and then merging it

func (*Owner) Retrieve

func (own *Owner) Retrieve(ctx context.Context, comm *Commit) (*Commit, error)

Retrieve will orchestrate the fetches of any collaborator

func (*Owner) ReviewPRCommit

func (own *Owner) ReviewPRCommit(sch *schema.Schema, pR *PullRequest, commIdx int, delegationWg *sync.WaitGroup)

ReviewPRCommit wraps schema validations to a specified commit of the given PullRequest

func (*Owner) Update

func (own *Owner) Update(ctx context.Context, comm *Commit) (*Commit, error)

Update will orchestrate the updations of any collaborator

func (*Owner) WaitAndClose

func (own *Owner) WaitAndClose() error

WaitAndClose will wait for the Owner WaitGroup to be done and close the Owner.Summary It closes an orchestration (Owner.Orchestrate())

type PullRequest

type PullRequest struct {
	Id      int64     `json:"id,omitempty"`
	Team    *Team     `json:"team,omitempty"`
	Commits []*Commit `json:"commits,omitempty"`
}

A PullRequest connects a group of Commits with a team

func NewPullRequest

func NewPullRequest(commits []*Commit) *PullRequest

func Orchestrate

func Orchestrate(
	ctx context.Context,
	db *sqlx.DB,
	project *schema.Planisphere,
	branchName integrity.BranchName,
	schemaName integrity.SchemaName,
	community *Community,
) (*PullRequest, error)

func (*PullRequest) AssignTeam

func (pR *PullRequest) AssignTeam(community *Community, schName integrity.SchemaName) error

AssignTeam looks up for a team given a schemaName and a community Notice that it cleans up the current Team

func (*PullRequest) GetId

func (pR *PullRequest) GetId() int64

GetId wraps the id retrieval to implement Storable interface

func (*PullRequest) SQLColumns

func (pR *PullRequest) SQLColumns() []string

SQLColumns returns the SQLColumns each field represent on db Notice the returned slice is the list of struct tags of exported fields It's done to avoid reflection

Testing: tested by using reflection at Columns_Test to check being the tags

func (*PullRequest) SQLTable

func (pR *PullRequest) SQLTable() string

SQLTable returns the sql SQLTable name of the entity

Testing: tested by using naming conventions. See internal/name pkg

func (*PullRequest) SetId

func (pR *PullRequest) SetId(id int64)

SetId wraps the id assignation to implement Storable interface

type Result

type Result struct {
	CommitId int64 `json:"commit_id,omitempty"`
	Error    error `json:"error,omitempty"`
}

Result is a commitment result

type Team

type Team struct {
	AssignedSchema integrity.SchemaName `json:"assigned_schema,omitempty"`
	Members        []*Member            `json:"members,omitempty"`
}

A Team is a group of Members which work for the same AssignedSchema

func (*Team) AddMember

func (t *Team) AddMember(tableName integrity.TableName, collab Collaborator, force bool) error

AddMember validates if a member with the provided args can be created and then adds it to the team

func (*Team) Delegate

func (t *Team) Delegate(tableName integrity.TableName) (Collaborator, error)

Delegate retrieves the Collaborator which can perform actions over the given tableName

Jump to

Keyboard shortcuts

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