-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a method that will reconcile the issue tracker labels with the configured labels. For #64. Change-Id: I51492fcfdd0ced31257b0355a8570489d3402499 Reviewed-on: https://go-review.googlesource.com/c/oscar/+/637155 Reviewed-by: Tatiana Bradley <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
- Loading branch information
Showing
3 changed files
with
185 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package labels | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"maps" | ||
"slices" | ||
"testing" | ||
|
||
"golang.org/x/oscar/internal/github" | ||
"golang.org/x/oscar/internal/testutil" | ||
) | ||
|
||
func TestSyncLabels(t *testing.T) { | ||
m := map[string]github.Label{ | ||
"A": {Name: "A", Description: "a", Color: "a"}, | ||
"B": {Name: "B", Description: "", Color: "b"}, | ||
"C": {Name: "C", Description: "c", Color: "c"}, | ||
"D": {Name: "D", Description: "d", Color: "d"}, | ||
} | ||
cats := []Category{ | ||
{Label: "A", Description: "a"}, // same as tracker | ||
{Label: "B", Description: "b"}, // set empty tracker description | ||
{Label: "C", Description: "other"}, // different descriptions | ||
// D in tracker but not in cats | ||
{Label: "E", Description: "e"}, // create | ||
} | ||
tl := &testTrackerLabels{m} | ||
|
||
if err := syncLabels(context.Background(), testutil.Slogger(t), cats, tl); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
want := map[string]github.Label{ | ||
"A": {Name: "A", Description: "a", Color: "a"}, | ||
"B": {Name: "B", Description: "b", Color: "b"}, // added B description | ||
"C": {Name: "C", Description: "c", Color: "c"}, | ||
"D": {Name: "D", Description: "d", Color: "d"}, | ||
"E": {Name: "E", Description: "e", Color: labelColor}, // added E | ||
} | ||
|
||
if got := tl.m; !maps.Equal(got, want) { | ||
t.Errorf("\ngot %v\nwant %v", got, want) | ||
} | ||
} | ||
|
||
type testTrackerLabels struct { | ||
m map[string]github.Label | ||
} | ||
|
||
func (t *testTrackerLabels) CreateLabel(ctx context.Context, lab github.Label) error { | ||
if _, ok := t.m[lab.Name]; ok { | ||
return errors.New("label exists") | ||
} | ||
t.m[lab.Name] = lab | ||
return nil | ||
} | ||
|
||
func (t *testTrackerLabels) ListLabels(ctx context.Context) ([]github.Label, error) { | ||
return slices.Collect(maps.Values(t.m)), nil | ||
} | ||
|
||
func (t *testTrackerLabels) EditLabel(ctx context.Context, name string, changes github.LabelChanges) error { | ||
if changes.NewName != "" || changes.Color != "" { | ||
return errors.New("unsupported edit") | ||
} | ||
if lab, ok := t.m[name]; ok { | ||
lab.Description = changes.Description | ||
t.m[name] = lab | ||
return nil | ||
} | ||
return errors.New("not found") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters