Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add calculation to display correct pull request velocity #47

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions cmd/show/contributors.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type ContributorModel struct {
username string
userInfo *client.DbUser
prList list.Model
prVelocity float64
APIClient *client.APIClient
serverContext context.Context
}
Expand Down Expand Up @@ -190,7 +191,7 @@ func (m *ContributorModel) fetchContributorInfo(name string) error {

// fetchContributorPRs: fetches the contributor pull requests and creates pull request list
func (m *ContributorModel) fetchContributorPRs(name string) error {
resp, r, err := m.APIClient.UserServiceAPI.FindContributorPullRequests(m.serverContext, name).Limit(10).Execute()
resp, r, err := m.APIClient.UserServiceAPI.FindContributorPullRequests(m.serverContext, name).Range_(30).Execute()
if err != nil {
return err
}
Expand All @@ -201,10 +202,21 @@ func (m *ContributorModel) fetchContributorPRs(name string) error {

// create contributor pull request list
var items []list.Item
var mergedPullRequests int
for _, pr := range resp.Data {
if strings.ToLower(pr.State) == "merged" {
mergedPullRequests++
}
items = append(items, prItem(pr))
}

// calculate pr velocity
if len(resp.Data) <= 0 {
m.prVelocity = 0.0
} else {
m.prVelocity = (float64(mergedPullRequests) / float64(len(resp.Data))) * 100.0
}

l := list.New(items, itemDelegate{}, WindowSize.Width, 14)
l.Title = "✨ Latest Pull Requests"
l.Styles.Title = ListItemTitleStyle
Expand Down Expand Up @@ -243,7 +255,7 @@ func (m *ContributorModel) drawContributorView() string {
func (m *ContributorModel) drawContributorInfo() string {
userOpenIssues := fmt.Sprintf("πŸ“„ Issues: %d", m.userInfo.OpenIssues)
isUserMaintainer := fmt.Sprintf("πŸ”¨ Maintainer: %t", m.userInfo.GetIsMaintainer())
prVelocity := fmt.Sprintf("πŸ”₯ PR Velocity (30d): %d%%", m.userInfo.RecentPullRequestVelocityCount)
prVelocity := fmt.Sprintf("πŸ”₯ PR Velocity (30d): %dd - %.0f%% merged", m.userInfo.RecentPullRequestVelocityCount, m.prVelocity)
prCount := fmt.Sprintf("πŸš€ PR Count (30d): %d", m.userInfo.RecentPullRequestsCount)

prStats := lipgloss.JoinVertical(lipgloss.Left, TextContainer.Render(prVelocity), TextContainer.Render(prCount))
Expand Down
Loading