From b46fb75c73bf9d09946f386cd88efe1ea1380ada Mon Sep 17 00:00:00 2001 From: Richard Gomez <32133502+rgmz@users.noreply.github.com> Date: Wed, 18 Oct 2023 09:53:58 -0400 Subject: [PATCH] feat(git): only generate line numbers > 0 (#1898) --- pkg/giturl/giturl.go | 5 +++++ pkg/giturl/giturl_test.go | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/pkg/giturl/giturl.go b/pkg/giturl/giturl.go index bf7adee0..737167da 100644 --- a/pkg/giturl/giturl.go +++ b/pkg/giturl/giturl.go @@ -158,6 +158,11 @@ func UpdateLinkLineNumber(ctx context.Context, link string, newLine int64) strin return link } + if newLine <= 0 { + // Don't change the link if the line number is 0. + return link + } + switch determineProvider(link) { case providerBitbucket: // For Bitbucket, it doesn't support line links (based on the GenerateLink function). diff --git a/pkg/giturl/giturl_test.go b/pkg/giturl/giturl_test.go index 1ccc2fd7..59bb0143 100644 --- a/pkg/giturl/giturl_test.go +++ b/pkg/giturl/giturl_test.go @@ -251,6 +251,14 @@ func TestUpdateLinkLineNumber(t *testing.T) { }, want: "https://onprem.customdomain.com/org/repo/commit/xyz123#L50", }, + { + name: "Don't include line when it's 0", + args: args{ + link: "https://github.com/coinbase/cbpay-js/issues/181", + newLine: int64(0), + }, + want: "https://github.com/coinbase/cbpay-js/issues/181", + }, { name: "Invalid link", args: args{