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 Jan 29, 2025
1 parent 1590a7d commit 1d3280a
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gh-dash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ theme:
primary: "#383B5B"
secondary: "#39386B"
faint: "#2B2B40"

showAuthorRole: true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ theme: # optional, see more info below
pager:
diff: less # or delta for example
confirmQuit: false # show prompt on quit or not
showAuthorRole: false # show author role ("new", "member", etc.)
```
### 🗃 Running with a different config file
Expand Down
2 changes: 2 additions & 0 deletions config/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ type Config struct {
Theme *ThemeConfig `yaml:"theme,omitempty" validate:"omitempty"`
Pager Pager `yaml:"pager"`
ConfirmQuit bool `yaml:"confirmQuit"`
ShowAuthorRole bool `yaml:"showAuthorRole"`
}

type configError struct {
Expand Down Expand Up @@ -313,6 +314,7 @@ func (parser ConfigParser) getDefaultConfig() Config {
},
},
ConfirmQuit: false,
ShowAuthorRole: false,
}
}

Expand Down
23 changes: 15 additions & 8 deletions data/issueapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,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 +54,12 @@ type IssueLabels struct {
Nodes []Label
}

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

func (data IssueData) GetTitle() string {
return data.Title
}
Expand Down
27 changes: 17 additions & 10 deletions data/prapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,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 @@ -166,6 +167,12 @@ type PageInfo struct {
EndCursor string
}

func (data PullRequestData) GetAuthor() string {
author := data.Author.Login
author += fmt.Sprintf(" %s", GetAuthorRoleIcon(data.AuthorAssociation))
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/constants"
)

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) string {
// https://docs.github.com/en/graphql/reference/enums#commentauthorassociation
switch role {
case "FIRST_TIMER", "FIRST_TIME_CONTRIBUTOR", "NONE":
return lipgloss.NewStyle().Foreground(lipgloss.Color(constants.NewContributorColor)).Render(constants.NewContributorIcon)
case "COLLABORATOR":
return lipgloss.NewStyle().Foreground(lipgloss.Color(constants.CollaboratorColor)).Render(constants.CollaboratorIcon)
case "CONTRIBUTOR":
return lipgloss.NewStyle().Foreground(lipgloss.Color(constants.ContributorColor)).Render(constants.ContributorIcon)
case "MEMBER":
return lipgloss.NewStyle().Foreground(lipgloss.Color(constants.MemberColor)).Render(constants.MemberIcon)
case "OWNER":
return lipgloss.NewStyle().Foreground(lipgloss.Color(constants.OwnerColor)).Render(constants.OwnerIcon)
default:
return constants.UnknownRoleIcon
}
}
2 changes: 1 addition & 1 deletion ui/components/issue/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (issue *Issue) renderTitle() string {
}

func (issue *Issue) renderOpenedBy() string {
return issue.getTextStyle().Render(issue.Data.Author.Login)
return issue.getTextStyle().Render(issue.Data.GetAuthor())
}

func (issue *Issue) renderAssignees() string {
Expand Down
4 changes: 2 additions & 2 deletions ui/components/pr/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (pr *PullRequest) renderExtendedTitle(isSelected bool) string {
baseStyle = baseStyle.Foreground(pr.Ctx.Theme.SecondaryText).Background(pr.Ctx.Theme.SelectedBackground)
}

author := baseStyle.Render(fmt.Sprintf("@%s", pr.Data.Author.Login))
author := baseStyle.Render(fmt.Sprintf("@%s", pr.Data.GetAuthor()))
top := lipgloss.JoinHorizontal(lipgloss.Top, pr.Data.Repository.NameWithOwner, fmt.Sprintf(" #%d by %s", pr.Data.Number, author))
branchHidden := pr.Ctx.Config.Defaults.Layout.Prs.Base.Hidden
if branchHidden == nil || !*branchHidden {
Expand All @@ -213,7 +213,7 @@ func (pr *PullRequest) renderExtendedTitle(isSelected bool) string {
}

func (pr *PullRequest) renderAuthor() string {
return pr.getTextStyle().Render(pr.Data.Author.Login)
return pr.getTextStyle().Render(pr.Data.GetAuthor())
}

func (pr *PullRequest) renderAssignees() string {
Expand Down
21 changes: 21 additions & 0 deletions ui/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,25 @@ const (
MergedIcon = ""
OpenIcon = ""
ClosedIcon = ""

NewContributorIcon = "󱃱" // U+F10F1 nf-md-hand_heart
ContributorIcon = "󱕾" // U+F157E nf-md-hand_heart_outline
CollaboratorIcon = "" // U+EDA0 nf-fa-handshake_simple
MemberIcon = "" // U+ED9F nf-fa-handshake_angle
OwnerIcon = "" // U+ED9F nf-fa-handshake_angle
UnknownRoleIcon = "󱐡" // U+F1421 nf-md-incognito_circle

// NewContributorIcon = "󰲡" // U+F0CA1 nf-md-numeric_1_circle_outline
// ContributorIcon = "󰦤" // U+F09A4 nf-md-star_circle_outline
// CollaboratorIcon = "󱟝" // U+F17DD nf-md-crown_circle_outline
// MemberIcon = "󱟝" // U+F17DD nf-md-crown_circle_outline
// OwnerIcon = "󱟜" // U+F17DC nf-md-crown_circle
// UnknownRoleIcon = "󱐡" // U+F1421 nf-md-incognito_circle

NewContributorColor = "77" // PaleGreen3
ContributorColor = "75" // SteelBlue1
CollaboratorColor = "178" // Gold3
MemberColor = "178" // Gold3
OwnerColor = "178" // Gold3

)

0 comments on commit 1d3280a

Please sign in to comment.