Skip to content

Commit 0ee85e8

Browse files
committed
Merge branch 'main' of https://github.com/gcp-kit/fti into issues/10/main
2 parents 074ecfd + 6f81271 commit 0ee85e8

File tree

8 files changed

+95
-34
lines changed

8 files changed

+95
-34
lines changed

.github/workflows/build.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: build
2+
on: [pull_request]
3+
jobs:
4+
golangci-lint:
5+
name: runner / build_and_run
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Check out code into the Go module directory
9+
uses: actions/checkout@v2
10+
- uses: actions/setup-go@v2
11+
with:
12+
go-version: 1.17
13+
- name: Install JRE
14+
run: |
15+
sudo apt update && sudo apt install openjdk-17-jre
16+
- uses: actions/setup-node@v2
17+
with:
18+
node-version: "16"
19+
cache: "npm"
20+
cache-dependency-path: package-lock.json
21+
- name: Install emulator
22+
run: |
23+
npm ci
24+
- name: Run emulator
25+
run: |
26+
make emulator &
27+
- name: Ensure samples are generated
28+
env:
29+
TZ: Asia/Tokyo
30+
run: |
31+
make gen_samples
32+
33+
clean=$(git status | grep "nothing to commit" || true)
34+
if [ -z "$clean" ]; then
35+
git diff
36+
echo 'Please run "make gen_samples"'
37+
exit 1
38+
fi

.github/workflows/linter.yml

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,8 @@ jobs:
1010
- uses: actions/setup-go@v2
1111
with:
1212
go-version: 1.17
13-
- name: Install JRE
14-
run: |
15-
sudo apt update && sudo apt install openjdk-17-jre
16-
- uses: actions/setup-node@v2
17-
with:
18-
node-version: "16"
19-
cache: "npm"
20-
cache-dependency-path: package-lock.json
21-
- name: Install emulator
22-
run: |
23-
npm ci
24-
- name: Run emulator
25-
run: |
26-
make emulator &
27-
- name: Ensure samples are generated
28-
env:
29-
TZ: Asia/Tokyo
30-
run: |
31-
make gen_samples
32-
33-
clean=$(git status | grep "nothing to commit" || true)
34-
if [ -z "$clean" ]; then
35-
git diff
36-
echo 'Please run "make gen_samples"'
37-
exit 1
38-
fi
3913
- name: golangci-lint
4014
uses: golangci/golangci-lint-action@v2
4115
with:
4216
args: "--config=.github/.golangci.yml"
43-
skip-go-installation: true`
17+
skip-go-installation: true

pkg/inserter/common_inserter.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,31 @@ func (c *CommonInserter) tryParseDate(item map[string]interface{}) map[string]in
6868
func (c *CommonInserter) setRefs(item map[string]interface{}) map[string]interface{} {
6969
for k, v := range item {
7070
switch vt := v.(type) {
71-
case string:
72-
if strings.HasPrefix(vt, "$") {
73-
refID := strings.TrimPrefix(vt, "$")
74-
rv, ok := c.refIDs[refID]
71+
case map[string]interface{}:
72+
for vtk, vtv := range vt {
73+
if !strings.HasPrefix(vtk, "$") {
74+
continue
75+
}
76+
refID := strings.TrimPrefix(vtk, "$")
77+
rk, ok := c.refIDs[refID]
7578
if !ok {
7679
log.Printf("%s was not found", refID)
7780
continue
7881
}
79-
item[k] = rv
82+
vt[rk] = vtv
83+
delete(vt, vtk)
84+
}
85+
case string:
86+
if !strings.HasPrefix(vt, "$") {
87+
continue
88+
}
89+
refID := strings.TrimPrefix(vt, "$")
90+
rv, ok := c.refIDs[refID]
91+
if !ok {
92+
log.Printf("%s was not found", refID)
93+
continue
8094
}
95+
item[k] = rv
8196
}
8297
}
8398

pkg/inserter/js_inserter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ func (j *JSInserter) Execute(ctx context.Context, cn, path string) error {
6969
return nil
7070
}
7171

72-
//nolint:dupl
7372
// CreateItem - Firestore にアイテムを生成する
73+
// nolint:dupl
7474
func (j *JSInserter) CreateItem(ctx context.Context, path []string, items []Document, collectionIndexes []int) error {
7575
for idx, parentItem := range items {
7676
nowIndexes := append(collectionIndexes, idx)

pkg/inserter/json_inserter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ func (j *JSONInserter) Execute(ctx context.Context, cn, path string) error {
4545
return nil
4646
}
4747

48-
//nolint:dupl
4948
// CreateItem - Firestore にアイテムを生成する
49+
// nolint: dupl
5050
func (j *JSONInserter) CreateItem(ctx context.Context, path []string, items []Document, collectionIndexes []int) error {
5151
for idx, parentItem := range items {
5252
nowIndexes := append(collectionIndexes, idx)

samples/Option/dummies.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"versions": "1.0",
3+
"items": [
4+
{
5+
"ref": "Option__dummy_0",
6+
"payload": {
7+
"name": "選択肢0"
8+
}
9+
},
10+
{
11+
"ref": "Option__dummy_1",
12+
"payload": {
13+
"name": "選択肢1"
14+
}
15+
}
16+
]
17+
}

samples/Survey/dummies.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "1.0",
3+
"items": [
4+
{
5+
"ref": "Foo__dummy_0",
6+
"payload": {
7+
"defaultOption": "$Option__dummy_0",
8+
"options": {
9+
"$Option__dummy_0": true,
10+
"$Option__dummy_1": true
11+
}
12+
}
13+
}
14+
]
15+
}

samples/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
targets:
22
- ./samples/Account
33
- ./samples/Food
4+
- ./samples/Option
5+
- ./samples/Survey
46
firestore_project_on_emulator: sample
57
firestore_emulator_host: localhost:41848

0 commit comments

Comments
 (0)