mirror of
https://github.com/Smaug123/gitea-repo-config
synced 2025-10-05 07:28:40 +00:00
Source-generate client (#92)
This commit is contained in:
@@ -5,11 +5,11 @@ open Gitea.Declarative
|
||||
|
||||
type private ServerState =
|
||||
{
|
||||
Users : Map<User, Gitea.CreateUserOption>
|
||||
Users : Map<User, GiteaClient.CreateUserOption>
|
||||
Repos : (User * Repo) list
|
||||
}
|
||||
|
||||
member this.WithUser (create : Gitea.CreateUserOption) : ServerState =
|
||||
member this.WithUser (create : GiteaClient.CreateUserOption) : ServerState =
|
||||
let user = User create.Username
|
||||
|
||||
match Map.tryFind user this.Users with
|
||||
@@ -27,7 +27,7 @@ type private ServerState =
|
||||
Repos = []
|
||||
}
|
||||
|
||||
type private ServerMessage = | AddUser of Gitea.CreateUserOption * AsyncReplyChannel<unit>
|
||||
type private ServerMessage = | AddUser of GiteaClient.CreateUserOption * AsyncReplyChannel<unit>
|
||||
|
||||
type Server =
|
||||
private
|
||||
@@ -51,57 +51,18 @@ module Client =
|
||||
return! loop (state.WithUser user) mailbox
|
||||
}
|
||||
|
||||
let make () : Server * IGiteaClient =
|
||||
let make () : Server * GiteaClient.IGiteaClient =
|
||||
let server = MailboxProcessor.Start (loop ServerState.Empty)
|
||||
|
||||
let client =
|
||||
{ new IGiteaClient with
|
||||
member _.AdminGetAllUsers (page, limit) = failwith "Not implemented"
|
||||
|
||||
member _.AdminCreateUser createUserOption =
|
||||
async {
|
||||
let! () = server.PostAndAsyncReply (fun reply -> AddUser (createUserOption, reply))
|
||||
return Operations.createdUser createUserOption
|
||||
}
|
||||
|> Async.StartAsTask
|
||||
|
||||
member _.AdminDeleteUser user = failwith "Not implemented"
|
||||
|
||||
member _.AdminEditUser (user, editUserOption) = failwith "Not implemented"
|
||||
|
||||
member _.AdminCreateRepo (user, createRepoOption) = failwith "Not implemented"
|
||||
|
||||
member _.UserListRepos (user, page, count) = failwith "Not implemented"
|
||||
|
||||
member _.RepoAddPushMirror (user, repo, createPushMirrorOption) = failwith "Not implemented"
|
||||
|
||||
member _.RepoDeletePushMirror (user, repo, remoteName) = failwith "Not implemented"
|
||||
|
||||
member _.RepoListPushMirrors (loginName, userName, page, count) = failwith "Not implemented"
|
||||
|
||||
member _.RepoListBranchProtection (loginName, userName) = failwith "Not implemented"
|
||||
|
||||
member _.RepoDeleteBranchProtection (user, repo, branch) = failwith "Not implemented"
|
||||
|
||||
member _.RepoCreateBranchProtection (user, repo, createBranchProtectionOption) =
|
||||
failwith "Not implemented"
|
||||
|
||||
member _.RepoEditBranchProtection (user, repo, branch, editBranchProtectionOption) =
|
||||
failwith "Not implemented"
|
||||
|
||||
member _.RepoMigrate migrateRepoOptions = failwith "Not implemented"
|
||||
|
||||
member _.RepoGet (user, repo) = failwith "Not implemented"
|
||||
|
||||
member _.RepoDelete (user, repo) = failwith "Not implemented"
|
||||
|
||||
member _.RepoEdit (user, repo, editRepoOption) = failwith "Not implemented"
|
||||
|
||||
member _.RepoListCollaborators (loginName, userName, page, count) = failwith "Not implemented"
|
||||
|
||||
member _.RepoAddCollaborator (user, repo, collaborator) = failwith "Not implemented"
|
||||
|
||||
member _.RepoDeleteCollaborator (user, repo, collaborator) = failwith "Not implemented"
|
||||
{ GiteaClient.GiteaClientMock.Empty with
|
||||
AdminCreateUser =
|
||||
fun (createUserOption, _ct) ->
|
||||
async {
|
||||
let! () = server.PostAndAsyncReply (fun reply -> AddUser (createUserOption, reply))
|
||||
return Operations.createdUser createUserOption
|
||||
}
|
||||
|> Async.StartAsTask
|
||||
}
|
||||
|
||||
Server server, client
|
||||
|
@@ -21,108 +21,3 @@ module Types =
|
||||
type Repo =
|
||||
| GitHubMirror of Uri
|
||||
| NativeRepo of NativeRepo
|
||||
|
||||
/// Allows us to use handy record-updating syntax.
|
||||
/// (I have a considerable dislike of Moq and friends.)
|
||||
type GiteaClientMock =
|
||||
{
|
||||
AdminGetAllUsers : int64 option * int64 option -> Gitea.User array Task
|
||||
AdminCreateUser : Gitea.CreateUserOption -> Gitea.User Task
|
||||
AdminDeleteUser : string -> unit Task
|
||||
AdminEditUser : string * Gitea.EditUserOption -> Gitea.User Task
|
||||
AdminCreateRepo : string * Gitea.CreateRepoOption -> Gitea.Repository Task
|
||||
|
||||
UserListRepos : string * int64 option * int64 option -> Gitea.Repository array Task
|
||||
|
||||
RepoAddPushMirror : string * string * Gitea.CreatePushMirrorOption -> Gitea.PushMirror Task
|
||||
RepoDeletePushMirror : string * string * string -> unit Task
|
||||
RepoListPushMirrors : string * string * int64 option * int64 option -> Gitea.PushMirror array Task
|
||||
|
||||
RepoListBranchProtection : string * string -> Gitea.BranchProtection array Task
|
||||
RepoDeleteBranchProtection : string * string * string -> unit Task
|
||||
RepoCreateBranchProtection : string * string * Gitea.CreateBranchProtectionOption -> Gitea.BranchProtection Task
|
||||
RepoEditBranchProtection :
|
||||
string * string * string * Gitea.EditBranchProtectionOption -> Gitea.BranchProtection Task
|
||||
|
||||
RepoMigrate : Gitea.MigrateRepoOptions -> Gitea.Repository Task
|
||||
RepoGet : string * string -> Gitea.Repository Task
|
||||
RepoDelete : string * string -> unit Task
|
||||
RepoEdit : string * string * Gitea.EditRepoOption -> Gitea.Repository Task
|
||||
|
||||
RepoListCollaborators : string * string * int64 option * int64 option -> Gitea.User array Task
|
||||
RepoAddCollaborator : string * string * string -> unit Task
|
||||
RepoDeleteCollaborator : string * string * string -> unit Task
|
||||
}
|
||||
|
||||
static member Unimplemented =
|
||||
{
|
||||
AdminGetAllUsers = fun _ -> failwith "Unimplemented"
|
||||
AdminCreateUser = fun _ -> failwith "Unimplemented"
|
||||
AdminDeleteUser = fun _ -> failwith "Unimplemented"
|
||||
AdminEditUser = fun _ -> failwith "Unimplemented"
|
||||
AdminCreateRepo = fun _ -> failwith "Unimplemented"
|
||||
|
||||
UserListRepos = fun _ -> failwith "Unimplemented"
|
||||
|
||||
RepoAddPushMirror = fun _ -> failwith "Unimplemented"
|
||||
RepoDeletePushMirror = fun _ -> failwith "Unimplemented"
|
||||
RepoListPushMirrors = fun _ -> failwith "Unimplemented"
|
||||
|
||||
RepoListBranchProtection = fun _ -> failwith "Unimplemented"
|
||||
RepoDeleteBranchProtection = fun _ -> failwith "Unimplemented"
|
||||
RepoCreateBranchProtection = fun _ -> failwith "Unimplemented"
|
||||
RepoEditBranchProtection = fun _ -> failwith "Unimplemented"
|
||||
|
||||
RepoMigrate = fun _ -> failwith "Unimplemented"
|
||||
RepoGet = fun _ -> failwith "Unimplemented"
|
||||
RepoDelete = fun _ -> failwith "Unimplemented"
|
||||
RepoEdit = fun _ -> failwith "Unimplemented"
|
||||
|
||||
RepoListCollaborators = fun _ -> failwith "Unimplemented"
|
||||
RepoAddCollaborator = fun _ -> failwith "Unimplemented"
|
||||
RepoDeleteCollaborator = fun _ -> failwith "Unimplemented"
|
||||
}
|
||||
|
||||
interface IGiteaClient with
|
||||
member this.AdminGetAllUsers (page, limit) = this.AdminGetAllUsers (page, limit)
|
||||
member this.AdminCreateUser user = this.AdminCreateUser user
|
||||
member this.AdminDeleteUser user = this.AdminDeleteUser user
|
||||
member this.AdminEditUser (user, option) = this.AdminEditUser (user, option)
|
||||
member this.AdminCreateRepo (user, option) = this.AdminCreateRepo (user, option)
|
||||
|
||||
member this.UserListRepos (user, page, count) = this.UserListRepos (user, page, count)
|
||||
|
||||
member this.RepoAddPushMirror (user, repo, options) =
|
||||
this.RepoAddPushMirror (user, repo, options)
|
||||
|
||||
member this.RepoListPushMirrors (loginName, userName, page, count) =
|
||||
this.RepoListPushMirrors (loginName, userName, page, count)
|
||||
|
||||
member this.RepoDeletePushMirror (loginName, userName, remoteName) =
|
||||
this.RepoDeletePushMirror (loginName, userName, remoteName)
|
||||
|
||||
member this.RepoListBranchProtection (login, user) =
|
||||
this.RepoListBranchProtection (login, user)
|
||||
|
||||
member this.RepoDeleteBranchProtection (user, repo, branch) =
|
||||
this.RepoDeleteBranchProtection (user, repo, branch)
|
||||
|
||||
member this.RepoCreateBranchProtection (user, repo, options) =
|
||||
this.RepoCreateBranchProtection (user, repo, options)
|
||||
|
||||
member this.RepoEditBranchProtection (user, repo, branch, edit) =
|
||||
this.RepoEditBranchProtection (user, repo, branch, edit)
|
||||
|
||||
member this.RepoMigrate options = this.RepoMigrate options
|
||||
member this.RepoGet (user, repo) = this.RepoGet (user, repo)
|
||||
member this.RepoDelete (user, repo) = this.RepoDelete (user, repo)
|
||||
member this.RepoEdit (user, repo, options) = this.RepoEdit (user, repo, options)
|
||||
|
||||
member this.RepoListCollaborators (login, user, page, count) =
|
||||
this.RepoListCollaborators (login, user, page, count)
|
||||
|
||||
member this.RepoAddCollaborator (user, repo, collaborator) =
|
||||
this.RepoAddCollaborator (user, repo, collaborator)
|
||||
|
||||
member this.RepoDeleteCollaborator (user, repo, collaborator) =
|
||||
this.RepoDeleteCollaborator (user, repo, collaborator)
|
||||
|
@@ -1,18 +1,33 @@
|
||||
namespace Gitea.InMemory
|
||||
|
||||
open Gitea.Declarative
|
||||
open System.Collections.Generic
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module Operations =
|
||||
let createdUser (createUserOption : Gitea.CreateUserOption) : Gitea.User =
|
||||
let result = Gitea.User ()
|
||||
result.Email <- createUserOption.Email
|
||||
result.Restricted <- createUserOption.Restricted
|
||||
// TODO: what is this username used for anyway
|
||||
// result.LoginName <- createUserOption.Username
|
||||
result.Visibility <- createUserOption.Visibility
|
||||
result.Created <- createUserOption.CreatedAt
|
||||
result.FullName <- createUserOption.FullName
|
||||
result.LoginName <- createUserOption.LoginName
|
||||
let createdUser (createUserOption : GiteaClient.CreateUserOption) : GiteaClient.User =
|
||||
let result : GiteaClient.User =
|
||||
{
|
||||
AdditionalProperties = Dictionary ()
|
||||
Active = None
|
||||
AvatarUrl = None
|
||||
Created = None
|
||||
Description = None
|
||||
Email = Some createUserOption.Email
|
||||
FollowersCount = None
|
||||
FollowingCount = None
|
||||
FullName = createUserOption.FullName
|
||||
Id = None
|
||||
IsAdmin = None
|
||||
Language = None
|
||||
LastLogin = None
|
||||
Location = None
|
||||
Login = None
|
||||
LoginName = createUserOption.LoginName
|
||||
ProhibitLogin = failwith "todo"
|
||||
Restricted = createUserOption.Restricted
|
||||
StarredReposCount = None
|
||||
Visibility = createUserOption.Visibility
|
||||
Website = None
|
||||
}
|
||||
|
||||
result
|
||||
|
Reference in New Issue
Block a user