-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsync_schema_gh.go
More file actions
44 lines (36 loc) · 907 Bytes
/
sync_schema_gh.go
File metadata and controls
44 lines (36 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package gontentful
import (
"context"
"encoding/json"
"path/filepath"
"github.com/moonwalker/moonbase/pkg/content"
gh "github.com/moonwalker/moonbase/pkg/github"
)
type GHSyncSchema struct {
FolderName string
Schema *ContentType
}
func NewGHSyncSchema(sys *Sys, schema *ContentType) *GHSyncSchema {
folderName := schema.Sys.ID
return &GHSyncSchema{
FolderName: folderName,
Schema: schema,
}
}
func (s *GHSyncSchema) Exec(repo string) error {
ctx := context.Background()
cfg := getConfig(ctx, owner, repo, branch)
ct := TransformModel(s.Schema)
cb, err := json.Marshal(ct)
if err != nil {
return err
}
sc := string(cb)
path := filepath.Join(cfg.WorkDir, s.FolderName, content.JsonSchemaName)
// Upload to github
_, err = gh.CommitBlob(ctx, cfg.Token, owner, repo, branch, path, &sc, "feat(content type): update files")
if err != nil {
return err
}
return nil
}