github.com/decred/politeia@v1.4.0/politeiawww/legacy/codetracker/github/database/database.go (about)

     1  // Copyright (c) 2020 The Decred developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  package database
     6  
     7  import (
     8  	"errors"
     9  )
    10  
    11  var (
    12  	// ErrNoVersionRecord is emitted when no version record exists.
    13  	ErrNoVersionRecord = errors.New("no version record")
    14  
    15  	// ErrNoPullRequestFound is emitted when no pull request matches.
    16  	ErrNoPullRequestFound = errors.New("no pull request found")
    17  
    18  	// ErrNoPullRequestReviewFound is emitted when no review matches.
    19  	ErrNoPullRequestReviewFound = errors.New("no pull request review found")
    20  
    21  	// ErrNoCommitFound is emitted when no commit matches.
    22  	ErrNoCommitFound = errors.New("no commit found")
    23  
    24  	// ErrWrongVersion is emitted when the version record does not
    25  	// match the implementation version.
    26  	ErrWrongVersion = errors.New("wrong version")
    27  
    28  	// ErrShutdown is emitted when the cache is shutting down.
    29  	ErrShutdown = errors.New("cache is shutting down")
    30  
    31  	// ErrUserNotFound indicates that a user name was not found in the
    32  	// database.
    33  	ErrUserNotFound = errors.New("user not found")
    34  )
    35  
    36  // Database interface contains all the functions expected of any db
    37  // implemention for github code stats.
    38  type Database interface {
    39  	// NewPullRequest creates a new pull request for the github code db.
    40  	NewPullRequest(*PullRequest) error
    41  
    42  	// UpdatePullRequest updates an existing pull request row.
    43  	UpdatePullRequest(*PullRequest) error
    44  
    45  	// PullRequestByID returns the pull request that matches the provided id.
    46  	PullRequestByID(id string) (*PullRequest, error)
    47  
    48  	// PullRequestsByURL returns all pull request entries matching the url.
    49  	PullRequestsByURL(url string) ([]*PullRequest, error)
    50  
    51  	// MergedPullRequestsByUserDates returns all merged pull requests that match the
    52  	// username and is in between the start and end dates (in Unix).
    53  	MergedPullRequestsByUserDates(username string, start int64, end int64) ([]*PullRequest, error)
    54  
    55  	// UpdatedPullRequestsByUserDates returns all updated pull requests that match the
    56  	// username and is in between the start and end dates (in Unix).
    57  	UpdatedPullRequestsByUserDates(username string, start int64, end int64) ([]*PullRequest, error)
    58  
    59  	// NewPullRequestReview creates a new entry for a pull request review.
    60  	NewPullRequestReview(*PullRequestReview) error
    61  
    62  	// UpdatePullRequestReview updates an exisiting entry for a pull request
    63  	// review.
    64  	UpdatePullRequestReview(*PullRequestReview) error
    65  
    66  	// ReviewByID returns a pull request review with a matching ID.
    67  	ReviewByID(id int64) (*PullRequestReview, error)
    68  
    69  	// ReviewsByUserDates retrusn all reviews from the given user between
    70  	// the dates provided.
    71  	ReviewsByUserDates(user string, start int64, end int64) ([]PullRequestReview, error)
    72  
    73  	// NewCommit creates a new entry for a pull request commit.
    74  	NewCommit(*Commit) error
    75  
    76  	// CommitBySHA returns a commit that matches the SHA.
    77  	CommitBySHA(sha string) (*Commit, error)
    78  
    79  	// CommitsByUserDates returns all commits that match the
    80  	// username and is in between the start and end dates (in Unix).
    81  	CommitsByUserDates(username string, start int64, end int64) ([]Commit, error)
    82  
    83  	// Setup creates the database instance and prepares it for usage.
    84  	Setup() error
    85  
    86  	// Close performs cleanup of the backend.
    87  	Close() error
    88  }
    89  
    90  // PullRequest contains all information pertaining to a specific PR.
    91  type PullRequest struct {
    92  	ID           string
    93  	Repo         string
    94  	Organization string
    95  	User         string
    96  	URL          string
    97  	Number       int
    98  	UpdatedAt    int64
    99  	ClosedAt     int64
   100  	MergedAt     int64
   101  	Merged       bool
   102  	State        string
   103  	Additions    int
   104  	Deletions    int
   105  	MergedBy     string
   106  }
   107  
   108  // PullRequestReview contains any information about reviews that a user
   109  // has submitted to a matching organization PR.
   110  type PullRequestReview struct {
   111  	PullRequestURL string
   112  	ID             int64
   113  	Author         string
   114  	State          string
   115  	SubmittedAt    int64
   116  	CommitID       string
   117  	Repo           string
   118  	Number         int
   119  	Additions      int
   120  	Deletions      int
   121  }
   122  
   123  // Commit contains all the details about specific commits that have been
   124  // made underneath a pull request.
   125  type Commit struct {
   126  	SHA          string `json:"sha"`
   127  	Repo         string `json:"repo"`
   128  	Organization string `json:"organization"`
   129  	Date         int64  `json:"date"`
   130  	Author       string `json:"author"`
   131  	Committer    string `json:"committer"`
   132  	Message      string `json:"message"`
   133  	URL          string `json:"url"`
   134  	ParentSHA    string `json:"parentsha"`
   135  	ParentURL    string `json:"parenturl"`
   136  	Additions    int    `json:"additions"`
   137  	Deletions    int    `json:"deletions"`
   138  	Rebase       bool   `json:"rebase"`
   139  }