From 051821ea5bd25f82aaa9fe31a8fc64be07a41a92 Mon Sep 17 00:00:00 2001 From: Tony Worthit <868644+TonyLovesDevOps@users.noreply.github.com> Date: Tue, 24 Sep 2024 08:41:28 -0600 Subject: [PATCH 1/2] GitHub usernames are case-insensitive but case preserving. This fixes the issue where setting GITHUB_USER to the same characters in a different case, causes the spurious error: "the specified owner doesn't match the identity associated with the given token" Signed-off-by: Tony Worthit <868644+TonyLovesDevOps@users.noreply.github.com> --- github/client_repositories_user.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/github/client_repositories_user.go b/github/client_repositories_user.go index be30fd42..5486e288 100644 --- a/github/client_repositories_user.go +++ b/github/client_repositories_user.go @@ -20,6 +20,7 @@ import ( "context" "errors" "fmt" + "strings" "github.com/fluxcd/go-git-providers/gitprovider" ) @@ -108,7 +109,8 @@ func (c *UserRepositoriesClient) Create(ctx context.Context, return nil, fmt.Errorf("unable to get owner from API") } - if ref.GetIdentity() != idRef.GetIdentity() { + // GitHub usernames are case insensitive, so compare them with https://pkg.go.dev/strings#EqualFold + if strings.EqualFold(ref.GetIdentity(), idRef.GetIdentity()) { return nil, gitprovider.NewErrIncorrectUser(ref.GetIdentity()) } From c332235373f6699bab3e021329a1c6962d74c7ef Mon Sep 17 00:00:00 2001 From: Tony DevOps <868644+TonyLovesDevOps@users.noreply.github.com> Date: Mon, 25 Nov 2024 05:45:36 -0700 Subject: [PATCH 2/2] Fix username comparison logic. Co-authored-by: souleb Signed-off-by: Tony DevOps <868644+TonyLovesDevOps@users.noreply.github.com> --- github/client_repositories_user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/client_repositories_user.go b/github/client_repositories_user.go index 5486e288..a3793b45 100644 --- a/github/client_repositories_user.go +++ b/github/client_repositories_user.go @@ -110,7 +110,7 @@ func (c *UserRepositoriesClient) Create(ctx context.Context, } // GitHub usernames are case insensitive, so compare them with https://pkg.go.dev/strings#EqualFold - if strings.EqualFold(ref.GetIdentity(), idRef.GetIdentity()) { + if !strings.EqualFold(ref.GetIdentity(), idRef.GetIdentity()) { return nil, gitprovider.NewErrIncorrectUser(ref.GetIdentity()) }