Skip to content

Commit

Permalink
Update the protob Ident and init to mempty
Browse files Browse the repository at this point in the history
  • Loading branch information
morucci committed Nov 28, 2023
1 parent f2dcbbd commit cc96285
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 36 deletions.
83 changes: 64 additions & 19 deletions codegen/Monocle/Protob/Change.hs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions schemas/monocle/protob/change.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "google/protobuf/timestamp.proto";
message Ident {
string uid = 1;
string muid = 2;
repeated string groups = 3;
}

message ChangedFile {
Expand Down
1 change: 1 addition & 0 deletions src/Lentille.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ toIdent host cb username = Ident {..}
uid = host <> "/" <> username
identUid = from uid
identMuid = from $ fromMaybe username (cb uid)
identGroups = mempty

ghostIdent :: Text -> Ident
ghostIdent host = toIdent host (const Nothing) nobody
Expand Down
6 changes: 4 additions & 2 deletions src/Monocle/Backend/Documents.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Monocle.Protob.Search qualified as SearchPB
data Author = Author
{ authorMuid :: LText
, authorUid :: LText
, authorGroups :: [LText]
}
deriving (Show, Eq, Generic)

Expand All @@ -47,12 +48,13 @@ instance From ChangePB.Ident Author where
Author
{ authorMuid = identMuid
, authorUid = identUid
, authorGroups = mempty
}

fromMaybeIdent :: Maybe ChangePB.Ident -> Author
fromMaybeIdent = maybe ghostAuthor from
where
ghostAuthor = Author "backend-ghost" "backend-ghost"
ghostAuthor = Author "backend-ghost" "backend-ghost" mempty

-- | CachedAuthor is used by the Author search cache
data CachedAuthor = CachedAuthor
Expand Down Expand Up @@ -116,7 +118,7 @@ instance FromJSON Commit where
ensureAuthor :: Maybe ChangePB.Ident -> ChangePB.Ident
ensureAuthor = \case
Just i -> i
Nothing -> ChangePB.Ident "backend-ghost" "backend-host"
Nothing -> ChangePB.Ident "backend-ghost" "backend-host" mempty

instance From ChangePB.Commit Commit where
from ChangePB.Commit {..} =
Expand Down
2 changes: 2 additions & 0 deletions src/Monocle/Backend/Index.hs
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,13 @@ toAuthor (Just ChangePB.Ident {..}) =
Monocle.Backend.Documents.Author
{ authorMuid = identMuid
, authorUid = identUid
, authorGroups = toList identGroups
}
toAuthor Nothing =
Monocle.Backend.Documents.Author
"backend-ghost"
"backend-ghost"
mempty

-- TODO: change that to a From instance
toEChangeEvent :: ChangePB.ChangeEvent -> EChangeEvent
Expand Down
4 changes: 2 additions & 2 deletions src/Monocle/Backend/Janitor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import Streaming.Prelude qualified as Streaming

updateAuthor :: Config.Index -> D.Author -> D.Author
updateAuthor index author@D.Author {..} = case getIdent of
Just ident -> D.Author ident authorUid
Just ident -> D.Author ident authorUid mempty
Nothing
| newMuid /= from authorMuid -> D.Author (from newMuid) authorUid
| newMuid /= from authorMuid -> D.Author (from newMuid) authorUid mempty
| otherwise -> author
where
getIdent :: Maybe LText
Expand Down
2 changes: 1 addition & 1 deletion src/Monocle/Backend/Provisioner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fakeTitle = from <$> Faker.Movie.BackToTheFuture.quotes
fakeAuthor :: Faker.Fake Author
fakeAuthor = do
name <- from <$> Faker.TvShow.Futurama.characters
pure $ Author name name
pure $ Author name name mempty

fakeText :: Faker.Fake LText
fakeText = from <$> Faker.TvShow.Futurama.quotes
Expand Down
24 changes: 12 additions & 12 deletions src/Monocle/Backend/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ fakeDate = [utctime|2021-05-31 10:00:00|]
fakeDateAlt = [utctime|2021-06-01 20:00:00|]

alice, bob, eve, fakeAuthor, fakeAuthorAlt :: Author
alice = Author "alice" "a"
bob = Author "bob" "b"
eve = Author "eve" "e"
fakeAuthor = Author "John" "John"
fakeAuthorAlt = Author "John Doe/12" "review.opendev.org/John Doe/12"
alice = Author "alice" "a" mempty
bob = Author "bob" "b" mempty
eve = Author "eve" "e" mempty
fakeAuthor = Author "John" "John" mempty
fakeAuthorAlt = Author "John Doe/12" "review.opendev.org/John Doe/12" mempty

fakeChangePB :: ChangePB.Change
fakeChangePB =
Expand Down Expand Up @@ -603,7 +603,7 @@ testJanitorUpdateIdents = do
}
mkIdent :: [Text] -> Text -> Config.Ident
mkIdent uid = Config.Ident uid Nothing
expectedAuthor = Author "John Doe" "github.com/john"
expectedAuthor = Author "John Doe" "github.com/john" mempty

doUpdateIndentOnEventsTest :: Eff [MonoQuery, ElasticEffect, LoggerEffect, IOE] ()
doUpdateIndentOnEventsTest = E.runFailIO do
Expand All @@ -617,8 +617,8 @@ testJanitorUpdateIdents = do
evt2' <- I.getChangeEventById $ I.getEventDocId evt2
assertEqual' "Ensure event not changed" evt2' $ Just evt2
where
evt1 = mkEventWithAuthor "e1" (Author "john" "github.com/john")
evt2 = mkEventWithAuthor "e2" (Author "paul" "github.com/paul")
evt1 = mkEventWithAuthor "e1" (Author "john" "github.com/john" mempty)
evt2 = mkEventWithAuthor "e2" (Author "paul" "github.com/paul" mempty)
mkEventWithAuthor ::
-- eventId
Text ->
Expand Down Expand Up @@ -647,10 +647,10 @@ testJanitorUpdateIdents = do
-- then default is to remove the "<provider-host>/" prefix
checkEChangeField (I.getChangeDocId change3) echangeAuthor expectedAuthor'
where
expectedAuthor' = Author "jane" "github.com/jane"
change1 = mkChangeWithAuthor "c1" (Author "john" "github.com/john")
change2 = mkChangeWithAuthor "c2" (Author "paul" "github.com/paul")
change3 = mkChangeWithAuthor "c3" (Author "Ident will revert" "github.com/jane")
expectedAuthor' = Author "jane" "github.com/jane" mempty
change1 = mkChangeWithAuthor "c1" (Author "john" "github.com/john" mempty)
change2 = mkChangeWithAuthor "c2" (Author "paul" "github.com/paul" mempty)
change3 = mkChangeWithAuthor "c3" (Author "Ident will revert" "github.com/jane" mempty)
mkChangeWithAuthor ::
-- changeId
Text ->
Expand Down

0 comments on commit cc96285

Please sign in to comment.