Skip to content

Commit ec65c7c

Browse files
committed
feat: trello plugin use env to set apiKey and token
Signed-off-by: Bird <[email protected]>
1 parent 2440e07 commit ec65c7c

File tree

10 files changed

+39
-25
lines changed

10 files changed

+39
-25
lines changed

docs/core-concepts/config.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,17 @@ For example, given config:
101101
```yaml
102102
tools:
103103
- name: trello
104-
instanceID: default
105-
options:
106-
scm:
107-
owner: IronCore864
108-
name: golang-demo
109-
scmType: github
110-
borad:
111-
name: golang-demo-board
112-
```
104+
instanceID: default
105+
options:
106+
board:
107+
name: golang-demo-board
108+
apikey: xxx
109+
token: xxx
110+
scm:
111+
owner: IronCore864
112+
repo: golang-demo
113+
scmType: github
114+
```
113115
114116
- `TOOL_NAME` is "trello"
115117
- `TOOL_INSTANCE_ID` is "default"

docs/core-concepts/config.zh.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,15 @@ tools:
100100
- name: trello
101101
instanceID: default
102102
options:
103-
owner: IronCore864
104-
repo: golang-demo
105-
kanbanBoardName: golang-demo-board
106-
```
103+
board:
104+
name: golang-demo-board
105+
apikey: xxx
106+
token: xxx
107+
scm:
108+
owner: IronCore864
109+
repo: golang-demo
110+
scmType: github
111+
```
107112
108113
- `TOOL_NAME` 是 "trello"
109114
- `TOOL_INSTANCE_ID` 是 "default"

internal/pkg/plugin/trello/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ type options struct {
2424
type board struct {
2525
Name string `mapstructure:"name"`
2626
Description string `mapstructure:"description"`
27+
APIKey string `mapstructure:"apiKey"`
28+
Token string `mapstructure:"token"`
2729
}
2830

2931
type boardIDInfo struct {

internal/pkg/plugin/trello/state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func getState(rawOptions configmanager.RawOptions) (statemanager.ResourceStatus,
1616
return nil, err
1717
}
1818

19-
c, err := trello.NewClient()
19+
c, err := trello.NewClient(opts.Board.APIKey, opts.Board.Token)
2020
if err != nil {
2121
return nil, err
2222
}

internal/pkg/plugin/trello/trello.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func createBoard(rawOptions configmanager.RawOptions) error {
1313
if err != nil {
1414
return err
1515
}
16-
c, err := trello.NewClient()
16+
c, err := trello.NewClient(opts.Board.APIKey, opts.Board.Token)
1717
if err != nil {
1818
return err
1919
}
@@ -27,7 +27,7 @@ func deleteBoard(rawOptions configmanager.RawOptions) error {
2727
if err != nil {
2828
return err
2929
}
30-
c, err := trello.NewClient()
30+
c, err := trello.NewClient(opts.Board.APIKey, opts.Board.Token)
3131
if err != nil {
3232
return err
3333
}
@@ -48,7 +48,7 @@ func addTrelloSecret(rawOptions configmanager.RawOptions) error {
4848
}
4949

5050
// 2. init trello client
51-
trelloClient, err := trello.NewClient()
51+
trelloClient, err := trello.NewClient(opts.Board.APIKey, opts.Board.Token)
5252
if err != nil {
5353
return err
5454
}

internal/pkg/plugin/trello/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func setDefault(rawOptions configmanager.RawOptions) (configmanager.RawOptions,
3232
if err != nil {
3333
return nil, err
3434
}
35-
// set board dedefault value
35+
// set board default value
3636
var boardDefaultConfig = &board{
3737
Name: fmt.Sprintf("%s/%s", opts.Scm.GetRepoOwner(), opts.Scm.GetRepoName()),
3838
Description: fmt.Sprintf("Description is managed by DevStream, please don't modify. %s/%s", opts.Scm.GetRepoOwner(), opts.Scm.GetRepoName()),

internal/pkg/plugin/trello/validate_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ var _ = Describe("setDefault method", func() {
2525
Expect(data["board"]).Should(Equal(map[string]any{
2626
"name": "test_user/test",
2727
"description": "Description is managed by DevStream, please don't modify. test_user/test",
28+
"apiKey": "",
29+
"token": "",
2830
}))
2931
Expect(data["scm"]).Should(Equal(map[string]any{
3032
"owner": "test_user",

internal/pkg/show/config/plugins/trello.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ tools:
99
options:
1010
# the repo's owner
1111
board:
12-
# the Tello board name. If empty, use owner/name as the board's name.
12+
# the Trello board name. If empty, use owner/name as the board's name.
1313
name: KANBAN_BOARD_NAME
14-
# the Tello board description. If empty, use devstream's default description
14+
# the Trello board description. If empty, use devstream's default description
1515
description: KANBAN_DESCRIPTION
16+
# Trello apiKey and token, see https://docs.servicenow.com/bundle/quebec-it-asset-management/page/product/software-asset-management2/task/generate-trello-apikey-token.html for more information
17+
apikey: [[ env TRELLO_API_KEY ]] # use environment variable "TRELLO_API_KEY" to set the value
18+
token: [[ env TRELLO_TOKEN ]] # use environment variable "TRELLO_TOKEN" to set the value
1619
scm:
1720
name: YOUR_PROJECT_NAME
1821
owner: YOUR_REPO_OWNER
@@ -21,4 +24,4 @@ tools:
2124
# project branch
2225
branch: YOUR_PROJECT_BRANCH
2326
# scm repo token
24-
token: YOUR_REPO_TOKEN
27+
token: [[ env GITHUB_TOKEN ]] # use environment variable "GITHUB_TOKEN" to set the value

pkg/util/trello/trello.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package trello
22

33
import (
44
"fmt"
5-
"os"
65

76
"github.com/adlio/trello"
87
)
@@ -16,9 +15,7 @@ type client struct {
1615
*trello.Client
1716
}
1817

19-
func NewClient() (TrelloAPI, error) {
20-
apiKey := os.Getenv("TRELLO_API_KEY")
21-
token := os.Getenv("TRELLO_TOKEN")
18+
func NewClient(apiKey, token string) (TrelloAPI, error) {
2219
if apiKey == "" || token == "" {
2320
const helpUrl = "https://docs.servicenow.com/bundle/quebec-it-asset-management/page/product/software-asset-management2/task/generate-trello-apikey-token.html"
2421
return nil, fmt.Errorf("TRELLO_API_KEY and/or TRELLO_TOKEN are/is empty. see %s for more info", helpUrl)

test/e2e/yaml/e2e-trello-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ tools:
1818
org: [[ githubOrganization ]]
1919
name: [[ repoName ]]
2020
scmType: github
21+
token: [[ env GITHUB_TOKEN ]]
2122
board:
2223
name: [[ kanbanBoardName ]]
24+
apikey: [[ env TRELLO_API_KEY ]]
25+
token: [[ env TRELLO_TOKEN ]]

0 commit comments

Comments
 (0)