Skip to content

Commit

Permalink
feat: show issue/PR author-role indicators in UI, after author logins
Browse files Browse the repository at this point in the history
  • Loading branch information
sideshowbarker committed Feb 9, 2025
1 parent 803b093 commit 0501cfd
Show file tree
Hide file tree
Showing 15 changed files with 451 additions and 121 deletions.
70 changes: 52 additions & 18 deletions config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type PrsLayoutConfig struct {
CreatedAt ColumnConfig `yaml:"createdAt,omitempty"`
Repo ColumnConfig `yaml:"repo,omitempty"`
Author ColumnConfig `yaml:"author,omitempty"`
AuthorIcon ColumnConfig `yaml:"authorIcon,omitempty"`
Assignees ColumnConfig `yaml:"assignees,omitempty"`
Title ColumnConfig `yaml:"title,omitempty"`
Base ColumnConfig `yaml:"base,omitempty"`
Expand All @@ -81,15 +82,16 @@ type PrsLayoutConfig struct {
}

type IssuesLayoutConfig struct {
UpdatedAt ColumnConfig `yaml:"updatedAt,omitempty"`
CreatedAt ColumnConfig `yaml:"createdAt,omitempty"`
State ColumnConfig `yaml:"state,omitempty"`
Repo ColumnConfig `yaml:"repo,omitempty"`
Title ColumnConfig `yaml:"title,omitempty"`
Creator ColumnConfig `yaml:"creator,omitempty"`
Assignees ColumnConfig `yaml:"assignees,omitempty"`
Comments ColumnConfig `yaml:"comments,omitempty"`
Reactions ColumnConfig `yaml:"reactions,omitempty"`
UpdatedAt ColumnConfig `yaml:"updatedAt,omitempty"`
CreatedAt ColumnConfig `yaml:"createdAt,omitempty"`
State ColumnConfig `yaml:"state,omitempty"`
Repo ColumnConfig `yaml:"repo,omitempty"`
Title ColumnConfig `yaml:"title,omitempty"`
Creator ColumnConfig `yaml:"creator,omitempty"`
CreatorIcon ColumnConfig `yaml:"creatorIcon,omitempty"`
Assignees ColumnConfig `yaml:"assignees,omitempty"`
Comments ColumnConfig `yaml:"comments,omitempty"`
Reactions ColumnConfig `yaml:"reactions,omitempty"`
}

type LayoutConfig struct {
Expand Down Expand Up @@ -143,6 +145,15 @@ type Pager struct {

type HexColor string

type ColorThemeIcon struct {
NewContributor HexColor `yaml:"newcontributor" validate:"omitempty,hexcolor"`
Contributor HexColor `yaml:"contributor" validate:"omitempty,hexcolor"`
Collaborator HexColor `yaml:"collaborator" validate:"omitempty,hexcolor"`
Member HexColor `yaml:"member" validate:"omitempty,hexcolor"`
Owner HexColor `yaml:"owner" validate:"omitempty,hexcolor"`
UnknownRole HexColor `yaml:"unknownrole" validate:"omitempty,hexcolor"`
}

type ColorThemeText struct {
Primary HexColor `yaml:"primary" validate:"omitempty,hexcolor"`
Secondary HexColor `yaml:"secondary" validate:"omitempty,hexcolor"`
Expand All @@ -164,6 +175,7 @@ type ColorThemeBackground struct {
}

type ColorTheme struct {
Icon ColorThemeIcon `yaml:"icon" validate:"required"`
Text ColorThemeText `yaml:"text" validate:"required"`
Background ColorThemeBackground `yaml:"background" validate:"required"`
Border ColorThemeBorder `yaml:"border" validate:"required"`
Expand All @@ -173,6 +185,19 @@ type ColorThemeConfig struct {
Inline ColorTheme `yaml:",inline"`
}

type IconTheme struct {
NewContributor string `yaml:"newcontributor,omitempty"`
Contributor string `yaml:"contributor,omitempty"`
Collaborator string `yaml:"collaborator,omitempty"`
Member string `yaml:"member,omitempty"`
Owner string `yaml:"owner,omitempty"`
UnknownRole string `yaml:"unknownrole,omitempty"`
}

type IconThemeConfig struct {
Inline IconTheme `yaml:",inline"`
}

type TableUIThemeConfig struct {
ShowSeparator bool `yaml:"showSeparator" default:"true"`
Compact bool `yaml:"compact" default:"false"`
Expand All @@ -186,18 +211,20 @@ type UIThemeConfig struct {
type ThemeConfig struct {
Ui UIThemeConfig `yaml:"ui,omitempty" validate:"omitempty"`
Colors *ColorThemeConfig `yaml:"colors,omitempty" validate:"omitempty"`
Icons *IconThemeConfig `yaml:"icons,omitempty" validate:"omitempty"`
}

type Config struct {
PRSections []PrsSectionConfig `yaml:"prSections"`
IssuesSections []IssuesSectionConfig `yaml:"issuesSections"`
Repo RepoConfig `yaml:"repo"`
Defaults Defaults `yaml:"defaults"`
Keybindings Keybindings `yaml:"keybindings"`
RepoPaths map[string]string `yaml:"repoPaths"`
Theme *ThemeConfig `yaml:"theme,omitempty" validate:"omitempty"`
Pager Pager `yaml:"pager"`
ConfirmQuit bool `yaml:"confirmQuit"`
PRSections []PrsSectionConfig `yaml:"prSections"`
IssuesSections []IssuesSectionConfig `yaml:"issuesSections"`
Repo RepoConfig `yaml:"repo"`
Defaults Defaults `yaml:"defaults"`
Keybindings Keybindings `yaml:"keybindings"`
RepoPaths map[string]string `yaml:"repoPaths"`
Theme *ThemeConfig `yaml:"theme,omitempty" validate:"omitempty"`
Pager Pager `yaml:"pager"`
ConfirmQuit bool `yaml:"confirmQuit"`
ShowAuthorIcons bool `yaml:"showAuthorIcons"`
}

type configError struct {
Expand Down Expand Up @@ -233,6 +260,9 @@ func (parser ConfigParser) getDefaultConfig() Config {
Author: ColumnConfig{
Width: utils.IntPtr(15),
},
AuthorIcon: ColumnConfig{
Hidden: utils.BoolPtr(false),
},
Assignees: ColumnConfig{
Width: utils.IntPtr(20),
Hidden: utils.BoolPtr(true),
Expand All @@ -258,6 +288,9 @@ func (parser ConfigParser) getDefaultConfig() Config {
Creator: ColumnConfig{
Width: utils.IntPtr(10),
},
CreatorIcon: ColumnConfig{
Hidden: utils.BoolPtr(false),
},
Assignees: ColumnConfig{
Width: utils.IntPtr(20),
Hidden: utils.BoolPtr(true),
Expand Down Expand Up @@ -313,6 +346,7 @@ func (parser ConfigParser) getDefaultConfig() Config {
},
},
ConfirmQuit: false,
ShowAuthorIcons: true,
}
}

Expand Down
27 changes: 19 additions & 8 deletions data/issueapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/charmbracelet/log"
gh "github.com/cli/go-gh/v2/pkg/api"
graphql "github.com/cli/shurcooL-graphql"

"github.com/dlvhdr/gh-dash/v4/ui/theme"
)

type IssueData struct {
Expand All @@ -17,14 +19,15 @@ type IssueData struct {
Author struct {
Login string
}
UpdatedAt time.Time
CreatedAt time.Time
Url string
Repository Repository
Assignees Assignees `graphql:"assignees(first: 3)"`
Comments IssueComments `graphql:"comments(first: 15)"`
Reactions IssueReactions `graphql:"reactions(first: 1)"`
Labels IssueLabels `graphql:"labels(first: 3)"`
AuthorAssociation string
UpdatedAt time.Time
CreatedAt time.Time
Url string
Repository Repository
Assignees Assignees `graphql:"assignees(first: 3)"`
Comments IssueComments `graphql:"comments(first: 15)"`
Reactions IssueReactions `graphql:"reactions(first: 1)"`
Labels IssueLabels `graphql:"labels(first: 3)"`
}

type IssueComments struct {
Expand Down Expand Up @@ -53,6 +56,14 @@ type IssueLabels struct {
Nodes []Label
}

func (data IssueData) GetAuthor(theme theme.Theme, showAuthorIcons bool) string {
author := data.Author.Login
if showAuthorIcons {
author += fmt.Sprintf(" %s", GetAuthorRoleIcon(data.AuthorAssociation, theme))
}
return author
}

func (data IssueData) GetTitle() string {
return data.Title
}
Expand Down
30 changes: 20 additions & 10 deletions data/prapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/shurcooL/githubv4"

"github.com/dlvhdr/gh-dash/v4/config"
"github.com/dlvhdr/gh-dash/v4/ui/theme"
)

type PullRequestData struct {
Expand All @@ -22,16 +23,17 @@ type PullRequestData struct {
Author struct {
Login string
}
UpdatedAt time.Time
CreatedAt time.Time
Url string
State string
Mergeable string
ReviewDecision string
Additions int
Deletions int
HeadRefName string
BaseRefName string
AuthorAssociation string
UpdatedAt time.Time
CreatedAt time.Time
Url string
State string
Mergeable string
ReviewDecision string
Additions int
Deletions int
HeadRefName string
BaseRefName string
HeadRepository struct {
Name string
}
Expand Down Expand Up @@ -167,6 +169,14 @@ type PageInfo struct {
EndCursor string
}

func (data PullRequestData) GetAuthor(theme theme.Theme, showAuthorIcon bool) string {
author := data.Author.Login
if showAuthorIcon {
author += fmt.Sprintf(" %s", GetAuthorRoleIcon(data.AuthorAssociation, theme))
}
return author
}

func (data PullRequestData) GetTitle() string {
return data.Title
}
Expand Down
21 changes: 21 additions & 0 deletions data/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package data

import (
"time"

"github.com/charmbracelet/lipgloss"
"github.com/dlvhdr/gh-dash/v4/ui/theme"
)

type RowData interface {
Expand All @@ -22,3 +25,21 @@ func IsStatusWaiting(status string) bool {
func IsConclusionAFailure(conclusion string) bool {
return conclusion == "FAILURE" || conclusion == "TIMED_OUT" || conclusion == "STARTUP_FAILURE"
}

func GetAuthorRoleIcon(role string, theme theme.Theme) string {
// https://docs.github.com/en/graphql/reference/enums#commentauthorassociation
switch role {
case "FIRST_TIMER", "FIRST_TIME_CONTRIBUTOR", "NONE":
return lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor(theme.NewContributorIconColor)).Render(theme.NewContributorIcon)
case "COLLABORATOR":
return lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor(theme.CollaboratorIconColor)).Render(theme.CollaboratorIcon)
case "CONTRIBUTOR":
return lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor(theme.ContributorIconColor)).Render(theme.ContributorIcon)
case "MEMBER":
return lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor(theme.MemberIconColor)).Render(theme.MemberIcon)
case "OWNER":
return lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor(theme.OwnerIconColor)).Render(theme.OwnerIcon)
default:
return lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor(theme.UnknownRoleIconColor)).Render(theme.UnknownRoleIcon)
}
}
11 changes: 11 additions & 0 deletions docs/data/schemas/gh-dash.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,14 @@ properties:
- less
- delta
default: less
showAuthorIcons:
title: Show Author Role Icons
description: |
Specifies whether to show author-role icons in the dashboard.
Set this value to `false` to hide the author-role icons.
See the [Theme Icons](theme#icons) section and
[Icon Colors](theme#colors.icons) section for
configuration options you can set to change the author-role icons and author-role icon colors.
type: boolean
schematize:
weight: 8
24 changes: 21 additions & 3 deletions docs/data/schemas/layout/issue.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,32 @@ properties:
The heading for this column is ![styled:`Creator`]().
default:
width: 10
creatorIcon:
title: Issue Creator Role Icon
description: Defines options for the role icon for each issue in an issue section.
type: object
properties:
hidden:
title: Hide Creator Icon
description: Specify whether the role icon for issue creators should be hidden from view.
schematize:
details: |
Set this value to `true` to hide the role icon for issue creators.
type: boolean
schematize:
weight: 6
skip_schema_render: true
format: yaml
details: |
This setting affects display of the role icon for the person who created the issue.
assignees:
title: Issue Assignees Column
description: Defines options for the assignees column in an issue section.
type: object
oneOf:
- $ref: ./options.yaml
schematize:
weight: 6
weight: 7
skip_schema_render: true
format: yaml
details: |
Expand All @@ -176,7 +194,7 @@ properties:
oneOf:
- $ref: ./options.yaml
schematize:
weight: 7
weight: 8
skip_schema_render: true
format: yaml
details: |
Expand All @@ -190,7 +208,7 @@ properties:
oneOf:
- $ref: ./options.yaml
schematize:
weight: 8
weight: 9
skip_schema_render: true
format: yaml
details: |
Expand Down
Loading

0 comments on commit 0501cfd

Please sign in to comment.