Skip to content

Commit 92417ad

Browse files
committed
update lambda
1 parent e7d3503 commit 92417ad

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

fn.go

+2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ func HandleRequest(_ context.Context, request events.LambdaFunctionURLRequest) (
1717

1818
secretToken := os.Getenv("SECRET_TOKEN")
1919
err := ParseWebHookJSON(secretToken, request)
20+
2021
if err != nil {
2122
fmt.Printf("error: %v\n", err)
23+
return GenerateResponse(err.Error(), 500), nil
2224
}
2325
return GenerateResponse("", 200), nil
2426
}

gitlab.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func ParseWebHookJSON(secret string, lambdaRequest events.LambdaFunctionURLReque
6868

6969
currentUser, _, err := gitLabClients[projectId].Users.CurrentUser()
7070
if err != nil {
71-
return fmt.Errorf("failed to get current GitLab user info, %v", err)
71+
return fmt.Errorf("failed to get current GitLab user info, projectId: %v, %v", projectId, err)
7272
}
7373
fmt.Printf("Current GitLab user id: %d\n", currentUser.ID)
7474

@@ -142,7 +142,7 @@ func ParseWebHookJSON(secret string, lambdaRequest events.LambdaFunctionURLReque
142142

143143
currentUser, _, err := gitLabClients[projectId].Users.CurrentUser()
144144
if err != nil {
145-
return fmt.Errorf("failed to get current GitLab user info, %v", err)
145+
return fmt.Errorf("failed to get current GitLab user info, projectId: %v, %v", projectId, err)
146146
}
147147
fmt.Printf("Current GitLab user id: %d\n", currentUser.ID)
148148

@@ -259,7 +259,8 @@ func CreateGitLabClient() (map[int]*gitlab.Client, error) {
259259
var tokens []map[string]string
260260
err := json.Unmarshal([]byte(gitlabTokenJson), &tokens)
261261
if err != nil {
262-
panic(err)
262+
fmt.Printf("failed to unmarshal gitlabTokenJson, %v", err)
263+
return nil, err
263264
}
264265
result = make(map[int]*gitlab.Client, len(tokens))
265266

go.mod

-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ go 1.20
44

55
require (
66
github.com/aws/aws-lambda-go v1.39.1
7-
github.com/davecgh/go-spew v1.1.1
8-
github.com/tidwall/gjson v1.14.4
97
github.com/xanzy/go-gitlab v0.81.0
108
)
119

@@ -14,8 +12,6 @@ require (
1412
github.com/google/go-querystring v1.1.0 // indirect
1513
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
1614
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
17-
github.com/tidwall/match v1.1.1 // indirect
18-
github.com/tidwall/pretty v1.2.0 // indirect
1915
golang.org/x/net v0.8.0 // indirect
2016
golang.org/x/oauth2 v0.6.0 // indirect
2117
golang.org/x/time v0.3.0 // indirect

go.sum

-6
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
2121
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2222
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
2323
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
24-
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
25-
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
26-
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
27-
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
28-
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
29-
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
3024
github.com/xanzy/go-gitlab v0.81.0 h1:ofbhZ5ZY9AjHATWQie4qd2JfncdUmvcSA/zfQB767Dk=
3125
github.com/xanzy/go-gitlab v0.81.0/go.mod h1:VMbY3JIWdZ/ckvHbQqkyd3iYk2aViKrNIQ23IbFMQDo=
3226
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

readme.md

+6
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@
1919
{"project": "46465722", "token": "glpat-1212232311"},
2020
{"project": "44723537": "token": "glpat-2323232323"}
2121
]
22+
```
23+
24+
## to deploy
25+
```
26+
npm run build
27+
serverless deploy
2228
```

0 commit comments

Comments
 (0)