Skip to content

Commit

Permalink
Added Repository.Get to the CLI.
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottArbeit committed Dec 1, 2023
1 parent fca24a0 commit 31768a3
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/Create-Grace-Objects.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$startTime = Get-Date
$iterations = 50

1..128 | ForEach-Object -Parallel {
1..$iterations | ForEach-Object -Parallel {
Set-Alias -Name grace -Value D:\Source\Grace\src\Grace.CLI\bin\Debug\net8.0\Grace.CLI.exe

$suffix = (Get-Random -Maximum 65536).ToString("X4")
Expand All @@ -25,7 +26,7 @@ $startTime = Get-Date
grace org get --output Verbose --ownerId $ownerId --organizationId $organizationId
grace repo create --output Verbose --ownerId $ownerId --organizationId $organizationId --repositoryName $repoNameOriginal --repositoryId $repoId --doNotSwitch
grace repo set-name --output Verbose --ownerId $ownerId --organizationId $organizationId --repositoryId $repoId --newName $repoName
#grace repo get --output Verbose --ownerId $ownerId --organizationId $organizationId --repositoryId $repoId
grace repo get --output Verbose --ownerId $ownerId --organizationId $organizationId --repositoryId $repoId
grace branch create --output Verbose --ownerId $ownerId --organizationId $organizationId --repositoryId $repoId --branchId $branchId --branchName $branchName --parentBranchName main --doNotSwitch

$words = "Sit fusce at sociosqu eros bibendum aliquet cursus ante non facilisis tempor Scelerisque arcu potenti feugiat fermentum viverra et litora facilisis vestibulum sit aliquam quisque sagittis ut Ultricies nisi urna cursus tellus tempor vivamus nec Dictumst tristique porta vel cubilia mollis Tempus nullam laoreet sit vestibulum etiam in volutpat dui class netus morbi Duis facilisis at aliquet fusce nisi Nulla arcu molestie mauris integer aenean ligula curabitur dui sociosqu suspendisse mi fringilla faucibus Rhoncus habitasse massa amet ipsum ligula quisque Quisque fames bibendum eu ullamcorper pulvinar in aenean hendrerit Augue tristique aenean amet auctor curabitur congue placerat aenean posuere porttitor pulvinar lectus Mattis aenean elit condimentum nam iaculis ante felis sollicitudin Risus viverra ornare curabitur sem massa nibh vulputate senectus dictum vitae leo varius dictumst tristique Ultrices ut blandit adipiscing dictumst sagittis elementum urna Vel feugiat consectetur malesuada nibh turpis odio convallis molestie vulputate magna venenatis lacinia Suscipit consequat lectus nullam suspendisse aliquam sed venenatis Feugiat vehicula iaculis donec aenean Volutpat amet feugiat fringilla bibendum scelerisque fermentum pellentesque hendrerit dapibus primis eu ipsum proin mauris Amet magna non mattis dictum risus sit Luctus hendrerit in integer euismod sapien aenean vel maecenas venenatis lorem cubilia taciti Id mauris dictum aenean leo quisque auctor sagittis nisl rutrum at Iaculis luctus orci egestas metus commodo praesent sodales nam quis conubia cras sagittis vestibulum Viverra justo cursus tempor fringilla egestas Potenti aliquam quisque tincidunt pellentesque Lacinia eu convallis quis risus accumsan Augue adipiscing orci massa lorem curabitur eleifend tincidunt justo varius vulputate Mollis aenean est pulvinar proin in donec bibendum dolor quis sociosqu mattis mi Euismod urna leo mollis potenti fames mattis ultrices diam Vivamus sit mattis vehicula viverra mi imperdiet Adipiscing est vehicula scelerisque velit Malesuada integer quisque fusce quis mollis eros Leo nec tellus curabitur ornare amet quisque fusce habitasse morbi Sem lacinia eu aenean pretium curae dolor cubilia faucibus purus Sollicitudin nisl tempus auctor etiam felis urna consectetur donec dui Posuere elit orci lobortis magna Enim at pellentesque ac taciti convallis sapien ad elit Integer potenti malesuada lacinia fames euismod amet purus justo sociosqu dolor cras tempus dictumst Dictumst adipiscing quisque sapien pharetra pretium aliquam nunc ipsum varius mi justo aenean mattis Aenean conubia felis inceptos nulla ante sociosqu libero non imperdiet Nunc feugiat sodales commodo interdum rhoncus nulla aliquet cras sociosqu eros sed Vivamus varius sapien sollicitudin curabitur class aenean tempus tempor magna donec bibendum nulla morbi semper Praesent inceptos etiam tempus in Varius hac et feugiat nullam dictum vivamus adipiscing ut in eros nulla molestie ante Interdum dictum volutpat accumsan posuere quis amet curae nostra purus fusce nisl lacus Aenean erat suscipit urna ante In ad varius interdum porta at pulvinar aptent enim nam sit ultrices hendrerit Vitae rhoncus consequat non metus nullam augue Massa vestibulum dapibus lectus nibh at tortor ullamcorper mattis rutrum pellentesque aliquam adipiscing porttitor".Split()
Expand Down Expand Up @@ -53,5 +54,5 @@ $startTime = Get-Date
} -ThrottleLimit 16

$endTime = Get-Date
$elapsed = $endTime.Subtract($startTime).TotalSeconds.ToString("F3")
"Elapsed: $elapsed seconds"
$elapsed = $endTime.Subtract($startTime).TotalSeconds
"Elapsed: $($elapsed.ToString('F3')) seconds; Operations: $($iterations * 14); Operations/second: $($iterations * 14 / $elapsed)."
15 changes: 5 additions & 10 deletions src/Grace.Actors/Repository.Actor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -344,20 +344,15 @@ module Repository =
}

interface IRepositoryActor with
member this.Get() =
Task.FromResult(repositoryDto)
member this.Get() = repositoryDto |> returnTask

member this.GetObjectStorageProvider() =
Task.FromResult(repositoryDto.ObjectStorageProvider)
member this.GetObjectStorageProvider() = repositoryDto.ObjectStorageProvider |> returnTask

member this.Exists() =
Task.FromResult(if repositoryDto.UpdatedAt.IsSome then true else false)
member this.Exists() = repositoryDto.UpdatedAt.IsSome |> returnTask

member this.IsEmpty() =
Task.FromResult(if repositoryDto.InitializedAt.IsSome then false else true)
member this.IsEmpty() = repositoryDto.InitializedAt.IsNone |> returnTask

member this.IsDeleted() =
Task.FromResult(if repositoryDto.DeletedAt.IsSome then true else false)
member this.IsDeleted() = repositoryDto.DeletedAt.IsSome |> returnTask

member this.Handle command metadata =
let isValid command (metadata: EventMetadata) =
Expand Down
50 changes: 50 additions & 0 deletions src/Grace.CLI/Command/Repository.CLI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ open System.IO
open System.Threading
open System.Threading.Tasks
open Grace.Shared.Parameters.Directory
open Spectre.Console.Json

module Repository =

Expand Down Expand Up @@ -424,6 +425,51 @@ module Repository =
return result |> renderOutput parseResult
})


// Get subcommand
type GetParameters() =
inherit CommonParameters()
let private getHandler (parseResult: ParseResult) (getParameters: GetParameters) =
task {
try
if parseResult |> verbose then printParseResult parseResult
let validateIncomingParameters = CommonValidations (parseResult, getParameters)
match validateIncomingParameters with
| Ok _ ->
let parameters = Parameters.Repository.GetRepositoryParameters(OwnerId = getParameters.OwnerId, OwnerName = getParameters.OwnerName,
OrganizationId = getParameters.OrganizationId, OrganizationName = getParameters.OrganizationName,
RepositoryId = getParameters.RepositoryId, RepositoryName = getParameters.RepositoryName,
CorrelationId = getParameters.CorrelationId)
if parseResult |> hasOutput then
return! progress.Columns(progressColumns)
.StartAsync(fun progressContext ->
task {
let t0 = progressContext.AddTask($"[{Color.DodgerBlue1}]Sending command to the server.[/]")
let! result = Repository.Get(parameters)
t0.Increment(100.0)
return result
})
else
return! Repository.Get(parameters)
| Error error -> return Error error
with
| ex -> return Error (GraceError.Create $"{Utilities.createExceptionResponse ex}" (parseResult |> getCorrelationId))
}
let private Get =
CommandHandler.Create(fun (parseResult: ParseResult) (getParameters: GetParameters) ->
task {
let! result = getHandler parseResult (getParameters |> normalizeIdsAndNames parseResult)
//return result |> renderOutput parseResult
match result with
| Ok graceReturnValue ->
let jsonText = JsonText(serialize graceReturnValue.ReturnValue)
AnsiConsole.Write(jsonText)
AnsiConsole.WriteLine()
return 0
| Error graceError ->
return Error graceError |> renderOutput parseResult
})

// Get-Branches subcommand
type GetBranchesParameters() =
inherit CommonParameters()
Expand Down Expand Up @@ -979,6 +1025,10 @@ module Repository =
repositoryCreateCommand.Handler <- Create
repositoryCommand.AddCommand(repositoryCreateCommand)

let repositoryGetCommand = new Command("get", Description = "Get information about a repository.") |> addCommonOptions
repositoryGetCommand.Handler <- Get
repositoryCommand.AddCommand(repositoryGetCommand)

let repositoryInitCommand = new Command("init", Description = "Initializes a new repository with the contents of a directory.") |> addOption Options.directory |> addOption Options.graceConfig |> addCommonOptions
repositoryInitCommand.Handler <- Init
repositoryCommand.AddCommand(repositoryInitCommand)
Expand Down
4 changes: 4 additions & 0 deletions src/Grace.Shared/Parameters/Repository.Parameters.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ module Repository =
type CreateRepositoryParameters() =
inherit RepositoryParameters()

/// Parameters for the /repository/get endpoint.
type GetRepositoryParameters() =
inherit RepositoryParameters()

/// Parameters for the /repository/isEmpty endpoint.
type IsEmptyParameters() =
inherit RepositoryParameters()
Expand Down

0 comments on commit 31768a3

Please sign in to comment.