feat(3p/gerrit-queue): Patch to use Gerrit 'Autosubmit' label
... instead of a hashtag in Gerrit.
Might be easier to review here:
24f5a642af
Change-Id: I1ae8d4607f7cb858135f88411c82e1a353b28105
This commit is contained in:
parent
417a1ba9eb
commit
afa2d08fe7
2 changed files with 193 additions and 0 deletions
187
third_party/gerrit-queue/0001-gerrit-Use-a-Gerrit-label-instead-of-hashtag-for-aut.patch
vendored
Normal file
187
third_party/gerrit-queue/0001-gerrit-Use-a-Gerrit-label-instead-of-hashtag-for-aut.patch
vendored
Normal file
|
@ -0,0 +1,187 @@
|
|||
From 24f5a642af3aa1627bbff977f0a101907a02c69f Mon Sep 17 00:00:00 2001
|
||||
From: Vincent Ambo <mail@tazj.in>
|
||||
Date: Thu, 9 Dec 2021 13:49:16 +0300
|
||||
Subject: [PATCH] gerrit: Use a Gerrit label instead of hashtag for autosubmit
|
||||
|
||||
This moves to using a Gerrit label ('Autosubmit') with boolean values
|
||||
for determining whether a developer wants to have a change
|
||||
automatically submitted.
|
||||
|
||||
See also https://cl.tvl.fyi/c/depot/+/4172
|
||||
---
|
||||
README.md | 2 +-
|
||||
gerrit/changeset.go | 20 +++++++++-----------
|
||||
gerrit/client.go | 16 ----------------
|
||||
main.go | 11 ++---------
|
||||
submitqueue/runner.go | 12 +++++-------
|
||||
5 files changed, 17 insertions(+), 44 deletions(-)
|
||||
|
||||
diff --git a/README.md b/README.md
|
||||
index d021fd0..9ffb81b 100644
|
||||
--- a/README.md
|
||||
+++ b/README.md
|
||||
@@ -8,7 +8,7 @@ await CI feedback on a rebased changeset, then one clicks submit, and
|
||||
effectively makes everybody else rebase again. `gerrit-queue` is meant to
|
||||
remove these races to master.
|
||||
|
||||
-Developers can add a specific tag `submit_me` to all changesets in a series,
|
||||
+Developers can set the `Autosubmit` label to `+1` on all changesets in a series,
|
||||
and if all preconditions on are met ("submittable" in gerrit speech, this
|
||||
usually means passing CI and passing Code Review), `gerrit-queue` takes care of
|
||||
rebasing and submitting it to master
|
||||
diff --git a/gerrit/changeset.go b/gerrit/changeset.go
|
||||
index 0a0a607..f71032a 100644
|
||||
--- a/gerrit/changeset.go
|
||||
+++ b/gerrit/changeset.go
|
||||
@@ -16,8 +16,8 @@ type Changeset struct {
|
||||
Number int
|
||||
Verified int
|
||||
CodeReviewed int
|
||||
+ Autosubmit int
|
||||
Submittable bool
|
||||
- HashTags []string
|
||||
CommitID string
|
||||
ParentCommitIDs []string
|
||||
OwnerName string
|
||||
@@ -32,8 +32,8 @@ func MakeChangeset(changeInfo *goGerrit.ChangeInfo) *Changeset {
|
||||
Number: changeInfo.Number,
|
||||
Verified: labelInfoToInt(changeInfo.Labels["Verified"]),
|
||||
CodeReviewed: labelInfoToInt(changeInfo.Labels["Code-Review"]),
|
||||
+ Autosubmit: labelInfoToInt(changeInfo.Labels["Autosubmit"]),
|
||||
Submittable: changeInfo.Submittable,
|
||||
- HashTags: changeInfo.Hashtags,
|
||||
CommitID: changeInfo.CurrentRevision, // yes, this IS the commit ID.
|
||||
ParentCommitIDs: getParentCommitIDs(changeInfo),
|
||||
OwnerName: changeInfo.Owner.Name,
|
||||
@@ -41,15 +41,13 @@ func MakeChangeset(changeInfo *goGerrit.ChangeInfo) *Changeset {
|
||||
}
|
||||
}
|
||||
|
||||
-// HasTag returns true if a Changeset has the given tag.
|
||||
-func (c *Changeset) HasTag(tag string) bool {
|
||||
- hashTags := c.HashTags
|
||||
- for _, hashTag := range hashTags {
|
||||
- if hashTag == tag {
|
||||
- return true
|
||||
- }
|
||||
- }
|
||||
- return false
|
||||
+// IsAutosubmit returns true if the changeset is intended to be
|
||||
+// automatically submitted by gerrit-queue.
|
||||
+//
|
||||
+// This is determined by the Change Owner setting +1 on the
|
||||
+// "Autosubmit" label.
|
||||
+func (c *Changeset) IsAutosubmit() bool {
|
||||
+ return c.Autosubmit == 1
|
||||
}
|
||||
|
||||
// IsVerified returns true if the changeset passed CI,
|
||||
diff --git a/gerrit/client.go b/gerrit/client.go
|
||||
index 415871d..314f972 100644
|
||||
--- a/gerrit/client.go
|
||||
+++ b/gerrit/client.go
|
||||
@@ -26,7 +26,6 @@ type IClient interface {
|
||||
GetChangesetURL(changeset *Changeset) string
|
||||
SubmitChangeset(changeset *Changeset) (*Changeset, error)
|
||||
RebaseChangeset(changeset *Changeset, ref string) (*Changeset, error)
|
||||
- RemoveTag(changeset *Changeset, tag string) (*Changeset, error)
|
||||
ChangesetIsRebasedOnHEAD(changeset *Changeset) bool
|
||||
SerieIsRebasedOnHEAD(serie *Serie) bool
|
||||
FilterSeries(filter func(s *Serie) bool) []*Serie
|
||||
@@ -161,21 +160,6 @@ func (c *Client) RebaseChangeset(changeset *Changeset, ref string) (*Changeset,
|
||||
return c.fetchChangeset(changeInfo.ChangeID)
|
||||
}
|
||||
|
||||
-// RemoveTag removes the submit queue tag from a changeset and updates gerrit
|
||||
-// we never add, that's something users should do in the GUI.
|
||||
-func (c *Client) RemoveTag(changeset *Changeset, tag string) (*Changeset, error) {
|
||||
- hashTags := changeset.HashTags
|
||||
- newHashTags := []string{}
|
||||
- for _, hashTag := range hashTags {
|
||||
- if hashTag != tag {
|
||||
- newHashTags = append(newHashTags, hashTag)
|
||||
- }
|
||||
- }
|
||||
- // TODO: implement setting hashtags api in go-gerrit and use here
|
||||
- // https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#set-hashtags
|
||||
- return changeset, nil
|
||||
-}
|
||||
-
|
||||
// GetBaseURL returns the gerrit base URL
|
||||
func (c *Client) GetBaseURL() string {
|
||||
return c.baseURL
|
||||
diff --git a/main.go b/main.go
|
||||
index 9f3277e..d8577da 100644
|
||||
--- a/main.go
|
||||
+++ b/main.go
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
- var URL, username, password, projectName, branchName, submitQueueTag string
|
||||
+ var URL, username, password, projectName, branchName string
|
||||
var fetchOnly bool
|
||||
var triggerInterval int
|
||||
|
||||
@@ -64,13 +64,6 @@ func main() {
|
||||
Destination: &branchName,
|
||||
Value: "master",
|
||||
},
|
||||
- cli.StringFlag{
|
||||
- Name: "submit-queue-tag",
|
||||
- Usage: "the tag used to submit something to the submit queue",
|
||||
- EnvVar: "SUBMIT_QUEUE_TAG",
|
||||
- Destination: &submitQueueTag,
|
||||
- Value: "submit_me",
|
||||
- },
|
||||
cli.IntFlag{
|
||||
Name: "trigger-interval",
|
||||
Usage: "How often we should trigger ourselves (interval in seconds)",
|
||||
@@ -102,7 +95,7 @@ func main() {
|
||||
}
|
||||
log.Infof("Successfully connected to gerrit at %s", URL)
|
||||
|
||||
- runner := submitqueue.NewRunner(l, gerrit, submitQueueTag)
|
||||
+ runner := submitqueue.NewRunner(l, gerrit)
|
||||
|
||||
handler := frontend.MakeFrontend(rotatingLogHandler, gerrit, runner)
|
||||
|
||||
diff --git a/submitqueue/runner.go b/submitqueue/runner.go
|
||||
index 0d8bcce..6e4a54a 100644
|
||||
--- a/submitqueue/runner.go
|
||||
+++ b/submitqueue/runner.go
|
||||
@@ -20,26 +20,24 @@ type Runner struct {
|
||||
wipSerie *gerrit.Serie
|
||||
logger *log.Logger
|
||||
gerrit *gerrit.Client
|
||||
- submitQueueTag string // the tag used to submit something to the submit queue
|
||||
}
|
||||
|
||||
// NewRunner creates a new Runner struct
|
||||
-func NewRunner(logger *log.Logger, gerrit *gerrit.Client, submitQueueTag string) *Runner {
|
||||
+func NewRunner(logger *log.Logger, gerrit *gerrit.Client) *Runner {
|
||||
return &Runner{
|
||||
- logger: logger,
|
||||
- gerrit: gerrit,
|
||||
- submitQueueTag: submitQueueTag,
|
||||
+ logger: logger,
|
||||
+ gerrit: gerrit,
|
||||
}
|
||||
}
|
||||
|
||||
// isAutoSubmittable determines if something could be autosubmitted, potentially requiring a rebase
|
||||
// for this, it needs to:
|
||||
-// * have the auto-submit label
|
||||
+// * have the "Autosubmit" label set to +1
|
||||
// * have gerrit's 'submittable' field set to true
|
||||
// it doesn't check if the series is rebased on HEAD
|
||||
func (r *Runner) isAutoSubmittable(s *gerrit.Serie) bool {
|
||||
for _, c := range s.ChangeSets {
|
||||
- if c.Submittable != true || !c.HasTag(r.submitQueueTag) {
|
||||
+ if c.Submittable != true || !c.IsAutosubmit() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
--
|
||||
2.33.1
|
||||
|
6
third_party/gerrit-queue/default.nix
vendored
6
third_party/gerrit-queue/default.nix
vendored
|
@ -12,6 +12,12 @@ pkgs.buildGoModule {
|
|||
hash = "sha256:1x0g6fd5hymf6a8wxj1b1xi4x1hmwpnx4f2cdidgvsyd77v902c1";
|
||||
};
|
||||
|
||||
# Add TVL patches to bend gerrit-queue functionality to our will.
|
||||
patches = [
|
||||
# Use 'Autosubmit' label instead of Gerrit hashtags.
|
||||
./0001-gerrit-Use-a-Gerrit-label-instead-of-hashtag-for-aut.patch
|
||||
];
|
||||
|
||||
# gerrit-queue embeds static assets which need to be generated
|
||||
nativeBuildInputs = [ pkgs.statik ];
|
||||
preBuild = ''
|
||||
|
|
Loading…
Reference in a new issue