Skip to content

Commit 58e1445

Browse files
committed
fix: update .md doc, functions
1 parent 5b444fd commit 58e1445

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

docs/plugins/trello-github-integ_plugin.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## 1 `trello-github-integ` Plugin
22

3-
This plugin creates a new github actions file(trello-github-integration) and upload to your GitHub repo.
3+
This plugin creates a new GitHub Actions file(trello-github-integration) and upload to your GitHub repo.
44

55
## 2 Usage:
66

@@ -24,7 +24,7 @@ tools:
2424
owner: YOUR_GITHUB_USERNAME
2525
# the repo where you'd like to setup GitHub Actions; please change the value below.
2626
repo: YOUR_REPO_NAME
27-
# reference from dependency
27+
# reference parameters come from dependency, their usage will be explained later
2828
boardId: ${{ default.trello.outputs.boardId }}
2929
todoListId: ${{ default.trello.outputs.todoListId }}
3030
doingListId: ${{ default.trello.outputs.doingListId }}
@@ -42,26 +42,26 @@ See the example below:
4242
```yaml
4343
---
4444
tools:
45-
- name: default
45+
- name: trello_init_demo
4646
plugin:
4747
kind: trello
4848
version: 0.2.0
4949
options:
5050
owner: lfbdev
5151
repo: golang-demo
5252
kanbanBoardName: kanban-name
53-
- name: default_trello_github
53+
- name: trello_github_integ_demo
5454
plugin:
5555
kind: trello-github-integ
5656
version: 0.2.0
57-
dependsOn: ["default.trello"]
57+
dependsOn: ["trello_init_demo.trello"]
5858
options:
5959
owner: lfbdev
6060
repo: golang-demo
61-
boardId: ${{ default.trello.outputs.bid }}
62-
todoListId: ${{ default.trello.outputs.todoid }}
63-
doingListId: ${{ default.trello.outputs.doingid }}
64-
doneListId: ${{ default.trello.outputs.doneid }}
61+
boardId: ${{ trello_init_demo.trello.outputs.boardId }}
62+
todoListId: ${{ trello_init_demo.trello.outputs.todoListId }}
63+
doingListId: ${{ trello_init_demo.trello.outputs.doingListId }}
64+
doneListId: ${{ trello_init_demo.trello.outputs.doneListId }}
6565
branch: main
6666
```
6767

docs/plugins/trello_plugin.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,26 @@ See the example below:
4444
```yaml
4545
---
4646
tools:
47-
- name: default
47+
- name: trello_init_demo
4848
plugin:
4949
kind: trello
5050
version: 0.2.0
5151
options:
5252
owner: lfbdev
5353
repo: golang-demo
5454
kanbanBoardName: kanban-name
55-
- name: default_trello_github
55+
- name: trello_github_integ_demo
5656
plugin:
5757
kind: trello-github-integ
5858
version: 0.2.0
59-
dependsOn: ["default.trello"]
59+
dependsOn: ["trello_init_demo.trello"]
6060
options:
6161
owner: lfbdev
6262
repo: golang-demo
63-
api:
64-
name: trello
65-
boardId: ${{ default.trello.outputs.bid }}
66-
todoListId: ${{ default.trello.outputs.todoid }}
67-
doingListId: ${{ default.trello.outputs.doingid }}
68-
doneListId: ${{ default.trello.outputs.doneid }}
63+
boardId: ${{ trello_init_demo.trello.outputs.boardId }}
64+
todoListId: ${{ trello_init_demo.trello.outputs.todoListId }}
65+
doingListId: ${{ trello_init_demo.trello.outputs.doingListId }}
66+
doneListId: ${{ trello_init_demo.trello.outputs.doneListId }}
6967
branch: main
7068
```
7169

internal/pkg/pluginengine/change.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func execute(smgr statemanager.Manager, changes []*Change) map[string]error {
103103

104104
log.Info("tool raw changes: ", c.Tool.Options)
105105
// fill ref inputs
106-
err = FillInputParams(smgr, c.Tool.Options)
106+
err = fillRefValueWithOutputs(smgr, c.Tool.Options)
107107
if err != nil {
108108
succeeded = false
109109
}
@@ -184,7 +184,7 @@ func handleResult(smgr statemanager.Manager, change *Change) error {
184184
}
185185

186186
// FillInputParams fill inputs from state
187-
func FillInputParams(smgr statemanager.Manager, options map[string]interface{}) error {
187+
func fillRefValueWithOutputs(smgr statemanager.Manager, options map[string]interface{}) error {
188188
// traverse options
189189
for key, value := range options {
190190
log.Debugf("Key: %s, Value: %s.", key, value)
@@ -199,8 +199,12 @@ func FillInputParams(smgr statemanager.Manager, options map[string]interface{})
199199
return errors.New("ref input format is not correct: " + ref)
200200
}
201201

202-
outputs := smgr.GetOutputs(refParam)
202+
outputs, err := smgr.GetOutputs(statemanager.GenStateKey(refParam))
203+
if err != nil {
204+
return err
205+
}
203206
log.Debug("Ref outputs: ", outputs)
207+
204208
if outs, ok := outputs.(map[string]interface{}); ok {
205209
log.Debug("Ref outs: ", outs)
206210
log.Debug("Ref param: ", refParam[3])
@@ -213,7 +217,7 @@ func FillInputParams(smgr statemanager.Manager, options map[string]interface{})
213217
}
214218
// judge wheter the format is map[string]interface{}, if true, then recursion
215219
if _, ok := value.(map[string]interface{}); ok {
216-
if err := FillInputParams(smgr, value.(map[string]interface{})); err != nil {
220+
if err := fillRefValueWithOutputs(smgr, value.(map[string]interface{})); err != nil {
217221
return err
218222
}
219223
}

internal/pkg/statemanager/manager.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package statemanager
22

33
import (
4+
"errors"
45
"fmt"
56

67
"gopkg.in/yaml.v3"
@@ -28,7 +29,7 @@ type Manager interface {
2829
AddState(key StateKey, state State) error
2930
UpdateState(key StateKey, state State) error
3031
DeleteState(key StateKey) error
31-
GetOutputs(refParam []string) interface{}
32+
GetOutputs(key StateKey) (interface{}, error)
3233
}
3334

3435
// manager is the default implement with Manager
@@ -108,7 +109,10 @@ func (m *manager) DeleteState(key StateKey) error {
108109
return m.Write(m.GetStatesMap().Format())
109110
}
110111

111-
func (m *manager) GetOutputs(refParam []string) interface{} {
112-
state := m.GetState(GenStateKey(refParam))
113-
return state.Resource["outputs"]
112+
func (m *manager) GetOutputs(key StateKey) (interface{}, error) {
113+
state := m.GetState(key)
114+
if value, ok := state.Resource["outputs"]; ok {
115+
return value, nil
116+
}
117+
return nil, errors.New(fmt.Sprintf("cannot find outputs from state: %s.", state.Name))
114118
}

0 commit comments

Comments
 (0)