From ffc355c630efda7fd6601106e00bae674de3442b Mon Sep 17 00:00:00 2001 From: Ryan Albert <42415738+ryan-timothy-albert@users.noreply.github.com> Date: Wed, 30 Oct 2024 13:13:48 -0700 Subject: [PATCH] feat: format pull request link (#181) * feat: format pull request link * feat: format pull request link --- internal/telemetry/telemetry.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/telemetry/telemetry.go b/internal/telemetry/telemetry.go index e3d10d8..0a6f832 100644 --- a/internal/telemetry/telemetry.go +++ b/internal/telemetry/telemetry.go @@ -125,7 +125,7 @@ func Track(ctx context.Context, exec shared.InteractionType, fn func(ctx context err = fn(ctx, runEvent) // Populate event with pull request env var (available only after run) - ghPullRequest := os.Getenv("GH_PULL_REQUEST") + ghPullRequest := reformatPullRequestURL(os.Getenv("GH_PULL_REQUEST")) if ghPullRequest != "" { runEvent.GhPullRequest = &ghPullRequest @@ -153,3 +153,9 @@ func Track(ctx context.Context, exec shared.InteractionType, fn func(ctx context return err } + +// Reformat from https://api.github.com/repos/.../.../pulls/... to https://github.com/.../.../pull/... +func reformatPullRequestURL(url string) string { + url = strings.Replace(url, "https://api.github.com/repos/", "https://github.com/", 1) + return strings.Replace(url, "/pulls/", "/pull/", 1) +}