github.com/munnerz/test-infra@v0.0.0-20190108210205-ce3d181dc989/velodrome/sql/model.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package sql
    18  
    19  import (
    20  	"regexp"
    21  	"time"
    22  )
    23  
    24  // Issue is a pull-request or issue. Its format fits into the ORM
    25  type Issue struct {
    26  	Repository     string `gorm:"primary_key"`
    27  	ID             string `gorm:"primary_key"`
    28  	Labels         []Label
    29  	Assignees      []Assignee
    30  	Title          string `gorm:"type:varchar(1000)"`
    31  	Body           string `gorm:"type:text"`
    32  	User           string
    33  	State          string
    34  	Comments       int
    35  	IsPR           bool
    36  	IssueClosedAt  *time.Time
    37  	IssueCreatedAt time.Time
    38  	IssueUpdatedAt time.Time
    39  }
    40  
    41  // FindLabels returns the list of labels matching the regex
    42  func (issue *Issue) FindLabels(regex *regexp.Regexp) []Label {
    43  	labels := []Label{}
    44  
    45  	for _, label := range issue.Labels {
    46  		if regex.MatchString(label.Name) {
    47  			labels = append(labels, label)
    48  		}
    49  	}
    50  
    51  	return labels
    52  }
    53  
    54  // IssueEvent is an event associated to a specific issued.
    55  // It's format fits into the ORM
    56  type IssueEvent struct {
    57  	Repository     string `gorm:"primary_key;index:repo_created"`
    58  	ID             string `gorm:"primary_key"`
    59  	Label          *string
    60  	Event          string
    61  	EventCreatedAt time.Time `gorm:"index:repo_created"`
    62  	IssueID        string
    63  	Assignee       *string
    64  	Actor          *string
    65  }
    66  
    67  // Label is a tag on an Issue. It's format fits into the ORM.
    68  type Label struct {
    69  	Repository string
    70  	IssueID    string
    71  	Name       string
    72  }
    73  
    74  // Assignee is assigned to an issue.
    75  type Assignee struct {
    76  	Repository string
    77  	IssueID    string
    78  	Name       string
    79  }
    80  
    81  // Comment is either a pull-request comment or an issue comment.
    82  type Comment struct {
    83  	Repository       string `gorm:"primary_key;index:repo_created"`
    84  	ID               string `gorm:"primary_key"`
    85  	IssueID          string
    86  	Body             string `gorm:"type:text"`
    87  	User             string
    88  	CommentCreatedAt time.Time `gorm:"index:repo_created"`
    89  	CommentUpdatedAt time.Time
    90  	PullRequest      bool
    91  }