Skip to content

Commit 1c4b79c

Browse files
thatnealpateldr2chase
authored andcommitted
internal/relui,task: use FetchReleaseMilestone directly
Change-Id: I236f2bf46419bb9de394350ac1ff880060b7f7fd Reviewed-on: https://go-review.googlesource.com/c/build/+/820460 Reviewed-by: Nicholas Husin <nsh@golang.org> Reviewed-by: Nicholas Husin <husin@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Neal Patel <nealpatel@google.com>
1 parent 0ef48a1 commit 1c4b79c

4 files changed

Lines changed: 11 additions & 24 deletions

File tree

internal/relui/buildrelease_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,8 @@ func TestMinorReleaseSecurityCoalesceRestart(t *testing.T) {
812812
}
813813

814814
// Second run: a restart forks a new checkpoint. The branch name embeds a
815-
// minute-resolution timestamp, so a same-minute restart collides on the
816-
// branch name (real Gerrit 409). When the minute has rolled over, the
815+
// second-resolution timestamp, so a same-second restart collides on the
816+
// branch name (real Gerrit 409). When the second has rolled over, the
817817
// restart succeeds with a distinct name; either way, the first run's
818818
// checkpoint branch must remain exactly as it was.
819819
second, err := deps.buildTasks.createSecurityCheckpoint(taskCtx, bi, cls)
@@ -822,7 +822,7 @@ func TestMinorReleaseSecurityCoalesceRestart(t *testing.T) {
822822
if !errors.As(err, &httpErr) || httpErr.Res.StatusCode != http.StatusConflict {
823823
t.Fatalf("second createSecurityCheckpoint: %v", err)
824824
}
825-
t.Logf("same-minute restart collided on the timestamped checkpoint name (expected): %v", err)
825+
t.Logf("same-second restart collided on the timestamped checkpoint name (expected): %v", err)
826826
} else if second == first {
827827
t.Errorf("restart reused checkpoint name %q; want a distinct timestamped branch", second)
828828
}

internal/relui/workflows.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import (
4747
"golang.org/x/net/context/ctxhttp"
4848
"golang.org/x/vulndb/report"
4949
"google.golang.org/protobuf/types/known/structpb"
50-
yaml "gopkg.in/yaml.v3"
5150
)
5251

5352
// DefinitionHolder holds workflow definitions.
@@ -1016,19 +1015,10 @@ func (b *BuildReleaseTasks) fetchSecurityMilestone(ctx *wf.TaskContext, mileston
10161015
ctx.Printf("No security milestone specified, no security milestone to fetch.")
10171016
return nil, nil
10181017
}
1019-
const project = "security-metadata"
1020-
head, err := b.PrivateGerritClient.ReadBranchHead(ctx, project, "main")
1018+
rm, err := task.FetchReleaseMilestone(ctx, b.PrivateGerritClient, milestoneNum)
10211019
if err != nil {
10221020
return nil, err
10231021
}
1024-
raw, err := b.PrivateGerritClient.ReadFile(ctx, project, head, path.Join("data", "milestones", milestoneNum+".yaml"))
1025-
if err != nil {
1026-
return nil, err
1027-
}
1028-
var rm relmeta.ReleaseMilestone
1029-
if err := yaml.Unmarshal(raw, &rm); err != nil {
1030-
return nil, fmt.Errorf("cannot YAML unmarshal the milestone: %v", err)
1031-
}
10321022
return &rm, nil
10331023
}
10341024

@@ -1233,9 +1223,9 @@ func (b *BuildReleaseTasks) createInternalReleaseBranches(ctx *wf.TaskContext, b
12331223
return internalBranches, nil
12341224
}
12351225

1236-
func (b *BuildReleaseTasks) createSecurityCherryPicks(ctx *wf.TaskContext, releaseBranches []string, cls []*gerrit.ChangeInfo) ([]*gerrit.ChangeInfo, error) {
1226+
func (b *BuildReleaseTasks) createSecurityCherryPicks(ctx *wf.TaskContext, releaseBranches []string, changes []*gerrit.ChangeInfo) ([]*gerrit.ChangeInfo, error) {
12371227
var cherryPicks []*gerrit.ChangeInfo
1238-
for _, ci := range cls {
1228+
for _, ci := range changes {
12391229
for _, releaseBranch := range releaseBranches {
12401230
// Check whether a non-abandoned cherry-pick of this
12411231
// change already exists on the target branch (e.g. from
@@ -1315,12 +1305,9 @@ func (b *BuildReleaseTasks) submitCherryPicks(ctx *wf.TaskContext, cherryPicks [
13151305
return submitted, nil
13161306
}
13171307

1318-
// majorFromMinor converts a release branch name from its minor version form to
1319-
// its major version form (i.e., release-branch.go1.2.3 to release-branch.go1.2).
13201308
func majorFromMinor(branch string) string {
13211309
stripped := strings.TrimPrefix(branch, "release-branch.")
1322-
major := goversion.Lang(stripped)
1323-
return "release-branch." + major
1310+
return "release-branch." + goversion.Lang(stripped)
13241311
}
13251312

13261313
func privateChangeURL[T int | string](clNum T) string {

internal/task/announce.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ type SecurityCommunicationTasks struct {
939939
//
940940
// It returns an empty string when there are 0 security fixes.
941941
func (t SecurityCommunicationTasks) GetSecuritySummary(ctx *workflow.TaskContext, milestoneNum string) (string, error) {
942-
rm, err := fetchReleaseMilestone(ctx, t.PrivateGerrit, milestoneNum)
942+
rm, err := FetchReleaseMilestone(ctx, t.PrivateGerrit, milestoneNum)
943943
if err != nil {
944944
return "", err
945945
}
@@ -971,7 +971,7 @@ func (t SecurityCommunicationTasks) GetSecuritySummary(ctx *workflow.TaskContext
971971
// GetSecurityReleaseNotes fetches a list of descriptions, one for each distinct security fix
972972
// included in the release identified by milestoneNum, in Markdown format.
973973
func (t SecurityCommunicationTasks) GetSecurityReleaseNotes(ctx *workflow.TaskContext, milestoneNum string) (releaseNotes []string, _ error) {
974-
rm, err := fetchReleaseMilestone(ctx, t.PrivateGerrit, milestoneNum)
974+
rm, err := FetchReleaseMilestone(ctx, t.PrivateGerrit, milestoneNum)
975975
if err != nil {
976976
return nil, err
977977
}
@@ -1000,7 +1000,7 @@ You can check with the security release coordinator for this release to confirm
10001000
numOnlyRE = regexp.MustCompile(`^\d+$`)
10011001
)
10021002

1003-
func fetchReleaseMilestone(ctx context.Context, private GerritClient, milestoneNum string) (relmeta.ReleaseMilestone, error) {
1003+
func FetchReleaseMilestone(ctx context.Context, private GerritClient, milestoneNum string) (relmeta.ReleaseMilestone, error) {
10041004
const project = "security-metadata"
10051005
head, err := private.ReadBranchHead(ctx, project, "main")
10061006
if err != nil {

internal/task/privx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (x *PrivXPatch) NewDefinition(tagx *TagXReposTasks) *wf.Definition {
8282

8383
func (x *PrivXPatch) PullMilestone(ctx *wf.TaskContext, milestone string) (*relmeta.ReleaseMilestone, error) {
8484
// TODO(nealpatel): Is this ceremony?
85-
rm, err := fetchReleaseMilestone(ctx, x.PrivateGerrit, milestone)
85+
rm, err := FetchReleaseMilestone(ctx, x.PrivateGerrit, milestone)
8686
return &rm, err
8787
}
8888

0 commit comments

Comments
 (0)