From 7ebb35b5650c2ca1e4ed8c0b3075c0fb51d4b154 Mon Sep 17 00:00:00 2001 From: jichangjun Date: Sun, 8 Sep 2024 18:33:24 +0800 Subject: [PATCH] refactor: use event id instead of uuid --- internal/lintersutil/lintersutil.go | 9 +++++++++ server.go | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/lintersutil/lintersutil.go b/internal/lintersutil/lintersutil.go index f264db4..c4ffe70 100644 --- a/internal/lintersutil/lintersutil.go +++ b/internal/lintersutil/lintersutil.go @@ -56,3 +56,12 @@ func FromContext(ctx context.Context) *xlog.Logger { } return xlog.New(eventGUID) } + +// GetEventGUID returns the event GUID from the context. +func GetEventGUID(ctx context.Context) string { + eventGUID, ok := ctx.Value(EventGUIDKey).(string) + if !ok { + return "default" + } + return eventGUID +} diff --git a/server.go b/server.go index a74a11c..aca7d36 100644 --- a/server.go +++ b/server.go @@ -28,7 +28,6 @@ import ( "github.com/bradleyfalzon/ghinstallation/v2" "github.com/google/go-github/v57/github" - "github.com/google/uuid" "github.com/gregjones/httpcache" "github.com/qiniu/reviewbot/config" "github.com/qiniu/reviewbot/internal/linters" @@ -329,7 +328,7 @@ func (s *Server) handle(ctx context.Context, event *github.PullRequestEvent) err PullRequestChangedFiles: pullRequestAffectedFiles, RepoDir: r.Directory(), Context: ctx, - ID: uuid.New().String(), + ID: lintersutil.GetEventGUID(ctx), } if !linters.LinterRelated(name, agent) {