warehouse

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2019 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var AllModels = []interface{}{
	Repository{},
	Provider{},
	Milestone{},
	Issue{},
	Label{},
	Account{},
}

Functions

func Compute

func Compute(db *gorm.DB) error

Compute loads issues from the given database, computes their fields, and stores the issues back into the database.

func PullAndCompute

func PullAndCompute(githubToken, gitlabToken string, db *gorm.DB, t Targets) error

PullAndCompute pulls issues from the given targets, computes their fields, and stores the issues in the database.

Types

type Account

type Account struct {
	Base

	// base fields
	URL       string `json:"url"`
	Login     string `json:"login"`
	FullName  string `json:"fullname"`
	Type      string `json:"type"`
	Bio       string `json:"bio"`
	Location  string `json:"location"`
	Company   string `json:"company"`
	Blog      string `json:"blog"`
	Email     string `json:"email"`
	AvatarURL string `json:"avatar-url"`

	// relationships
	Provider   *Provider `json:"provider"`
	ProviderID string    `json:"provider-id"`
}

func (Account) String

func (a Account) String() string

func (Account) ToRecord

func (a Account) ToRecord(cache airtabledb.DB) airtabledb.Record

type Base

type Base struct {
	ID        string         `gorm:"primary_key" json:"id"`
	CreatedAt time.Time      `json:"created-at,omitempty"`
	UpdatedAt time.Time      `json:"updated-at,omitempty"`
	Errors    pq.StringArray `json:"errors,omitempty" gorm:"type:varchar[]"`
}

func (Base) GetID

func (b Base) GetID() string

type Feature

type Feature interface {
	String() string
	GetID() string
	ToRecord(airtabledb.DB) airtabledb.Record
}

type Issue

type Issue struct {
	Base

	// base fields
	URL         string    `json:"url"`
	CompletedAt time.Time `json:"completed-at"`
	Title       string    `json:"title"`
	State       string    `json:"state"`
	Body        string    `json:"body"`
	IsPR        bool      `json:"is-pr"`
	IsLocked    bool      `json:"is-locked"`
	Comments    int       `json:"comments"`
	Upvotes     int       `json:"upvotes"`
	Downvotes   int       `json:"downvotes"`
	IsOrphan    bool      `json:"is-orphan"`
	IsHidden    bool      `json:"is-hidden"`
	Weight      int       `json:"weight"`
	IsEpic      bool      `json:"is-epic"`
	HasEpic     bool      `json:"has-epic"`

	// relationships
	Repository   *Repository `json:"repository"`
	RepositoryID string      `json:"repository_id"`
	Milestone    *Milestone  `json:"milestone"`
	MilestoneID  string      `json:"milestone_id"`
	Author       *Account    `json:"author"`
	AuthorID     string      `json:"author_id"`
	Labels       []*Label    `gorm:"many2many:issue_labels" json:"labels"`
	Assignees    []*Account  `gorm:"many2many:issue_assignees" json:"assignees"`
	Parents      []*Issue    `json:"-" gorm:"many2many:issue_parents;association_jointable_foreignkey:parent_id"`
	Children     []*Issue    `json:"-" gorm:"many2many:issue_children;association_jointable_foreignkey:child_id"`
	Duplicates   []*Issue    `json:"-" gorm:"many2many:issue_duplicates;association_jointable_foreignkey:duplicate_id"`

	// internal
	ChildIDs     []string `json:"child_ids" gorm:"-"`
	ParentIDs    []string `json:"parent_ids" gorm:"-"`
	DuplicateIDs []string `json:"duplicate_ids" gorm:"-"`
}

func (Issue) GetRelativeURL

func (i Issue) GetRelativeURL(target string) string
Example
issue := Issue{
	URL: "https://github.com/moul/depviz/issues/42",
	Repository: &Repository{
		URL: "https://github.com/moul/depviz",
		Provider: &Provider{
			URL: "https://github.com/",
		},
	},
}
for _, target := range []string{
	"#43",
	"moul/depviz#44",
	"github.com/moul/depviz/issues/45",
	"https://github.com/moul/depviz/issues/46",
	"test/test#47",
	"github.com/test/test/issues/48",
	"https://github.com/test/test/issues/49",
	"gitlab.com/moul/depviz/issues/50",
	"https://gitlab.com/moul/depviz/issues/51",
	"gitlab.com/test2/issues/52",
	"gitlab.com/test2/test3/test4/issues/53",
} {
	fmt.Printf("%-42s -> %s\n", target, issue.GetRelativeURL(target))
}

issue = Issue{
	URL: "https://gitlab.com/moul/depviz/issues/42",
	Repository: &Repository{
		URL: "https://gitlab.com/moul/depviz",
		Provider: &Provider{
			URL: "https://gitlab.com/",
		},
	},
}
for _, target := range []string{
	"#43",
	"moul/depviz#44",
	"gitlab.com/moul/depviz/issues/45",
	"https://gitlab.com/moul/depviz/issues/46",
	"test/test#47",
	"gitlab.com/test/test/issues/48",
	"https://gitlab.com/test/test/issues/49",
	"github.com/moul/depviz/issues/50",
	"https://github.com/moul/depviz/issues/51",
	"github.com/test2/issues/52",
	"github.com/test2/test3/test4/issues/53",
} {
	fmt.Printf("%-42s -> %s\n", target, issue.GetRelativeURL(target))
}
Output:

#43                                        -> https://github.com/moul/depviz/issues/43
moul/depviz#44                             -> https://github.com/moul/depviz/issues/44
github.com/moul/depviz/issues/45           -> https://github.com/moul/depviz/issues/45
https://github.com/moul/depviz/issues/46   -> https://github.com/moul/depviz/issues/46
test/test#47                               -> https://github.com/test/test/issues/47
github.com/test/test/issues/48             -> https://github.com/test/test/issues/48
https://github.com/test/test/issues/49     -> https://github.com/test/test/issues/49
gitlab.com/moul/depviz/issues/50           -> https://gitlab.com/moul/depviz/issues/50
https://gitlab.com/moul/depviz/issues/51   -> https://gitlab.com/moul/depviz/issues/51
gitlab.com/test2/issues/52                 -> https://gitlab.com/test2/issues/52
gitlab.com/test2/test3/test4/issues/53     -> https://gitlab.com/test2/test3/test4/issues/53
#43                                        -> https://gitlab.com/moul/depviz/issues/43
moul/depviz#44                             -> https://gitlab.com/moul/depviz/issues/44
gitlab.com/moul/depviz/issues/45           -> https://gitlab.com/moul/depviz/issues/45
https://gitlab.com/moul/depviz/issues/46   -> https://gitlab.com/moul/depviz/issues/46
test/test#47                               -> https://gitlab.com/test/test/issues/47
gitlab.com/test/test/issues/48             -> https://gitlab.com/test/test/issues/48
https://gitlab.com/test/test/issues/49     -> https://gitlab.com/test/test/issues/49
github.com/moul/depviz/issues/50           -> https://github.com/moul/depviz/issues/50
https://github.com/moul/depviz/issues/51   -> https://github.com/moul/depviz/issues/51
github.com/test2/issues/52                 -> https://github.com/test2/issues/52
github.com/test2/test3/test4/issues/53     -> https://github.com/test2/test3/test4/issues/53

func (Issue) IsClosed

func (i Issue) IsClosed() bool

func (Issue) IsReady

func (i Issue) IsReady() bool

func (Issue) MatchesWithATarget

func (i Issue) MatchesWithATarget(targets Targets) bool

func (*Issue) Number

func (i *Issue) Number() string

func (*Issue) Path

func (i *Issue) Path() string

func (*Issue) PostLoad

func (i *Issue) PostLoad()

func (*Issue) Render

func (i *Issue) Render(w http.ResponseWriter, r *http.Request) error

func (Issue) String

func (i Issue) String() string

func (Issue) ToRecord

func (i Issue) ToRecord(cache airtabledb.DB) airtabledb.Record

type Issues

type Issues []*Issue

func Load

func Load(db *gorm.DB, targets []Target) (Issues, error)

Load returns the issues stored in the database.

func (Issues) FilterByTargets

func (issues Issues) FilterByTargets(targets []Target) Issues

func (Issues) Get

func (issues Issues) Get(id string) *Issue

type Label

type Label struct {
	Base

	// base fields
	URL         string `json:"url"`
	Name        string `json:"name"`
	Color       string `json:"color"`
	Description string `json:"description"`
}

func (Label) String

func (l Label) String() string

func (Label) ToRecord

func (l Label) ToRecord(cache airtabledb.DB) airtabledb.Record

type Milestone

type Milestone struct {
	Base

	// base fields
	URL         string    `json:"url"`
	Title       string    `json:"title"`
	Description string    `json:"description"`
	ClosedAt    time.Time `json:"closed-at"`
	DueOn       time.Time `json:"due-on"`

	// relationships
	Creator      *Account    `json:"creator"`
	CreatorID    string      `json:"creator-id"`
	Repository   *Repository `json:"repository"`
	RepositoryID string      `json:"repository-id"`
}

func (Milestone) String

func (m Milestone) String() string

func (Milestone) ToRecord

func (m Milestone) ToRecord(cache airtabledb.DB) airtabledb.Record

type Provider

type Provider struct {
	Base

	// base fields
	URL    string `json:"url"`
	Driver string `json:"driver"` // github, gitlab, unknown
}

func (Provider) String

func (p Provider) String() string

func (Provider) ToRecord

func (p Provider) ToRecord(cache airtabledb.DB) airtabledb.Record

type ProviderDriver

type ProviderDriver string
const (
	UnknownProviderDriver ProviderDriver = "unknown"
	GithubDriver          ProviderDriver = "github"
	GitlabDriver          ProviderDriver = "gitlab"
)

type Repository

type Repository struct {
	Base

	// base fields
	URL         string    `json:"url"`
	Title       string    `json:"name"`
	Description string    `json:"description"`
	Homepage    string    `json:"homepage"`
	PushedAt    time.Time `json:"pushed-at"`
	IsFork      bool      `json:"fork"`

	// relationships
	Provider   *Provider `json:"provider"`
	ProviderID string    `json:"provider-id"`
	Owner      *Account  `json:"owner"`
	OwnerID    string    `json:"owner-id"`
}

func (Repository) String

func (r Repository) String() string

func (Repository) ToRecord

func (r Repository) ToRecord(cache airtabledb.DB) airtabledb.Record

type Target

type Target string

func (Target) Canonical

func (t Target) Canonical() string

func (Target) Driver

func (t Target) Driver() ProviderDriver

func (Target) Issue

func (t Target) Issue() string

func (Target) Namespace

func (t Target) Namespace() string

func (Target) Path

func (t Target) Path() string

func (Target) Project

func (t Target) Project() string

func (Target) ProjectURL

func (t Target) ProjectURL() string

func (Target) ProviderURL

func (t Target) ProviderURL() string

type Targets

type Targets []Target

func ParseTargets

func ParseTargets(inputs []string) (Targets, error)
Example
targets, _ := ParseTargets([]string{
	"moul/project1",
	"moul/project2#42",
	"github.com/moul/project3",
	"https://github.com/moul/project4/issues/42",
	"https://gitlab.com/moul/project5#42",
	"gitlab.com/moul/project6",
})
for _, target := range targets {
	fmt.Printf(
		"target=%q canonical=%q project=%q namespace=%q providerurl=%q driver=%q path=%q projecturl=%q issue=%q\n",
		target,
		target.Canonical(),
		target.Project(),
		target.Namespace(),
		target.ProviderURL(),
		target.Driver(),
		target.Path(),
		target.ProjectURL(),
		target.Issue(),
	)
}
Output:

target="https://github.com/moul/project1" canonical="https://github.com/moul/project1" project="project1" namespace="moul" providerurl="https://github.com" driver="github" path="moul/project1" projecturl="https://github.com/moul/project1" issue=""
target="https://github.com/moul/project2/issues/42" canonical="https://github.com/moul/project2/issues/42" project="project2" namespace="moul" providerurl="https://github.com" driver="github" path="moul/project2" projecturl="https://github.com/moul/project2" issue="42"
target="https://github.com/moul/project3" canonical="https://github.com/moul/project3" project="project3" namespace="moul" providerurl="https://github.com" driver="github" path="moul/project3" projecturl="https://github.com/moul/project3" issue=""
target="https://github.com/moul/project4/issues/42" canonical="https://github.com/moul/project4/issues/42" project="project4" namespace="moul" providerurl="https://github.com" driver="github" path="moul/project4" projecturl="https://github.com/moul/project4" issue="42"
target="https://gitlab.com/moul/project5/issues/42" canonical="https://gitlab.com/moul/project5/issues/42" project="project5" namespace="moul" providerurl="https://gitlab.com" driver="gitlab" path="moul/project5" projecturl="https://gitlab.com/moul/project5" issue="42"
target="https://gitlab.com/moul/project6" canonical="https://gitlab.com/moul/project6" project="project6" namespace="moul" providerurl="https://gitlab.com" driver="gitlab" path="moul/project6" projecturl="https://gitlab.com/moul/project6" issue=""

func (Targets) UniqueProjects

func (t Targets) UniqueProjects() Targets
Example
targets, _ := ParseTargets([]string{
	"moul/project1",
	"moul/project2#42",
	"moul/project2",
	"github.com/moul/project1",
	"https://github.com/moul/project2/issues/42",
	"https://gitlab.com/moul/project1#42",
	"https://gitlab.com/moul/project1",
	"https://gitlab.com/moul/project2",
	"gitlab.com/moul/project1",
})
for _, target := range targets.UniqueProjects() {
	fmt.Println(target.Canonical())
}
Output:

https://github.com/moul/project1
https://github.com/moul/project2
https://gitlab.com/moul/project1
https://gitlab.com/moul/project2

Jump to

Keyboard shortcuts

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