dmitri.shuralyov.com/service/change/maintner

Display hashtags as labels.

Also remove commented out sort code. It's normal and expected for
Gerrit IDs not to line up with created times. As documented at
https://godoc.org/golang.org/x/build/maintner#GerritCL.Number:

> Number is the CL number on the Gerrit server (e.g. 1, 2, 3). Gerrit CL
> numbers are sparse (CL N does not guarantee that CL N-1 exists) and
> Gerrit issues CL's out of order - it may issue CL N, then CL (N - 18),
> then CL (N - 40).
dmitshur committed 6 years ago commit e712a6949fbe7fe04b2f49fc22810f827b17f3f8
Showing partial commit. Full Commit
Collapse all
maintner/maintner.go
@@ -9,10 +9,11 @@ import (
	"sort"
	"strings"
	"unicode"

	"dmitri.shuralyov.com/service/change"
	"github.com/shurcooL/issues"
	"github.com/shurcooL/users"
	"golang.org/x/build/maintner"
	"sourcegraph.com/sourcegraph/go-diff/diff"
)

@@ -44,24 +45,31 @@ func (s service) List(_ context.Context, repo string, opt change.ListOptions) ([
		case opt.Filter == change.FilterOpen && state != change.OpenState:
			return nil
		case opt.Filter == change.FilterClosedMerged && !(state == change.ClosedState || state == change.MergedState):
			return nil
		}
		var labels []issues.Label
		cl.Meta.Hashtags().Foreach(func(hashtag string) {
			labels = append(labels, issues.Label{
				Name:  hashtag,
				Color: issues.RGB{R: 0xed, G: 0xed, B: 0xed}, // A default light gray.
			})
		})
		is = append(is, change.Change{
			ID:        uint64(cl.Number),
			State:     state,
			Title:     firstParagraph(cl.Commit.Msg),
			Labels:    labels,
			Author:    gerritUser(cl.Commit.Author),
			CreatedAt: cl.Created,
			Replies:   len(cl.Messages),
		})
		return nil
	})
	if err != nil {
		return nil, err
	}
	//sort.Sort(sort.Reverse(byID(is))) // For some reason, IDs don't completely line up with created times.
	sort.Slice(is, func(i, j int) bool {
		return is[i].CreatedAt.After(is[j].CreatedAt)
	})
	return is, nil
}
@@ -100,14 +108,22 @@ func (s service) Get(_ context.Context, repo string, id uint64) (change.Change,
	}
	cl := project.CL(int32(id))
	if cl == nil || cl.Private {
		return change.Change{}, os.ErrNotExist
	}
	var labels []issues.Label
	cl.Meta.Hashtags().Foreach(func(hashtag string) {
		labels = append(labels, issues.Label{
			Name:  hashtag,
			Color: issues.RGB{R: 0xed, G: 0xed, B: 0xed}, // A default light gray.
		})
	})
	return change.Change{
		ID:           uint64(cl.Number),
		State:        state(cl.Status),
		Title:        firstParagraph(cl.Commit.Msg),
		Labels:       labels,
		Author:       gerritUser(cl.Commit.Author),
		CreatedAt:    cl.Created,
		Replies:      len(cl.Messages),
		Commits:      int(cl.Version),
		ChangedFiles: 0, // TODO.