Use Runner

This revamps code quite a bit. Series handling has been moved into the
gerrit client, it also handles caching.

The Runner logic itself has been greatly simplified.

The runner logic has been moved into the runner.go, submitqueue.go is
gone.

The "per-run result object" concept has been dropped - we instead just
use annotated logs.

Also, we switched to apex/log
This commit is contained in:
Florian Klink 2019-12-02 10:00:32 +01:00
parent 7bafef7a84
commit 04a24a0c60
14 changed files with 486 additions and 537 deletions

View file

@ -5,7 +5,7 @@ import (
"fmt"
goGerrit "github.com/andygrunwald/go-gerrit"
log "github.com/sirupsen/logrus"
"github.com/apex/log"
)
// Changeset represents a single changeset
@ -14,8 +14,8 @@ type Changeset struct {
changeInfo *goGerrit.ChangeInfo
ChangeID string
Number int
IsVerified bool
IsCodeReviewed bool
Verified int
CodeReviewed int
HashTags []string
CommitID string
ParentCommitIDs []string
@ -29,8 +29,8 @@ func MakeChangeset(changeInfo *goGerrit.ChangeInfo) *Changeset {
changeInfo: changeInfo,
ChangeID: changeInfo.ChangeID,
Number: changeInfo.Number,
IsVerified: isVerified(changeInfo),
IsCodeReviewed: isCodeReviewed(changeInfo),
Verified: labelInfoToInt(changeInfo.Labels["Verified"]),
CodeReviewed: labelInfoToInt(changeInfo.Labels["Code-Review"]),
HashTags: changeInfo.Hashtags,
CommitID: changeInfo.CurrentRevision, // yes, this IS the commit ID.
ParentCommitIDs: getParentCommitIDs(changeInfo),
@ -39,12 +39,6 @@ func MakeChangeset(changeInfo *goGerrit.ChangeInfo) *Changeset {
}
}
// MakeMockChangeset creates a mock changeset
// func MakeMockChangeset(isVerified, IsCodeReviewed bool, hashTags []string, commitID string, parentCommitIDs []string, ownerName, subject string) *Changeset {
// //TODO impl
// return nil
//}
// HasTag returns true if a Changeset has the given tag.
func (c *Changeset) HasTag(tag string) bool {
hashTags := c.HashTags
@ -56,6 +50,18 @@ func (c *Changeset) HasTag(tag string) bool {
return false
}
// IsVerified returns true if the changeset passed CI,
// that's when somebody left the Approved (+1) on the "Verified" label
func (c *Changeset) IsVerified() bool {
return c.Verified == 1
}
// IsCodeReviewed returns true if the changeset passed code review,
// that's when somebody left the Recommended (+2) on the "Code-Review" label
func (c *Changeset) IsCodeReviewed() bool {
return c.CodeReviewed == 2
}
func (c *Changeset) String() string {
var b bytes.Buffer
b.WriteString("Changeset")
@ -76,18 +82,21 @@ func FilterChangesets(changesets []*Changeset, f func(*Changeset) bool) []*Chang
return newChangesets
}
// isVerified returns true if the code passed CI,
// that's when somebody left the Approved (+1) on the "Verified" label
func isVerified(changeInfo *goGerrit.ChangeInfo) bool {
labels := changeInfo.Labels
return labels["Verified"].Approved.AccountID != 0
}
// isCodeReviewed returns true if the code passed code review,
// that's when somebody left the Recommended (+2) on the "Code-Review" label
func isCodeReviewed(changeInfo *goGerrit.ChangeInfo) bool {
labels := changeInfo.Labels
return labels["Code-Review"].Recommended.AccountID != 0
// labelInfoToInt converts a goGerrit.LabelInfo to -2…+2 int
func labelInfoToInt(labelInfo goGerrit.LabelInfo) int {
if labelInfo.Recommended.AccountID != 0 {
return 2
}
if labelInfo.Approved.AccountID != 0 {
return 1
}
if labelInfo.Disliked.AccountID != 0 {
return -1
}
if labelInfo.Rejected.AccountID != 0 {
return -2
}
return 0
}
// getParentCommitIDs returns the parent commit IDs of the goGerrit.ChangeInfo