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

armory / dinghy / 9704674769

27 Jun 2024 10:54PM UTC coverage: 41.534% (-13.0%) from 54.581%
9704674769

Pull #187

github

jasonmcintosh
fix: Builds to use parallel checks
Pull Request #187: chore: Upgrade to golang 1.22, sprout vs. spring, and other updates and fixes plus plank upgrade to fix deletes

8 of 22 new or added lines in 8 files covered. (36.36%)

1 existing line in 1 file now uncovered.

2252 of 5422 relevant lines covered (41.53%)

14.59 hits per line

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

0.0
/pkg/events/events.go
1
/*
2
* Copyright 2019 Armory, Inc.
3

4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7

8
*    http://www.apache.org/licenses/LICENSE-2.0
9

10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
 */
16

17
package events
18

19
import (
20
        "context"
21
        "encoding/json"
22
        "errors"
23
        "fmt"
24
        "github.com/armory/dinghy/pkg/settings/global"
25
        "net/http"
26

27
        cleanhttp "github.com/hashicorp/go-cleanhttp"
28
        retryablehttp "github.com/hashicorp/go-retryablehttp"
29
        log "github.com/sirupsen/logrus"
30
)
31

32
type EventClient interface {
33
        SendEvent(string, *Event)
34
}
35

36
type Client struct {
37
        Client        *retryablehttp.Client
38
        Settings      *global.Settings
39
        Ctx           context.Context
40
        IsMultiTenant bool
41
}
42

43
type Event struct {
44
        Start      int64  `json:"start_time"`
45
        End        int64  `json:"end_time"`
46
        Org        string `json:"org"`
47
        Repo       string `json:"repo"`
48
        Path       string `json:"path"`
49
        Branch     string `json:"branch"`
50
        Dinghyfile string `json:"dinghyfile"`
51
        Module     bool   `json:"is_module"`
52
}
53

54
type details struct {
55
        Source  string `json:"source"`
56
        Version string `json:"sourceVersion"`
57
        Type    string `json:"type"`
58
}
59

60
type payload struct {
61
        Details details `json:"details"`
62
        Event   *Event  `json:"content"`
63
}
64

65
func NewEventClient(ctx context.Context, settings *global.Settings, isMultiTennant bool) *Client {
×
66
        c := retryablehttp.NewClient()
×
67
        c.HTTPClient.Transport = cleanhttp.DefaultPooledTransport() // reuse the client so we can pipeline stuff
×
68
        return &Client{
×
NEW
69
                Client:        c,
×
NEW
70
                Settings:      settings,
×
NEW
71
                Ctx:           ctx,
×
72
                IsMultiTenant: isMultiTennant,
×
73
        }
×
74
}
×
75

76
func (c *Client) SendEvent(eventType string, event *Event) {
×
77
        payload := payload{
×
78
                Details: details{
×
79
                        Source:  "dinghy",
×
80
                        Version: c.Settings.Logging.Remote.Version,
×
81
                        Type:    eventType,
×
82
                },
×
83
                Event: event,
×
84
        }
×
85

×
86
        if err := c.postEvent(payload); err != nil {
×
87
                log.Errorf(err.Error())
×
88
                return
×
89
        }
×
90
}
91

92
func (c *Client) postEvent(event payload) error {
×
93
        postData, err := json.Marshal(event)
×
94
        if err != nil {
×
95
                return err
×
96
        }
×
97
        var req *retryablehttp.Request
×
98
        if c.IsMultiTenant {
×
99
                req, err = retryablehttp.NewRequest(http.MethodPost, c.Settings.SpinnakerSupplied.Gate.BaseURL, postData)
×
100
        } else {
×
101
                req, err = retryablehttp.NewRequest(http.MethodPost, c.Settings.SpinnakerSupplied.Echo.BaseURL, postData)
×
102
        }
×
103
        if err != nil {
×
104
                return err
×
105
        }
×
106

107
        req.Header.Set("Content-Type", "application/json")
×
108
        req = req.WithContext(c.Ctx)
×
109
        res, err := c.Client.Do(req)
×
110
        if err != nil {
×
111
                return err
×
112
        }
×
113
        if res.StatusCode != 200 {
×
114
                return errors.New(fmt.Sprintf("debug at %s returned %d", c.Settings.SpinnakerSupplied.Echo.BaseURL, res.StatusCode))
×
115
        }
×
116
        return nil
×
117
}
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

© 2025 Coveralls, Inc