Skip to content

Commit f8322c0

Browse files
committed
feat: add __ID__ pipeline marker for the eval id
1 parent 1949473 commit f8322c0

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

cmd/shared.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func ProcessMR(ctx context.Context, client scm.Client, cfg *config.Config, event
3737
ctx = state.WithStartTime(ctx, time.Now())
3838

3939
// Attach unique eval id to the logs so they are easy to filter on later
40-
ctx = slogctx.With(ctx, slog.String("eval_id", sid.MustGenerate()))
40+
ctx = state.WithEvaluationID(ctx, sid.MustGenerate())
4141

4242
// Track where we grab the configuration file from
4343
ctx = slogctx.With(ctx, slog.String("config_source_branch", "merge_request_branch"))

pkg/scm/gitlab/client.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ func (client *Client) Start(ctx context.Context) error {
119119

120120
if len(pattern) != 0 {
121121
link := pattern
122-
link = strings.ReplaceAll(link, "__PROJECT_ID__", state.ProjectID(ctx))
122+
link = strings.ReplaceAll(link, "__ID__", state.EvaluationID(ctx))
123123
link = strings.ReplaceAll(link, "__MR_ID__", state.MergeRequestID(ctx))
124+
link = strings.ReplaceAll(link, "__PROJECT_ID__", state.ProjectID(ctx))
124125
link = strings.ReplaceAll(link, "__START_TS_MS__", strconv.FormatInt(state.StartTime(ctx).UnixMilli(), 10))
125126
link = strings.ReplaceAll(link, "__STOP_TS_MS__", "")
126127

@@ -158,8 +159,9 @@ func (client *Client) Stop(ctx context.Context, err error) error {
158159

159160
if len(pattern) != 0 {
160161
link := pattern
161-
link = strings.ReplaceAll(link, "__PROJECT_ID__", state.ProjectID(ctx))
162+
link = strings.ReplaceAll(link, "__ID__", state.EvaluationID(ctx))
162163
link = strings.ReplaceAll(link, "__MR_ID__", state.MergeRequestID(ctx))
164+
link = strings.ReplaceAll(link, "__PROJECT_ID__", state.ProjectID(ctx))
163165
link = strings.ReplaceAll(link, "__START_TS_MS__", strconv.FormatInt(state.StartTime(ctx).UnixMilli(), 10))
164166
link = strings.ReplaceAll(link, "__STOP_TS_MS__", strconv.FormatInt(time.Now().UnixMilli(), 10))
165167

pkg/state/context.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,21 @@ const (
2020
mergeRequestID
2121
projectID
2222
provider
23+
startTime
2324
token
2425
updatePipeline
2526
updatePipelineURL
26-
startTime
27+
evaluationID
2728
)
2829

2930
func ProjectID(ctx context.Context) string {
3031
return ctx.Value(projectID).(string) //nolint:forcetypeassert
3132
}
3233

34+
func EvaluationID(ctx context.Context) string {
35+
return ctx.Value(evaluationID).(string) //nolint:forcetypeassert
36+
}
37+
3338
func CommitSHA(ctx context.Context) string {
3439
return ctx.Value(commitSha).(string) //nolint:forcetypeassert
3540
}
@@ -62,6 +67,12 @@ func StartTime(ctx context.Context) time.Time {
6267
return ctx.Value(startTime).(time.Time) //nolint:forcetypeassert
6368
}
6469

70+
func WithEvaluationID(ctx context.Context, id string) context.Context {
71+
ctx = slogctx.With(ctx, slog.String("eval_id", id))
72+
73+
return context.WithValue(ctx, evaluationID, id)
74+
}
75+
6576
func WithStartTime(ctx context.Context, now time.Time) context.Context {
6677
return context.WithValue(ctx, startTime, now)
6778
}

0 commit comments

Comments
 (0)