Skip to content

Commit 3225ff8

Browse files
committed
expand Change description structure
1 parent dd84bca commit 3225ff8

3 files changed

Lines changed: 43 additions & 14 deletions

File tree

form/form.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import (
1111

1212
type Form interface{}
1313

14+
type Forms []Form
15+
16+
type Map = map[string]Form
17+
1418
type None struct{}
1519

1620
func SprintJSON(form Form) string {

git/change.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,32 @@ package git
22

33
import "github.com/gov4git/lib4git/form"
44

5-
type Change[R any] struct {
6-
Result R
7-
Msg string //commit msg
5+
type Change[Q any, R any] struct {
6+
Msg string `json:"msg"`
7+
Fn string `json:"fn"`
8+
Query Q `json:"query"`
9+
Result R `json:"result"`
10+
Steps form.Forms `json:"steps"`
811
}
912

10-
type ChangeNoResult = Change[form.None]
13+
func NewChange[Q any, R any](
14+
msg string,
15+
fn string,
16+
query Q,
17+
result R,
18+
steps form.Forms,
19+
) Change[Q, R] {
20+
return Change[Q, R]{
21+
Msg: msg,
22+
Fn: fn,
23+
Query: query,
24+
Result: result,
25+
Steps: steps,
26+
}
27+
}
28+
29+
type ChangeNoResult = Change[form.None, form.None]
30+
31+
func NewChangeNoResult(msg string, fn string) ChangeNoResult {
32+
return NewChange(msg, fn, form.None{}, form.None{}, nil)
33+
}

id/init.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package id
33
import (
44
"context"
55

6+
"github.com/gov4git/lib4git/form"
67
"github.com/gov4git/lib4git/git"
78
"github.com/gov4git/lib4git/must"
89
)
910

1011
func Init(
1112
ctx context.Context,
1213
ownerAddr OwnerAddress,
13-
) git.Change[PrivateCredentials] {
14+
) git.Change[form.None, PrivateCredentials] {
1415
ownerCloned := CloneOwner(ctx, ownerAddr)
1516
privChg := InitLocal(ctx, ownerAddr, ownerCloned)
1617

@@ -23,7 +24,7 @@ func InitLocal(
2324
ctx context.Context,
2425
ownerAddr OwnerAddress,
2526
ownerCloned OwnerCloned,
26-
) git.Change[PrivateCredentials] {
27+
) git.Change[form.None, PrivateCredentials] {
2728

2829
privChg := initPrivateStageOnly(ctx, ownerCloned.Private.Tree(), ownerAddr)
2930
pubChg := initPublicStageOnly(ctx, ownerCloned.Public.Tree(), privChg.Result.PublicCredentials)
@@ -32,25 +33,26 @@ func InitLocal(
3233
return privChg
3334
}
3435

35-
func initPrivateStageOnly(ctx context.Context, priv *git.Tree, ownerAddr OwnerAddress) git.Change[PrivateCredentials] {
36+
func initPrivateStageOnly(ctx context.Context, priv *git.Tree, ownerAddr OwnerAddress) git.Change[form.None, PrivateCredentials] {
3637
if _, err := priv.Filesystem.Stat(PrivateCredentialsNS.Path()); err == nil {
3738
must.Errorf(ctx, "private credentials file already exists")
3839
}
3940
cred, err := GenerateCredentials()
4041
must.NoError(ctx, err)
4142
git.ToFileStage(ctx, priv, PrivateCredentialsNS.Path(), cred)
42-
return git.Change[PrivateCredentials]{
43-
Result: cred,
44-
Msg: "Initialized private credentials.",
45-
}
43+
return git.NewChange(
44+
"Initialized private credentials.",
45+
"id_init_private",
46+
form.None{},
47+
cred,
48+
nil,
49+
)
4650
}
4751

4852
func initPublicStageOnly(ctx context.Context, pub *git.Tree, cred PublicCredentials) git.ChangeNoResult {
4953
if _, err := pub.Filesystem.Stat(PublicCredentialsNS.Path()); err == nil {
5054
must.Errorf(ctx, "public credentials file already exists")
5155
}
5256
git.ToFileStage(ctx, pub, PublicCredentialsNS.Path(), cred)
53-
return git.ChangeNoResult{
54-
Msg: "Initialized public credentials.",
55-
}
57+
return git.NewChangeNoResult("Initialized public credentials.", "id_init_public")
5658
}

0 commit comments

Comments
 (0)