Skip to content

Commit

Permalink
Merge pull request #42 from grafana/debug-busyiness
Browse files Browse the repository at this point in the history
Make team member busyness calculation more verbose
  • Loading branch information
replay authored May 31, 2024
2 parents 1a28b06 + 0874cb6 commit 7234171
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ic-assignment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ outputs:
description: "The output property of the assigned person. If output property is empty, name is used instead"
runs:
using: "docker"
image: "docker://ghcr.io/grafana/issue-team-scheduler-ic-assignment:v0.12"
image: "docker://ghcr.io/grafana/issue-team-scheduler-ic-assignment:v0.13"
50 changes: 33 additions & 17 deletions pkg/icassigner/busyness/busyness.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package busyness
import (
"context"
"fmt"
"log"
"slices"
"strings"
"time"
Expand Down Expand Up @@ -55,6 +56,8 @@ type busynessClient interface {

// CalculateBusynessForTeam calculates busyness of all members and returns a BusynessReport for them
func CalculateBusynessForTeam(ctx context.Context, now time.Time, githubClient *github.Client, ignorableLabels []string, members []string) (Report, error) {
log.Printf("Calculating busyness for team members: %s\n", strings.Join(members, ", "))

bA, err := newGithubBusynessClient(githubClient, ignorableLabels)
if err != nil {
return Report{}, fmt.Errorf("unable to create github busyness client, due %w", err)
Expand Down Expand Up @@ -140,15 +143,8 @@ func newGithubBusynessClient(githubClient *github.Client, ignorableLabels []stri
// If there are labels to be ignored, all issues with that label are ignored from the busyness calculation
func (b *githubBusynessClient) getBusyness(ctx context.Context, since time.Time, member string) int {
// check if one of the labels is contained by the labels to ignore
containsLabelsToIgnore := func(labels []github.Label) bool {
for _, l := range labels {
_, tobeIgnored := b.labelsToIgnore[*l.Name]
if tobeIgnored {
return true
}
}
return false
}

log.Printf("Calculating busyness of member %s based on their issues since %s\n", member, since.String())

issues, err := b.listByAssigneeFunc(ctx, since, member, 20)
if err != nil {
Expand All @@ -158,27 +154,47 @@ func (b *githubBusynessClient) getBusyness(ctx context.Context, since time.Time,
// count relevant issues
busyness := 0
for _, i := range issues {
// ignore everything without any state
if i.State == nil {
continue
}

switch *i.State {
switch i.GetState() {
case "open":
// check for labels to ignore, e.g. `stale` and ignore issue in this case
if containsLabelsToIgnore(i.Labels) {
if b.containsLabelsToIgnore(i.Labels) {
log.Printf("%s: Ignoring open issue because it contains labels to ignore (%s): %s\n", member, labelsToString(i.Labels), i.GetTitle())
continue
}

// increase busyness count otherwise
log.Printf("%s: Issue increases busyness because it is still open: %s\n", member, i.GetTitle())
busyness++
case "closed":
// if the issue got closed since our time to check
if since.Before(*i.ClosedAt) {
if since.Before(i.GetClosedAt()) {
log.Printf("%s: Issue increases busyness because it has been closed at %s which is after %s: %s\n", member, i.GetClosedAt().String(), since.String(), i.GetTitle())
busyness++
} else {
log.Printf("%s: Issue doesn't increase busyness because it has been closed at %s which is before %s: %s\n", member, i.GetClosedAt().String(), since.String(), i.GetTitle())
}
default:
log.Printf("%s: Issue doesn't increase busyness because it has an unknown state (%s): %s\n", member, i.GetState(), i.GetTitle())
}
}

return busyness
}

func (b *githubBusynessClient) containsLabelsToIgnore(labels []github.Label) bool {
for _, l := range labels {
_, tobeIgnored := b.labelsToIgnore[l.GetName()]
if tobeIgnored {
return true
}
}
return false
}

func labelsToString(labels []github.Label) string {
labelNames := make([]string, len(labels))
for idx, l := range labels {
labelNames[idx] = l.GetName()
}
return strings.Join(labelNames, ", ")
}
2 changes: 1 addition & 1 deletion regex-labeler/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ inputs:
description: "GitHub token to use for API calls"
runs:
using: "docker"
image: "docker://ghcr.io/grafana/issue-team-scheduler-regex-labeler:v0.12"
image: "docker://ghcr.io/grafana/issue-team-scheduler-regex-labeler:v0.13"

0 comments on commit 7234171

Please sign in to comment.