• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

go-playground / webhooks / 11185386857

04 Oct 2024 06:52PM UTC coverage: 88.583% (-0.4%) from 88.933%
11185386857

Pull #199

github

j2nullify
Autofix for finding 01J0HQ0A7GG1STVT9074R18TMZ
Pull Request #199: Autofix/01 j0 hq0 a7 gg1 stvt9074 r18 tmz

249 of 270 new or added lines in 9 files covered. (92.22%)

64 existing lines in 7 files now uncovered.

900 of 1016 relevant lines covered (88.58%)

8.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.73
/docker/docker.go
1
package docker
2

3
// this package receives the Docker Hub Automated Build webhook
4
// https://docs.docker.com/docker-hub/webhooks/
5
// NOT the Docker Trusted Registry webhook
6
// https://docs.docker.com/ee/dtr/user/create-and-manage-webhooks/
7

8
import (
9
        "encoding/json"
10
        "errors"
11
        "io"
12
        "net/http"
13
)
14

15
// parse errors
16
var (
17
        ErrInvalidHTTPMethod = errors.New("invalid HTTP Method")
18
        ErrParsingPayload    = errors.New("error parsing payload")
19
)
20

21
// Event defines a Docker hook event type
22
type Event string
23

24
// Docker hook types (only one for now)
25
const (
26
        BuildEvent Event = "build"
27
)
28

29
// BuildPayload a docker hub build notice
30
// https://docs.docker.com/docker-hub/webhooks/
31
type BuildPayload struct {
32
        CallbackURL string `json:"callback_url"`
33
        PushData    struct {
34
                Images   []string `json:"images"`
35
                PushedAt float32  `json:"pushed_at"`
36
                Pusher   string   `json:"pusher"`
37
                Tag      string   `json:"tag"`
38
        } `json:"push_data"`
39
        Repository struct {
40
                CommentCount    int     `json:"comment_count"`
41
                DateCreated     float32 `json:"date_created"`
42
                Description     string  `json:"description"`
43
                Dockerfile      string  `json:"dockerfile"`
44
                FullDescription string  `json:"full_description"`
45
                IsOfficial      bool    `json:"is_official"`
46
                IsPrivate       bool    `json:"is_private"`
47
                IsTrusted       bool    `json:"is_trusted"`
48
                Name            string  `json:"name"`
49
                Namespace       string  `json:"namespace"`
50
                Owner           string  `json:"owner"`
51
                RepoName        string  `json:"repo_name"`
52
                RepoURL         string  `json:"repo_url"`
53
                StarCount       int     `json:"star_count"`
54
                Status          string  `json:"status"`
55
        } `json:"repository"`
56
}
57

58
// Webhook instance contains all methods needed to process events
59
type Webhook struct {
60
}
61

62
// New creates and returns a WebHook instance
63
func New() (*Webhook, error) {
1✔
64
        hook := new(Webhook)
1✔
65
        return hook, nil
1✔
66
}
1✔
67

68
// Parse verifies and parses the events specified and returns the payload object or an error
69
func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error) {
1✔
70
        defer func() {
2✔
71
                _, _ = io.Copy(io.Discard, r.Body)
1✔
72
                _ = r.Body.Close()
1✔
73
        }()
1✔
74

75
        if r.Method != http.MethodPost {
1✔
76
                return nil, ErrInvalidHTTPMethod
×
UNCOV
77
        }
×
78

79
        payload, err := io.ReadAll(r.Body)
1✔
80
        if err != nil || len(payload) == 0 {
1✔
81
                return nil, ErrParsingPayload
×
UNCOV
82
        }
×
83

84
        var pl BuildPayload
1✔
85
        err = json.Unmarshal([]byte(payload), &pl)
1✔
86
        if err != nil {
1✔
87
                return nil, ErrParsingPayload
×
UNCOV
88
        }
×
89
        return pl, err
1✔
90

91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc