Skip to content

Commit f6b4009

Browse files
committed
Add license
Signed-off-by: jolheiser <[email protected]>
1 parent 92e9281 commit f6b4009

File tree

5 files changed

+30
-46
lines changed

5 files changed

+30
-46
lines changed

modules/webhook/webhook_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
15
package webhook
26

37
import (

routers/web/repo/webhook_custom.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
15
package repo
26

37
import (

services/webhook/custom.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
15
package webhook
26

37
import (

testdata/testdata.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
15
package testdata
26

37
import "embed"

testdata/webhook/executable.go

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
package webhook
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
26

37
import (
48
"encoding/json"
@@ -8,12 +12,11 @@ import (
812
)
913

1014
type Payload struct {
11-
Form map[string]struct {
12-
Label string `json:"label"`
13-
Type string `json:"type"`
14-
Required bool `json:"required"`
15-
Default interface{} `json:"default"`
16-
Value interface{} `json:"value"`
15+
Form struct {
16+
Username string `json:"username"`
17+
FavoriteNumber int `json:"favorite-number"`
18+
Pineapple bool `json:"pineapple"`
19+
Passphrase string `json:"passphrase"`
1720
} `json:"form"`
1821
}
1922

@@ -28,58 +31,23 @@ func main() {
2831
panic(err)
2932
}
3033

31-
username, ok := p.Form["username"]
32-
if !ok {
33-
panic("username not found in form data")
34-
}
35-
checkType(username.Type, username.Value)
36-
if username.Value.(string) != "jolheiser" {
34+
if p.Form.Username != "jolheiser" {
3735
panic("username should be jolheiser")
3836
}
3937

40-
favNum, ok := p.Form["favorite-number"]
41-
if !ok {
42-
panic("favorite-number not found in form data")
43-
}
44-
checkType(favNum.Type, favNum.Value)
45-
if username.Value.(float64) != 12 {
38+
if p.Form.FavoriteNumber != 12 {
4639
panic("favNum should be 12")
4740
}
4841

49-
pineapple, ok := p.Form["pineapple"]
50-
if !ok {
51-
panic("pineapple not found in form data")
52-
}
53-
checkType(pineapple.Type, pineapple.Value)
54-
if pineapple.Value.(bool) {
42+
if p.Form.Pineapple {
5543
panic("pineapple should be false")
5644
}
5745

58-
secret, ok := p.Form["secret"]
59-
if !ok {
60-
panic("secret not found in form data")
61-
}
62-
checkType(secret.Type, secret.Value)
63-
if secret.Value.(string) != "sn34ky" {
46+
if p.Form.Passphrase != "sn34ky" {
6447
panic("secret should be sn34ky")
6548
}
6649
}
6750

68-
func checkType(typ string, val interface{}) {
69-
var ok bool
70-
switch typ {
71-
case "text", "secret":
72-
_, ok = val.(string)
73-
case "bool":
74-
_, ok = val.(bool)
75-
case "number":
76-
_, ok = val.(float64)
77-
}
78-
if !ok {
79-
panic(fmt.Sprintf("unexpected type %q for %v", typ, val))
80-
}
81-
}
82-
8351
// override panic
8452
func panic(v interface{}) {
8553
fmt.Println(v)

0 commit comments

Comments
 (0)