From 9910872ee408af2781f4b645fb3c46ebbdaffbeb Mon Sep 17 00:00:00 2001 From: Vu Le Date: Mon, 26 Feb 2024 12:53:29 +0700 Subject: [PATCH] fix(#189): Use REPO_FULL_NAME default substitution that contains both user/org and repo name Doc: https://cloud.google.com/build/docs/configuring-builds/substitute-variable-values#using_default_substitutions --- githubissues/main.go | 11 ++++------- githubissues/main_test.go | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/githubissues/main.go b/githubissues/main.go index 40d7dab5..20928dc5 100644 --- a/githubissues/main.go +++ b/githubissues/main.go @@ -151,13 +151,10 @@ func (g *githubissuesNotifier) SendNotification(ctx context.Context, build *cbpb func GetGithubRepo(configGithubRepo string, build *cbpb.Build) string { if build.Substitutions != nil { - if repo, ok := build.Substitutions["REPO_NAME"]; ok { - // split and only take repo name as last two parts - // e.g. "github.com/GoogleCloudPlatform/cloud-build-notifiers" -> "GoogleCloudPlatform/cloud-build-notifiers" - parts := strings.Split(repo, "/") - if len(parts) > 2 { - return strings.Join(parts[len(parts)-2:], "/") - } + if repo, ok := build.Substitutions["REPO_FULL_NAME"]; ok { + // return repo full name if it's available + // e.g. "GoogleCloudPlatform/cloud-build-notifiers" + return repo } } return configGithubRepo diff --git a/githubissues/main_test.go b/githubissues/main_test.go index 21e3c7cb..420b5bfa 100644 --- a/githubissues/main_test.go +++ b/githubissues/main_test.go @@ -165,7 +165,7 @@ func TestConfigs(t *testing.T) { func TestGetGithubRepo(t *testing.T) { // test GetGithubRepo method build := &cbpb.Build{ - Substitutions: map[string]string{"REPO_NAME": "github.com/somename/somerepo"}, + Substitutions: map[string]string{"REPO_FULL_NAME": "somename/somerepo"}, } if got, want := GetGithubRepo("config/repo", build), "somename/somerepo"; got != want { t.Errorf("got %q, want %q", got, want)