Skip to content

Commit 123f309

Browse files
Cabbie Teamcopybara-github
authored andcommitted
Add support for automatically unhiding updates when they are removed from enforcement.json
PiperOrigin-RevId: 652989914
1 parent 3ac842f commit 123f309

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

cabbie.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ func enforce() error {
314314
deck.ErrorA(failures).With(eventID(cablib.EvtErrHide)).Go()
315315
}
316316
}
317+
if err := unHideUpdates(updates); err != nil {
318+
failures = fmt.Errorf("error unhiding updates: %v", err)
319+
deck.ErrorA(failures).With(eventID(cablib.EvtErrUnhide)).Go()
320+
}
317321
return failures
318322
}
319323

hide.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ import (
2121

2222
"flag"
2323
"github.com/google/cabbie/cablib"
24+
"github.com/google/cabbie/enforcement"
2425
"github.com/google/cabbie/search"
2526
"github.com/google/cabbie/session"
2627
"github.com/google/cabbie/updatecollection"
2728
"github.com/google/deck"
29+
"golang.org/x/exp/slices"
2830
"github.com/google/subcommands"
2931
)
3032

@@ -129,6 +131,37 @@ func hide(kbs KBSet) error {
129131
return nil
130132
}
131133

134+
func unHideUpdates(upd enforcement.Enforcements) error {
135+
// Find hidden updates.
136+
uc, err := findUpdates("IsHidden=1")
137+
if err != nil {
138+
return err
139+
}
140+
defer uc.Close()
141+
deck.InfofA("Found %d hidden updates.", len(uc.Updates)).With(eventID(cablib.EvtUnhide)).Go()
142+
// Check if currently hidden updates are still in the list of hidden updates.
143+
// If they are, continue. If they are not still in the list, unhide them.
144+
for _, u := range uc.Updates {
145+
var skip bool
146+
if slices.Contains(upd.HiddenUpdateID, u.Identity.UpdateID) {
147+
continue
148+
}
149+
for _, kb := range u.KBArticleIDs {
150+
if slices.Contains(upd.Hidden, kb) {
151+
skip = true
152+
}
153+
}
154+
if skip {
155+
continue
156+
}
157+
deck.InfofA("Unhiding update:\n%s", u.Title).With(eventID(cablib.EvtUnhide)).Go()
158+
if err := u.UnHide(); err != nil {
159+
deck.ErrorfA("Failed to unhide update %s:\n %s", u.Title, err).With(eventID(cablib.EvtErrUnhide)).Go()
160+
}
161+
}
162+
return nil
163+
}
164+
132165
func hideByUpdateID(uuids []string) error {
133166
// Find non-hidden updates that are installed or not installed.
134167
uc, err := findUpdates("IsHidden=0 and IsInstalled=0 or IsHidden=0 and IsInstalled=1")

0 commit comments

Comments
 (0)