From e239e48a0e132ac848552b7c8661f17e20562a8e Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Sun, 7 Oct 2018 17:57:00 +0200 Subject: [PATCH] feat: add more fields --- cmd_airtable.go | 22 +++++++++++++++++++-- issue.go | 51 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 57 insertions(+), 16 deletions(-) diff --git a/cmd_airtable.go b/cmd_airtable.go index ef0702915..5964750e0 100644 --- a/cmd_airtable.go +++ b/cmd_airtable.go @@ -160,11 +160,11 @@ func (i Issue) ToAirtableRecord() airtableRecord { } labels := []string{} for _, label := range i.Labels { - labels = append(labels, label.Name) + labels = append(labels, label.ID) } assignees := []string{} for _, assignee := range i.Assignees { - assignees = append(assignees, assignee.Username) + assignees = append(assignees, assignee.ID) } return airtableRecord{ @@ -181,6 +181,12 @@ func (i Issue) ToAirtableRecord() airtableRecord { RepoURL: i.RepoURL, Body: i.Body, State: i.State, + Locked: i.Locked, + Author: i.AuthorID, + Comments: i.Comments, + Milestone: i.Milestone, + Upvotes: i.Upvotes, + Downvotes: i.Downvotes, Errors: "", }, } @@ -196,6 +202,12 @@ type airtableIssue struct { Body string RepoURL string Type string + Locked bool + Author string + Comments int + Milestone string + Upvotes int + Downvotes int Labels []string Assignees []string Errors string @@ -222,6 +234,12 @@ func (ai airtableIssue) Equals(other airtableIssue) bool { ai.Body == other.Body && ai.RepoURL == other.RepoURL && ai.Type == other.Type && + ai.Locked == other.Locked && + ai.Author == other.Author && + ai.Comments == other.Comments && + ai.Milestone == other.Milestone && + ai.Upvotes == other.Upvotes && + ai.Downvotes == other.Downvotes && sameSlice(ai.Labels, other.Labels) && sameSlice(ai.Assignees, other.Assignees) && ai.Errors == other.Errors diff --git a/issue.go b/issue.go index 569644097..1446e0089 100644 --- a/issue.go +++ b/issue.go @@ -56,16 +56,24 @@ type Issue struct { Labels []*IssueLabel `gorm:"many2many:issue_labels;"` Assignees []*Profile `gorm:"many2many:issue_assignees;"` IsPR bool + + Locked bool + Author Profile + AuthorID string + Comments int + Milestone string + Upvotes int + Downvotes int } type IssueLabel struct { - Name string `gorm:"primary_key"` + ID string `gorm:"primary_key"` Color string } type Profile struct { - Name string - Username string `gorm:"primary_key"` + ID string `gorm:"primary_key"` + Name string } func FromGitHubIssue(input *github.Issue) *Issue { @@ -74,6 +82,10 @@ func FromGitHubIssue(input *github.Issue) *Issue { body = *input.Body } parts := strings.Split(*input.HTMLURL, "/") + authorName := *input.User.Login + if input.User.Name != nil { + authorName = *input.User.Name + } issue := &Issue{ CreatedAt: *input.CreatedAt, UpdatedAt: *input.UpdatedAt, @@ -88,10 +100,21 @@ func FromGitHubIssue(input *github.Issue) *Issue { RepoURL: strings.Join(parts[0:len(parts)-2], "/"), Labels: make([]*IssueLabel, 0), Assignees: make([]*Profile, 0), + Locked: *input.Locked, + Comments: *input.Comments, + Upvotes: *input.Reactions.PlusOne, + Downvotes: *input.Reactions.MinusOne, + Author: Profile{ + ID: *input.User.Login, + Name: authorName, + }, + } + if input.Milestone != nil { + issue.Milestone = *input.Milestone.Title } for _, label := range input.Labels { issue.Labels = append(issue.Labels, &IssueLabel{ - Name: *label.Name, + ID: *label.Name, Color: *label.Color, }) } @@ -101,8 +124,8 @@ func FromGitHubIssue(input *github.Issue) *Issue { name = *assignee.Name } issue.Assignees = append(issue.Assignees, &Profile{ - Name: name, - Username: *assignee.Login, + ID: *assignee.Login, + Name: name, }) } return issue @@ -136,14 +159,14 @@ func FromGitLabIssue(input *gitlab.Issue) *Issue { } for _, label := range input.Labels { issue.Labels = append(issue.Labels, &IssueLabel{ - Name: label, + ID: label, Color: "cccccc", }) } for _, assignee := range input.Assignees { issue.Assignees = append(issue.Assignees, &Profile{ - Name: assignee.Name, - Username: assignee.Username, + Name: assignee.Name, + ID: assignee.Username, }) } return issue @@ -189,7 +212,7 @@ func (i Issue) ProviderURL() string { func (i Issue) IsEpic() bool { for _, label := range i.Labels { - if label.Name == viper.GetString("epic-label") { + if label.ID == viper.GetString("epic-label") { return true } } @@ -230,11 +253,11 @@ func (i Issue) NodeTitle() string { title = strings.Replace(html.EscapeString(wrap(title, 20)), "\n", "
", -1) labels := []string{} for _, label := range i.Labels { - switch label.Name { - case "t/step", "t/epic": + switch label.ID { + case "t/step", "t/epic", "epic": continue } - labels = append(labels, fmt.Sprintf(`%s`, label.Color, label.Name)) + labels = append(labels, fmt.Sprintf(`%s`, label.Color, label.ID)) } labelsText := "" if len(labels) > 0 { @@ -244,7 +267,7 @@ func (i Issue) NodeTitle() string { if len(i.Assignees) > 0 { assignees := []string{} for _, assignee := range i.Assignees { - assignees = append(assignees, assignee.Username) + assignees = append(assignees, assignee.ID) } assigneeText = fmt.Sprintf(`@%s`, strings.Join(assignees, ", @")) }