Skip to content

Commit 5d2b616

Browse files
Copy some diverged changes over (#31)
Co-authored-by: @lstout
1 parent 664d0dc commit 5d2b616

File tree

10 files changed

+66
-53
lines changed

10 files changed

+66
-53
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.18
1+
FROM golang:1.23
22

33
WORKDIR /usr/src/app
44

cmd/gitlab-honeycomb-buildevents/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import (
55
"os"
66
"strconv"
77

8-
"github.com/zoidbergwill/gitlab-honeycomb-buildevents-webhooks-sink/internal/hook"
9-
108
"github.com/honeycombio/libhoney-go"
119
"github.com/spf13/cobra"
10+
"github.com/zoidyzoidzoid/gitlab-honeycomb-buildevents-webhooks-sink/internal/hook"
1211
)
1312

1413
// Version is the default value that should be overridden in the

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module github.com/zoidyzoidzoid/gitlab-honeycomb-buildevents-webhooks-sink
22

3-
// +heroku goVersion 1.18
4-
go 1.18
3+
// +heroku goVersion 1.23
4+
go 1.23
55

66
require (
77
github.com/honeycombio/libhoney-go v1.20.0

internal/hook/hook.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"github.com/honeycombio/libhoney-go"
1414
"github.com/honeycombio/libhoney-go/transmission"
15-
"github.com/zoidbergwill/gitlab-honeycomb-buildevents-webhooks-sink/internal/hook/types"
15+
"github.com/zoidyzoidzoid/gitlab-honeycomb-buildevents-webhooks-sink/internal/hook/types"
1616
)
1717

1818
type Listener struct {
@@ -48,7 +48,7 @@ func New(cfg Config) (*Listener, error) {
4848
mux.HandleFunc("/", l.Home)
4949

5050
srv := &http.Server{
51-
Addr: fmt.Sprintf(cfg.ListenAddr),
51+
Addr: cfg.ListenAddr,
5252
Handler: mux,
5353
ReadTimeout: 5 * time.Second,
5454
WriteTimeout: 10 * time.Second,
@@ -129,6 +129,13 @@ func (l *Listener) HandleRequest(w http.ResponseWriter, r *http.Request) {
129129
}
130130
}
131131

132+
func SendEvent(e *libhoney.Event) {
133+
err := e.Send()
134+
if err != nil {
135+
fmt.Printf("failed to send event: %s", err)
136+
}
137+
}
138+
132139
func (l *Listener) handlePipeline(p types.PipelineEventPayload) error {
133140
if p.ObjectAttributes.Duration == 0 || p.ObjectAttributes.Status == "running" {
134141
return nil
@@ -140,7 +147,7 @@ func (l *Listener) handlePipeline(p types.PipelineEventPayload) error {
140147
return err
141148
}
142149

143-
defer ev.Send()
150+
defer SendEvent(ev)
144151
buildURL := fmt.Sprintf("%s/-/pipelines/%d", p.Project.WebURL, p.ObjectAttributes.ID)
145152
err = ev.Add(map[string]interface{}{
146153
// Basic trace information
@@ -194,14 +201,14 @@ func (l *Listener) handleJob(j types.JobEventPayload) error {
194201
return err
195202
}
196203

197-
defer ev.Send()
204+
defer SendEvent(ev)
198205
err = ev.Add(map[string]interface{}{
199206
// Basic trace information
200207
"service_name": "job",
201208
"trace.span_id": spanID,
202209
"trace.trace_id": parentTraceID,
203210
"trace.parent_id": parentTraceID,
204-
"name": fmt.Sprintf(j.BuildName),
211+
"name": j.BuildName,
205212

206213
// CI information
207214
"ci_provider": "GitLab-CI",
@@ -210,12 +217,14 @@ func (l *Listener) handleJob(j types.JobEventPayload) error {
210217
"build_id": j.BuildID,
211218
"repo": j.Repository.Homepage,
212219
// TODO: Something with job status
213-
"status": j.BuildStatus,
220+
"status": j.BuildStatus,
221+
"queued_duration_ms": j.BuildQueuedDuration * 1000,
222+
"queued_duration_min": j.BuildQueuedDuration / 60,
214223

215224
// Runner information
216225
"ci_runner": j.Runner.Description,
217226
"ci_runner_id": j.Runner.ID,
218-
//"ci_runner_tags": strings.Join(j.Runner.Tags, ","),
227+
// "ci_runner_tags": strings.Join(j.Runner.Tags, ","),
219228

220229
"duration_ms": j.BuildDuration * 1000,
221230
})

internal/hook/hook_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package hook
22

33
import (
4-
"github.com/honeycombio/libhoney-go"
54
"testing"
5+
6+
"github.com/honeycombio/libhoney-go"
67
)
78

89
func Test_createEvent(t *testing.T) {
@@ -19,6 +20,9 @@ func Test_createEvent(t *testing.T) {
1920
HookSecret: "",
2021
HoneycombConfig: &config,
2122
})
23+
if err != nil {
24+
t.Errorf("failed to create config: %s", err)
25+
}
2226
got, err := l.createEvent()
2327
if err != nil {
2428
t.Errorf("failed to create event: %s", err)
@@ -35,7 +39,7 @@ func Test_createEvent(t *testing.T) {
3539
})
3640
}
3741

38-
//func Test_HandlePipeline(t *testing.T) {
42+
// func Test_HandlePipeline(t *testing.T) {
3943
// defer libhoney.Close()
4044
// var config libhoney.Config
4145
// tests := []struct {

internal/hook/parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"log"
99
"net/http"
1010

11-
"github.com/zoidbergwill/gitlab-honeycomb-buildevents-webhooks-sink/internal/hook/types"
11+
"github.com/zoidyzoidzoid/gitlab-honeycomb-buildevents-webhooks-sink/internal/hook/types"
1212
)
1313

1414
var (

internal/hook/types/job.go

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
package types
22

3-
// JobEventPayload contains the information for GitLab's Job status change
3+
// JobEventPayload contains the information for GitLab's Job status change.
44
type JobEventPayload struct {
5-
ObjectKind string `json:"object_kind"`
6-
Ref string `json:"ref"`
7-
Tag bool `json:"tag"`
8-
BeforeSHA string `json:"before_sha"`
9-
SHA string `json:"sha"`
10-
BuildID int64 `json:"build_id"`
11-
BuildName string `json:"build_name"`
12-
BuildStage string `json:"build_stage"`
13-
BuildStatus string `json:"build_status"`
14-
BuildStartedAt GitLabTimestamp `json:"build_started_at,omitempty"`
15-
BuildFinishedAt GitLabTimestamp `json:"build_finished_at,omitempty"`
16-
BuildDuration float64 `json:"build_duration"`
17-
BuildAllowFailure bool `json:"build_allow_failure"`
18-
BuildFailureReason string `json:"build_failure_reason"`
19-
PipelineID int64 `json:"pipeline_id"`
20-
ProjectID int64 `json:"project_id"`
21-
ProjectName string `json:"project_name"`
22-
User User `json:"user"`
23-
Commit BuildCommit `json:"commit"`
24-
Repository Repository `json:"repository"`
25-
Runner Runner `json:"runner"`
5+
ObjectKind string `json:"object_kind"`
6+
Ref string `json:"ref"`
7+
Tag bool `json:"tag"`
8+
BeforeSHA string `json:"before_sha"`
9+
SHA string `json:"sha"`
10+
BuildID int64 `json:"build_id"`
11+
BuildName string `json:"build_name"`
12+
BuildStage string `json:"build_stage"`
13+
BuildStatus string `json:"build_status"`
14+
BuildStartedAt GitLabTimestamp `json:"build_started_at,omitempty"`
15+
BuildFinishedAt GitLabTimestamp `json:"build_finished_at,omitempty"`
16+
BuildDuration float64 `json:"build_duration"`
17+
BuildAllowFailure bool `json:"build_allow_failure"`
18+
BuildFailureReason string `json:"build_failure_reason"`
19+
BuildQueuedDuration float64 `json:"build_queued_duration"`
20+
PipelineID int64 `json:"pipeline_id"`
21+
ProjectID int64 `json:"project_id"`
22+
ProjectName string `json:"project_name"`
23+
User User `json:"user"`
24+
Commit BuildCommit `json:"commit"`
25+
Repository Repository `json:"repository"`
26+
Runner Runner `json:"runner"`
2627
}
2728

28-
// BuildCommit contains all of the GitLab build commit information
29+
// BuildCommit contains all of the GitLab build commit information.
2930
type BuildCommit struct {
3031
ID int64 `json:"id"`
3132
SHA string `json:"sha"`

internal/hook/types/mergerequest.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package types
22

33
import "time"
44

5-
// MergeRequest contains all the GitLab merge request information
5+
// MergeRequest contains all the GitLab merge request information.
66
type MergeRequest struct {
77
ID int64 `json:"id"`
88
TargetBranch string `json:"target_branch"`
@@ -29,7 +29,7 @@ type MergeRequest struct {
2929
URL string `json:"url"`
3030
}
3131

32-
// Source contains all the GitLab source information
32+
// Source contains all the GitLab source information.
3333
type Source struct {
3434
Name string `json:"name"`
3535
Description string `json:"description"`
@@ -47,7 +47,7 @@ type Source struct {
4747
HTTPURL string `json:"http_url"`
4848
}
4949

50-
// Target contains all the GitLab target information
50+
// Target contains all the GitLab target information.
5151
type Target struct {
5252
Name string `json:"name"`
5353
Description string `json:"description"`
@@ -65,7 +65,7 @@ type Target struct {
6565
HTTPURL string `json:"http_url"`
6666
}
6767

68-
// LastCommit contains all the GitLab last commit information
68+
// LastCommit contains all the GitLab last commit information.
6969
type LastCommit struct {
7070
ID string `json:"id"`
7171
Message string `json:"message"`

internal/hook/types/pipeline.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package types
22

3-
// PipelineEventPayload contains the information for GitLab's pipeline status change event
3+
// PipelineEventPayload contains the information for GitLab's pipeline status change event.
44
type PipelineEventPayload struct {
55
ObjectKind string `json:"object_kind"`
66
User User `json:"user"`
@@ -11,7 +11,7 @@ type PipelineEventPayload struct {
1111
Builds []Build `json:"builds"`
1212
}
1313

14-
// PipelineObjectAttributes contains pipeline specific GitLab object attributes information
14+
// PipelineObjectAttributes contains pipeline specific GitLab object attributes information.
1515
type PipelineObjectAttributes struct {
1616
ID int64 `json:"id"`
1717
Ref string `json:"ref"`
@@ -27,13 +27,13 @@ type PipelineObjectAttributes struct {
2727
Variables []Variable `json:"variables"`
2828
}
2929

30-
// Variable contains pipeline variables
30+
// Variable contains pipeline variables.
3131
type Variable struct {
3232
Key string `json:"key"`
3333
Value string `json:"value"`
3434
}
3535

36-
// Build contains all of the GitLab Build information
36+
// Build contains all of the GitLab Build information.
3737
type Build struct {
3838
ID int64 `json:"id"`
3939
Stage string `json:"stage"`
@@ -49,7 +49,7 @@ type Build struct {
4949
ArtifactsFile ArtifactsFile `json:"artifactsfile"`
5050
}
5151

52-
// ArtifactsFile contains all of the GitLab artifact information
52+
// ArtifactsFile contains all of the GitLab artifact information.
5353
type ArtifactsFile struct {
5454
Filename string `json:"filename"`
5555
Size string `json:"size"`

internal/hook/types/types.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"time"
77
)
88

9-
// Commit contains all of the GitLab commit information
9+
// Commit contains all of the GitLab commit information.
1010
type Commit struct {
1111
ID string `json:"id"`
1212
Message string `json:"message"`
@@ -19,13 +19,13 @@ type Commit struct {
1919
Removed []string `json:"removed"`
2020
}
2121

22-
// Author contains all of the GitLab author information
22+
// Author contains all of the GitLab author information.
2323
type Author struct {
2424
Name string `json:"name"`
2525
Email string `json:"email"`
2626
}
2727

28-
// Project contains all of the GitLab project information
28+
// Project contains all of the GitLab project information.
2929
type Project struct {
3030
ID int64 `json:"id"`
3131
Name string `json:"name"`
@@ -44,7 +44,7 @@ type Project struct {
4444
HTTPURL string `json:"http_url"`
4545
}
4646

47-
// Repository contains all of the GitLab repository information
47+
// Repository contains all of the GitLab repository information.
4848
type Repository struct {
4949
Name string `json:"name"`
5050
URL string `json:"url"`
@@ -55,7 +55,7 @@ type Repository struct {
5555
VisibilityLevel int64 `json:"visibility_level"`
5656
}
5757

58-
// User contains all of the GitLab user information
58+
// User contains all of the GitLab user information.
5959
type User struct {
6060
ID int64 `json:"id"`
6161
Name string `json:"name"`
@@ -64,7 +64,7 @@ type User struct {
6464
Email string `json:"email"`
6565
}
6666

67-
// Runner represents a runner agent
67+
// Runner represents a runner agent.
6868
type Runner struct {
6969
ID int64 `json:"id"`
7070
Description string `json:"description"`

0 commit comments

Comments
 (0)