()
| 298 | } |
| 299 | |
| 300 | func Example_entity() { |
| 301 | const gitBugNamespace = "git-bug" |
| 302 | // Note: this example ignore errors for readability |
| 303 | // Note: variable names get a little confusing as we are simulating both side in the same function |
| 304 | |
| 305 | // Let's start by defining two git repository and connecting them as remote |
| 306 | repoRenePath, _ := os.MkdirTemp("", "") |
| 307 | repoIsaacPath, _ := os.MkdirTemp("", "") |
| 308 | repoRene, _ := repository.InitGoGitRepo(repoRenePath, gitBugNamespace) |
| 309 | defer repoRene.Close() |
| 310 | repoIsaac, _ := repository.InitGoGitRepo(repoIsaacPath, gitBugNamespace) |
| 311 | defer repoIsaac.Close() |
| 312 | _ = repoRene.AddRemote("origin", repoIsaacPath) |
| 313 | _ = repoIsaac.AddRemote("origin", repoRenePath) |
| 314 | |
| 315 | // Now we need identities and to propagate them |
| 316 | rene, _ := identity.NewIdentity(repoRene, "René Descartes", "rene@descartes.fr") |
| 317 | isaac, _ := identity.NewIdentity(repoRene, "Isaac Newton", "isaac@newton.uk") |
| 318 | _ = rene.Commit(repoRene) |
| 319 | _ = isaac.Commit(repoRene) |
| 320 | _ = identity.Pull(repoIsaac, "origin") |
| 321 | |
| 322 | // create a new entity |
| 323 | confRene := NewProjectConfig() |
| 324 | |
| 325 | // add some operations |
| 326 | confRene.Append(NewAddAdministratorOp(rene, rene)) |
| 327 | confRene.Append(NewAddAdministratorOp(rene, isaac)) |
| 328 | confRene.Append(NewSetSignatureRequired(rene, true)) |
| 329 | |
| 330 | // Rene commits on its own repo |
| 331 | _ = confRene.Commit(repoRene) |
| 332 | |
| 333 | // Isaac pull and read the config |
| 334 | _ = dag.Pull(def, wrapper, repoIsaac, simpleResolvers(repoIsaac), "origin", isaac) |
| 335 | confIsaac, _ := Read(repoIsaac, confRene.Id()) |
| 336 | |
| 337 | // Compile gives the current state of the config |
| 338 | snapshot := confIsaac.Compile() |
| 339 | for admin, _ := range snapshot.Administrator { |
| 340 | fmt.Println(admin.DisplayName()) |
| 341 | } |
| 342 | |
| 343 | // Isaac add more operations |
| 344 | confIsaac.Append(NewSetSignatureRequired(isaac, false)) |
| 345 | reneFromIsaacRepo, _ := identity.ReadLocal(repoIsaac, rene.Id()) |
| 346 | confIsaac.Append(NewRemoveAdministratorOp(isaac, reneFromIsaacRepo)) |
| 347 | _ = confIsaac.Commit(repoIsaac) |
| 348 | } |
nothing calls this directly
no test coverage detected