operations

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2018 License: MIT Imports: 19 Imported by: 14

README

Integrations operations

This folder contains useful scripts and commands to update integrations in bulk.

Env vars

  • GITHUB_TOKEN: To query/update GitHub.
  • GITHUB_USER: For commits. Optional, if not present it will use the system configuration.
  • GITHUB_EMAIL: For commits. Optional, if not present it will use the system configuration.

To use SegmentDestinationsBot, get the credentials from:

$ aws-okta exec prod-privileged -- chamber read -q destinations github_bot_(token|user|email)

list-repositories

Lists all the integrations repositories. Options:

  • --verbose
  • --searchMods=<string>: GitHub search mods to query the repositories (is:private, is:public).

list-integrations

Lists all the integrations. Options:

  • --verbose
  • --monorepoPath=<string>: Local path where the monorepo lives. Default to ..

list-updated-integrations

Lists all the updated integrations since the specified commit or refs/heads/master. Options:

  • --verbose
  • --monorepoPath=<string>: Local path where the monorepo lives. Default to ..
  • --commit=<string>: Commit or reference to compare with the current workspace. Default to refs/heads/master.

migrate-integration

Migrates the integration repo into the monorepo:

  1. Copies the integration code in the monorepo.
  2. Updates references in package.json for the integration.
  3. Commits the integration code.
  4. Updates the integration repo with a notice.
  5. Comments in all opened issues and pull requests and copies them to the monorepo as issues.
  6. Marks the repo as migrated.

Options:

  • --verbose
  • --integration=<name>
  • --monorepoPath=<string>: Local path where the monorepo lives. Default to ..
  • --tmpPath=<string>: Temporal folder. Default to /tmp/integrations.

archive-integration-repository

Archives the repository of the integration:

  1. Removes all webhooks.
  2. Archives the repository.

Options:

  • --verbose
  • --integration=<name>
  • --tmpPath=<string>: Temporal folder. Default to /tmp/integrations.

boneyard-integration-repository

Moves the repository to the boneyard organization.

Options:

  • --verbose
  • --integration=<name>
  • --tmpPath=<string>: Temporal folder. Default to /tmp/integrations.

libgit2

Install libgit2 v27 following this script. This is also required for the CI docker image. IMPORTANT: The following extensions need to be present for libgit2:

  • openssl
  • libhttp-parser-dev

SauceConnect

We use SauceConnect to make a tunnel between localhost and SauceLabs infrastructure. To install it, check this script. This is also required for the CI docker image.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPackageNotFound = errors.New("not found")

ErrPackageNotFound returned by NPM when the package is not found in the registry

View Source
var Verbose = false

Verbose prints some extra info

Functions

func CompareSemanticVersion

func CompareSemanticVersion(version, other string) (int, error)

CompareSemanticVersion returns -1, 0 or 1 if the version is older, the same or newer than the other. See https://godoc.org/github.com/blang/semver#Version.Compare

func Debug

func Debug(format string, args ...interface{})

Debug prints a message if the Verbose flag is set

func EncodePackage

func EncodePackage(p Package, file string) error

EncodePackage writes the struct into package.json

func GetGitHubAuthToken

func GetGitHubAuthToken() string

GetGitHubAuthToken returns the authentication token if found, if not, it exist the app.

func Log

func Log(format string, args ...interface{})

Log prints the message to stderr

func LogError

func LogError(err error, format string, args ...interface{})

LogError prints the error and a message to stderr

func Output

func Output(format string, args ...interface{})

Output prints the message to stdout

Types

type Bugs

type Bugs struct {
	URL string `json:"url"`
}

Bugs from package.json

type Dependencies

type Dependencies map[string]string

Dependencies is a map of package:version

type GitHub

type GitHub struct {
	V3 *github.Client
	V4 *githubv4.Client
}

GitHub is a convenient wrapper for the GraphQL client

func NewGitHubClient

func NewGitHubClient() *GitHub

NewGitHubClient creates and authenticates a GraphQL client for GitHub's V4 API.

func (*GitHub) AddCommentToIssue

func (g *GitHub) AddCommentToIssue(comment string, issue Issue) error

AddCommentToIssue append a comment to an existing issue

func (*GitHub) AddCommentToPullRequest

func (g *GitHub) AddCommentToPullRequest(comment string, pr PullRequest) error

AddCommentToPullRequest append a comment to an existing issue

func (*GitHub) AddIssue

func (g *GitHub) AddIssue(title, body string, project Project) (Issue, error)

AddIssue adds an issue to an existing repository

func (*GitHub) AddLabelToIssue

func (g *GitHub) AddLabelToIssue(label string, issue Issue) error

AddLabelToIssue adds a label

func (*GitHub) AddLabelToPullRequest

func (g *GitHub) AddLabelToPullRequest(label string, pr PullRequest) error

AddLabelToPullRequest adds a label

func (*GitHub) AddLabelToRepository

func (g *GitHub) AddLabelToRepository(label, color, description string, project Project) error

AddLabelToRepository adds a label

func (*GitHub) ArchiveRepository

func (g *GitHub) ArchiveRepository(project Project) error

ArchiveRepository patches the repo and archives it

func (*GitHub) DeleteAllWebHooks

func (g *GitHub) DeleteAllWebHooks(project Project) error

DeleteAllWebHooks retrieves and deletes all webhooks for the project

func (*GitHub) GetOpenIssues

func (g *GitHub) GetOpenIssues(organization, name string) ([]Issue, error)

GetOpenIssues retrieves a list of opened issues for the given project

func (*GitHub) GetOpenPullRequests

func (g *GitHub) GetOpenPullRequests(organization, name string) ([]PullRequest, error)

GetOpenPullRequests retrieves a list of opened pull requests for the given project

func (*GitHub) GetProject

func (g *GitHub) GetProject(organization, name string) (Project, error)

GetProject returns the GitHub repo info

func (*GitHub) ListProjects

func (g *GitHub) ListProjects(organization, prefix string, mods ...string) ([]Project, error)

ListProjects retrieves all repositories starting with prefix

func (*GitHub) Transfer

func (g *GitHub) Transfer(project Project, organization string) error

Transfer moves the repository to another organization

func (*GitHub) UpdateTopics

func (g *GitHub) UpdateTopics(topics []string, project Project) error

UpdateTopics override the existing topics of a repository

type Integration

type Integration struct {
	Name    string
	Path    string
	Package Package
	// contains filtered or unexported fields
}

Integration represents an integration contained in the monorepo

type IntegrationRepo

type IntegrationRepo struct {
	Name string
	Project
	Repo             *git.Repository
	OpenIssues       []Issue
	OpenPullRequests []PullRequest
	// contains filtered or unexported fields
}

IntegrationRepo represents an old integration with its own repository

func OpenIntegrationRepo

func OpenIntegrationRepo(github *GitHub, organization, name, dst string) (*IntegrationRepo, error)

OpenIntegration gets the project from GitHub and clones the repo locally

func (*IntegrationRepo) Archive

func (i *IntegrationRepo) Archive(github *GitHub) error

Archive archives the repo and removes webhooks.

func (*IntegrationRepo) IsMigrated

func (i *IntegrationRepo) IsMigrated() bool

IsMigrated returns true if the repo has been commited to the monorepo and all the issues and open requests have been migrated

func (*IntegrationRepo) MigrateToMonorepo

func (i *IntegrationRepo) MigrateToMonorepo(github *GitHub, monorepo *Monorepo) error

MigrateToMonorepo commits the source code to the monorepo, migrates issues and pull requests, and updates the readme.

func (*IntegrationRepo) MoveToBoneyard

func (i *IntegrationRepo) MoveToBoneyard(github *GitHub, boneyard string) error

MoveToBoneyard moves the repo to the boneyard organization only if it was archived and migrated.

type Issue

type Issue struct {
	ID          string
	Number      int
	Title       string
	URL         string
	Body        string
	Author      string
	PublishedAt time.Time
	UpdatedAt   time.Time
	Labels      []string

	Organization   string
	RepositoryName string
}

Issue represents a GitHub issue

type Monorepo

type Monorepo struct {
	Project
	IntegrationsPath string
	// contains filtered or unexported fields
}

Monorepo

func OpenMonorepo

func OpenMonorepo(path string) (*Monorepo, error)

OpenMonorepo returns the git repository of the monorepo

func (*Monorepo) AddIntegrationRepo

func (m *Monorepo) AddIntegrationRepo(integration IntegrationRepo) (string, error)

AddIntegrationRepo adds the integration files into the monorepo as a folder, and commits the results. It returns the new commit's link.

func (*Monorepo) ConnectToGitHub

func (m *Monorepo) ConnectToGitHub(github *GitHub, organization, name string) error

ConnectToGitHub updates the struct containing GitHub metadata. This was separated from `OpenMonorepo` because in some ocasions we don't need all GitHub information.

func (*Monorepo) ListUpdatedIntegrationsSinceCommit

func (m *Monorepo) ListUpdatedIntegrationsSinceCommit(commitID string) (map[string]*Integration, error)

ListUpdatedIntegrationsSinceCommit compare the current state of the integration with a commit (oid or ref) and return the integrations that have change.

func (*Monorepo) OpenAllIntegrations

func (m *Monorepo) OpenAllIntegrations() (map[string]*Integration, error)

OpenAllIntegrations scans the integration folder

func (*Monorepo) OpenIntegration

func (m *Monorepo) OpenIntegration(name string) (*Integration, error)

OpenIntegration retuns a reference to the integration stored in the monorepo.

type Package

type Package struct {
	Name            string       `json:"name"`
	Description     string       `json:"description"`
	Version         string       `json:"version"`
	Keywords        []string     `json:"keywords"`
	Main            string       `json:"main"`
	Scripts         Scripts      `json:"scripts"`
	Author          string       `json:"author"`
	License         string       `json:"license"`
	Homepage        string       `json:"homepage"`
	Bugs            Bugs         `json:"bugs"`
	Repository      Repository   `json:"repository"`
	Dependencies    Dependencies `json:"dependencies"`
	DevDependencies Dependencies `json:"devDependencies"`
}

Package is the representation of package.json

func DecodePackage

func DecodePackage(file string) (Package, error)

DecodePackage parses package.json into the struct

type Project

type Project struct {
	ID               string
	URL              string
	Organization     string
	RepositoryName   string
	IsPrivate        bool
	Forks            int
	OpenPullRequests int
	OpenIssues       int
	LastUpdated      time.Time
	Labels           []string
	Topics           []string
	IsArchived       bool
}

Project represents a GitHub project

type PullRequest

type PullRequest struct {
	ID          string
	Number      int
	Title       string
	URL         string
	Body        string
	Author      string
	PublishedAt time.Time
	UpdatedAt   time.Time
	Labels      []string

	Organization   string
	RepositoryName string
}

PullRequest represents a GitHub pull request

type Repository

type Repository struct {
	Type string `json:"type"`
	URL  string `json:"url"`
}

Repository from package.json

type Scripts

type Scripts map[string]string

Scripts from package.json

type Tag

type Tag struct {
	Name        string
	When        time.Time
	IsAnnotated bool
	Tag         *git.Tag    // for annotated
	Commit      *git.Commit // for lightweight
}

Tag is an annotated or lightweight tag

func GetLatestTag

func GetLatestTag(repo *git.Repository) (*Tag, error)

type Yarn

type Yarn struct {
}

Look away, I'm hideous! - KramerYarn

func NewYarnClient

func NewYarnClient() *Yarn

NewYarnClient returns a new npm client

func (*Yarn) GetLatestVersion

func (y *Yarn) GetLatestVersion(pack string) (string, error)

GetLatestVersion returns the latest version uploaded to NPM

Jump to

Keyboard shortcuts

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