github

package
v0.0.0-...-c783a93 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: Apache-2.0 Imports: 18 Imported by: 6

Documentation

Overview

Package github provides definitions and methods for structs used for handling Github data from BigQuery and Cloud SQL. Methods for making authenticated requests to the GitHub API are implemented in this package

Index

Constants

This section is empty.

Variables

View Source
var (
	DB *gorm.DB
)

DB exposes the connection to the backend database

Functions

func API

func API(ctx context.Context, path string, params ...string) (*http.Response, error)

API makes an authenticated request to the GitHub API using Oauth2 Client ID & Secret

func UpdateRepo

func UpdateRepo(ctx context.Context, r string) error

UpdateRepo creates or updates repo data for a repository given by r from Github

Types

type Comment

type Comment struct {
	ID        int64     `gorm:"primary_key"` // Github's unique ID for comments created
	IssueID   string    // Parent Issue's ID for the comment
	Body      string    // Comment's body
	Author    string    // author's github login name
	Created   time.Time // timestamp with date of creation
	UpdatedAt time.Time // timestamp with last update
	Repo      string    // API url for the Comment's parent repo
	URL       string    // https url for the comment on github.com
}

Comment holds metadata for comments on GitHub Issues

type CommentFetcher

type CommentFetcher struct {
	Opts Options
	// contains filtered or unexported fields
}

CommentFetcher uses information stored to query the githubarchive dataset for comments

func (*CommentFetcher) Fetch

func (f *CommentFetcher) Fetch(ctx context.Context) ([]Comment, error)

Fetch uses the fields stored in CommentFetcher and runs a query job on BigQuery

type EmailPayload

type EmailPayload struct {
	Email   string
	Content []Payload
}

EmailPayload is the type that contains email data for one Email to be sent

func FetchData

func FetchData(c context.Context,
	subscriptions []Subscription, emailType Frequency) ([]EmailPayload, error)

FetchData constructs bigquery requests for fetching appropriate data for email notifications

type EmailPreference

type EmailPreference struct {
	SubscriptionID uint      `gorm:"unique;index;not null;"`
	IssueOpen      Frequency `gorm:"type:INT;" sql:"DEFAULT:1"`
	IssueClose     Frequency `gorm:"type:INT;" sql:"DEFAULT:1"`
	IssueReopen    Frequency `gorm:"type:INT;" sql:"DEFAULT:1"`
	NewComment     Frequency `gorm:"type:INT;" sql:"DEFAULT:1"`
	NoComment      Frequency `gorm:"type:INT;" sql:"DEFAULT:1"`
}

EmailPreference stores frequency for various types of notifications

func NewPreference

func NewPreference() EmailPreference

NewPreference returns a default email frequency for all types set to daily

type Frequency

type Frequency int

Frequency is used for tracking notification frequency preferences

const (
	Never   Frequency = iota // 1
	Daily                    // 2
	Weekly                   // 3
	Monthly                  // 4
)

Named frequency constants to help make code readable

type Issue

type Issue struct {
	ID        int64     `gorm:"primary_key"` // Github's unique ID for issues created
	Number    int       // issue number that is specific to a repository
	Title     string    // title for the issue
	Author    string    // author's github login name
	Created   time.Time // timestamp with date of creation
	UpdatedAt time.Time // timestamp with last update
	Repo      string    // API url for the issue's parent repo
	URL       string    // https url for the issue on github.com
}

Issue holds metadata for GitHub Issues

type IssueFetcher

type IssueFetcher struct {
	Opts Options
	// contains filtered or unexported fields
}

IssueFetcher uses information stored to query the githubarchive dataset for issues

func (*IssueFetcher) Fetch

func (f *IssueFetcher) Fetch(ctx context.Context) ([]Issue, error)

Fetch uses the data stored in IssueFetcher and runs a query job on BigQuery

type Notification

type Notification struct {
	ID        uint      `gorm:"primary_key;AUTO_INCREMENT"`
	UserID    uint64    `gorm:"index;not null;"`
	Email     string    `gorm:"not null;"`
	Type      Frequency `gorm:"not null;"`
	Repos     string    `gorm:"not null;type:TEXT;"`
	CreatedAt time.Time
}

Notification stores logging information of outgoing notifications

type Options

type Options struct {
	Tables       []string // To override the default tables - when extending the query for different dates
	Repositories []string // To set repositories to fetch Issues From
	Kind         []string // To set the Kinds of Event to select - eg "opened", "closed",etc
	Order        []string // To override default fields for use in OrderBy Clause
	Limit        uint64   // To override default limit value
	Conditions   []string // To override all conditions for the Query
}

Options allows for additional configuration of the query

func (*Options) SetTables

func (o *Options) SetTables(f Frequency)

SetTables sets the default table values for the given frequency type If an invalid frequency is passed, it returns the default table for today's github events

type Payload

type Payload struct {
	RepoName       string
	OpenIssues     []Issue
	ClosedIssues   []Issue
	Comments       []Comment
	NoComment      bool
	NoCommentSince time.Time
}

Payload is the type that contains email data for one repo

type Repo

type Repo struct {
	ID         uint64 `gorm:"primary_key;AUTO_INCREMENT"`
	Name       string `gorm:"index;not null;"`
	IssuesOpen uint64 `gorm:"type:INT;" `
	UpdatedAt  time.Time
}

Repo stores open issue count for repositories

type Subscription

type Subscription struct {
	ID                 uint            `gorm:"primary_key;AUTO_INCREMENT"`
	UserID             uint64          `gorm:"index;not null;"`
	Repo               string          `gorm:"index;not null;"`
	DefaultEmail       string          `gorm:"not null;"`
	EmailPreference    EmailPreference `gorm:"ForeignKey:SubscriptionID"`
	LastNotificationID uint64          // Last notification’s ID for sending reminders if needed

}

Subscription stores information that relates a repo with a user's watch list

type User

type User struct {
	ID            uint64         `gorm:"primary_key;"`  // Unique Identifier for user Entity
	FireKey       string         `gorm:"unique_index;"` // User's firebase UID
	Login         string         `gorm:"unique_index;"` // Github ID for the user
	Email         string         `gorm:"unique_index;"` // User's default email
	Subscriptions []Subscription `gorm:"ForeignKey:UserID"`
	CreatedAt     time.Time
}

User stores basic user data

func FindUserByLogin

func FindUserByLogin(login string) (User, error)

FindUserByLogin retrieves a user object by their Github ID

func GetUsers

func GetUsers() ([]User, error)

GetUsers retrieves all user objects

func (*User) Add

func (u *User) Add() error

Add inserts a user record for the calling object to the DB

func (User) AddNotification

func (u User) AddNotification(
	ctx context.Context,
	email string, emailType Frequency, data []Payload)

AddNotification saves notification information for the user

func (User) GetNotifications

func (u User) GetNotifications(emailType Frequency) ([]Notification, error)

GetNotifications returns all notifications sent to a user if emailType is 0 or all notifications of a particular emailType (daily/weekly/monthly)

func (User) GetRepos

func (u User) GetRepos(repos ...string) ([]Repo, error)

GetRepos returns data for passed repos If no repos are passed, it returns the entire list of repo data stored for a user

func (User) GetSubscriptions

func (u User) GetSubscriptions(repos ...string) ([]Subscription, error)

GetSubscriptions returns all the subscriptions that match passed repos for a user If no repos are passed, it returns the entire list of subscriptions

func (*User) IsNew

func (u *User) IsNew() (User, bool)

IsNew returns true if there is an entry for the given user in the database

func (User) Remove

func (u User) Remove() error

Remove deletes the user record for the calling object to the DB if it exists

func (*User) Subscribe

func (u *User) Subscribe(repo string, pref EmailPreference, argv ...string) error

Subscribe adds a subscription to a user

Optional argument is DefaultEmail

func (*User) Unsubscribe

func (u *User) Unsubscribe(repos ...string) error

Unsubscribe removes a subscription from a user

func (*User) UnsubscribeAll

func (u *User) UnsubscribeAll() error

UnsubscribeAll removes all subscriptions for a user

func (*User) Update

func (u *User) Update() error

Update updates the user record for the calling object or creates a new record in the DB

func (*User) UpdateSubscription

func (u *User) UpdateSubscription(repo string, s *Subscription) error

UpdateSubscription updates a user's subscription preferences

Directories

Path Synopsis
Package bq provides definitions and methods for structs used for querying data from the a dataset on BigQuery
Package bq provides definitions and methods for structs used for querying data from the a dataset on BigQuery
Package db provides types and methods database operations.
Package db provides types and methods database operations.

Jump to

Keyboard shortcuts

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