Skip to content

Commit

Permalink
Merge pull request #68 from tstromberg/tag-mousing
Browse files Browse the repository at this point in the history
UI: add titles to tags, improve similarity/omit display
  • Loading branch information
tstromberg authored May 7, 2020
2 parents c97799d + b218b89 commit aed7337
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 34 deletions.
2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ Triage Party has an automatic tagging mechanism that adds annotations which can
* `recv-q`: the original author commented with a question more recently than a member of the project has commented (may be waiting on an answer from a project member)
* `member-last`: a member of the organization was the last commenter
* `author-last`: the original author was the last commenter
* `other-last`: an unrelated individual was the last commenter
* `closed`: the issue or PR has been closed
* `similar`: the issue or PR appears to be similar to another
8 changes: 7 additions & 1 deletion pkg/hubbub/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,16 @@ type Conversation struct {
ClosedAt time.Time `json:"closed_at"`
ClosedBy *github.User `json:"closed_by"`

Tags []string `json:"tags"`
Tags []Tag `json:"tags"`

// Similar issues to this one
Similar []*RelatedConversation `json:"similar"`

Milestone string `json:"milestone"`
}

// Tag is used for automatically labelling issues
type Tag struct {
ID string `json:"id"`
Description string `json:"description"`
}
3 changes: 3 additions & 0 deletions pkg/hubbub/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package hubbub
import (
"context"
"fmt"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -177,6 +178,8 @@ func (h *Engine) IssueSummary(i *github.Issue, cs []*github.IssueComment, author
co.Reactions[k] += v
}
co.ClosedBy = i.GetClosedBy()

sort.Slice(co.Tags, func(i, j int) bool { return co.Tags[i].ID < co.Tags[j].ID })
return co
}

Expand Down
75 changes: 60 additions & 15 deletions pkg/hubbub/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package hubbub

import (
"fmt"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -56,9 +55,9 @@ func (h *Engine) conversation(i GitHubItem, cs []CommentLike, authorIsMember boo
}

lastQuestion := time.Time{}
tags := map[string]bool{}
seenCommenters := map[string]bool{}
seenClosedCommenters := map[string]bool{}
seenMemberComment := false

for _, c := range cs {
// We don't like their kind around here
Expand Down Expand Up @@ -88,7 +87,10 @@ func (h *Engine) conversation(i GitHubItem, cs []CommentLike, authorIsMember boo
co.AccumulatedHoldTime += c.GetCreatedAt().Sub(co.LatestAuthorResponse)
}
co.LatestMemberResponse = c.GetCreatedAt()
tags["commented"] = true
if !seenMemberComment {
co.Tags = append(co.Tags, commentedTag())
seenMemberComment = true
}
}

if strings.Contains(c.GetBody(), "?") {
Expand All @@ -110,41 +112,35 @@ func (h *Engine) conversation(i GitHubItem, cs []CommentLike, authorIsMember boo
}

if co.LatestMemberResponse.After(co.LatestAuthorResponse) {
tags["send"] = true
co.Tags = append(co.Tags, sendTag())
co.CurrentHoldTime = 0
} else if !authorIsMember {
tags["recv"] = true
co.Tags = append(co.Tags, recvTag())
co.CurrentHoldTime += time.Since(co.LatestAuthorResponse)
co.AccumulatedHoldTime += time.Since(co.LatestAuthorResponse)
}

if lastQuestion.After(co.LatestMemberResponse) {
tags["recv-q"] = true
co.Tags = append(co.Tags, recvQTag())
}

if len(cs) > 0 {
last := cs[len(cs)-1]
assoc := strings.ToLower(last.GetAuthorAssociation())
if assoc == "none" {
if last.GetUser().GetLogin() == i.GetUser().GetLogin() {
tags["author-last"] = true
} else {
tags["other-last"] = true
co.Tags = append(co.Tags, authorLast())
}
} else {
tags[fmt.Sprintf("%s-last", assoc)] = true
co.Tags = append(co.Tags, assocLast(assoc))
}
co.Updated = last.GetUpdatedAt()
}

if co.State == "closed" {
tags["closed"] = true
co.Tags = append(co.Tags, closedTag())
}

for k := range tags {
co.Tags = append(co.Tags, k)
}
sort.Strings(co.Tags)
co.CommentersTotal = len(seenCommenters)
co.ClosedCommentersTotal = len(seenClosedCommenters)

Expand All @@ -158,3 +154,52 @@ func (h *Engine) conversation(i GitHubItem, cs []CommentLike, authorIsMember boo
co.ReactionsPerMonth = float64(co.ReactionsTotal) / float64(months)
return co
}

func commentedTag() Tag {
return Tag{
ID: "commented",
Description: "A project member has commented on this",
}
}

func sendTag() Tag {
return Tag{
ID: "send",
Description: "A project member commented more recently than the author",
}
}

func recvTag() Tag {
return Tag{
ID: "recv",
Description: "The author commented more recently than a project member",
}
}

func recvQTag() Tag {
return Tag{
ID: "recv-q",
Description: "The author has asked a question since the last project member commented",
}
}

func authorLast() Tag {
return Tag{
ID: "author-last",
Description: "The last commenter was the original author",
}
}

func assocLast(role string) Tag {
return Tag{
ID: fmt.Sprintf("%s-last", role),
Description: fmt.Sprintf("The last commenter was a project %s", role),
}
}

func closedTag() Tag {
return Tag{
ID: "closed",
Description: "This item has been closed",
}
}
4 changes: 2 additions & 2 deletions pkg/hubbub/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ func matchNegateRegex(value string, re *regexp.Regexp, negate bool) bool {
return negate
}

func matchTag(tags []string, re *regexp.Regexp, negate bool) bool {
func matchTag(tags []Tag, re *regexp.Regexp, negate bool) bool {
for _, s := range tags {
if re.MatchString(s) {
if re.MatchString(s.ID) {
return !negate
}
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/hubbub/pull_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package hubbub
import (
"context"
"fmt"
"sort"
"time"

"github.com/google/go-github/v31/github"
Expand Down Expand Up @@ -68,6 +69,7 @@ func (h *Engine) updatePRs(ctx context.Context, org string, project string, stat
}
}

// TODO: update tables for cached entries too!
h.updateSimilarityTables(pr.GetTitle(), pr.GetHTMLURL())
allPRs = append(allPRs, pr)
}
Expand Down Expand Up @@ -139,15 +141,16 @@ func (h *Engine) PRSummary(pr *github.PullRequest, cs []*github.PullRequestComme
}
co := h.conversation(pr, cl, isMember(pr.GetAuthorAssociation()))
if reviewed {
co.Tags = append(co.Tags, "reviewed")
co.Tags = append(co.Tags, Tag{ID: "reviewed", Description: "PR has been reviewed at least once"})
}

if pr.GetDraft() {
co.Tags = append(co.Tags, "draft")
co.Tags = append(co.Tags, Tag{ID: "draft", Description: "Draft PR"})
}

// Technically not the same thing, but close enough for me.
co.ClosedBy = pr.GetMergedBy()

sort.Slice(co.Tags, func(i, j int) bool { return co.Tags[i].ID < co.Tags[j].ID })
return co
}
8 changes: 8 additions & 0 deletions pkg/hubbub/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ func (h *Engine) SearchIssues(ctx context.Context, org string, project string, f
}

co.Similar = h.FindSimilar(co)
if len(co.Similar) > 0 {
co.Tags = append(co.Tags, Tag{ID: "similar", Description: "Title appears similar to another PR or issue"})
}

filtered = append(filtered, co)
}
Expand Down Expand Up @@ -228,6 +231,11 @@ func (h *Engine) SearchPullRequests(ctx context.Context, org string, project str

co := h.PRSummary(pr, comments)
co.Labels = pr.Labels
co.Similar = h.FindSimilar(co)
if len(co.Similar) > 0 {
co.Tags = append(co.Tags, Tag{ID: "similar", Description: "Title appears similar to another PR or issue"})
}

h.seen[co.URL] = co

if !postFetchMatch(co, fs) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/hubbub/similar.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (h *Engine) FindSimilar(co *Conversation) []*RelatedConversation {

oco := h.seen[url]
if oco == nil {
klog.Warningf("find similar: no conversation found for %s", url)
klog.V(1).Infof("find similar: no conversation found for %s -- must have been filtered out", url)
continue
}
klog.V(2).Infof("found %s: %q", url, oco.Title)
Expand Down
10 changes: 7 additions & 3 deletions pkg/site/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"k8s.io/klog/v2"
)

const VERSION = "v1.0.0-beta.2"
const VERSION = "v1.0.0-beta.3"

var (
nonWordRe = regexp.MustCompile(`\W`)
Expand Down Expand Up @@ -151,10 +151,13 @@ func (h *Handlers) Collection() http.HandlerFunc {

return func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
dataAge := time.Time{}
id := strings.TrimPrefix(r.URL.Path, "/s/")

defer func() {
klog.Infof("Collection request complete in %s", time.Since(start))
klog.Infof("Served %q request within %s from data %s old", id, time.Since(start), time.Since(dataAge))
}()
id := strings.TrimPrefix(r.URL.Path, "/s/")

playerChoices := []string{"Select a player"}
players := getInt(r.URL, "players", 1)
player := getInt(r.URL, "player", 0)
Expand Down Expand Up @@ -203,6 +206,7 @@ func (h *Handlers) Collection() http.HandlerFunc {
klog.V(2).Infof("lookup %q result: %d items", id, len(result.RuleResults))
}

dataAge = result.Time
warning := ""
if result.Time.IsZero() {
warning = fmt.Sprintf("Triage Party started %s ago, and is serving stale results while refreshing in the background", humanDuration(time.Since(h.startTime)))
Expand Down
13 changes: 7 additions & 6 deletions site/collection.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<a href="{{ .URL }}" title="{{ .LastCommentBody }}"><strong>{{ .Title }}</strong></a>
{{ if .Similar }}<div class="similar"><ul>
{{ range .Similar }}
<li><a href="{{ .URL }}" title="Issue title is similar to #{{ .ID }}">#{{ .ID }} &mdash; {{ .Title }}</a></li>
<li><a href="{{ .URL }}" title="Title is similar to #{{ .ID }}">Similar to {{ if eq .Type "pull_request" }}PR{{ end }}#{{ .ID }}: {{ .Title }}</a></li>
{{ end }}
</div>
{{ end }}
Expand All @@ -132,17 +132,18 @@
{{ end }}
</td>
<td class="cell-tags">
{{ range .Tags }}<div class="gh-tag tag-{{ . }}">{{ . }}</div> {{ end }}
{{ range .Tags }}<div class="gh-tag tag-{{ .ID }}" title="{{ .Description }}">{{ .ID }}</div> {{ end }}
</td>
</tr>
{{ end }}
{{ end }}
{{ if gt .Duplicates 2 }}
<tr class="dupes"><td colspan="12">{{ .Duplicates }} previously listed
{{ if eq .Duplicates 1 }}item{{ else }}items{{ end }} are hidden from this table:
{{ range .Items }}
{{ if .Hidden }}
<a href="{{ .URL }}" title="{{ .Title }}">#{{ .ID }}</a>
{{ if eq .Duplicates 1 }}item{{ else }}items{{ end }} omitted{{ if lt .Duplicates 20 }}:
{{ range .Items }}
{{ if .Hidden }}
<a href="{{ .URL }}" title="{{ .Title }}">#{{ .ID }}</a>
{{ end }}
{{ end }}
{{ end }}
</td></tr>
Expand Down
3 changes: 0 additions & 3 deletions site/static/css/tparty.css
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,6 @@ td:last-child { padding-right: 0.2em !important; }
font-style: italic;
}

.similar a::before {
content: "~"
}
.similar a {
color: #3F1D09;
}
Expand Down

0 comments on commit aed7337

Please sign in to comment.