Skip to content

Commit

Permalink
fix(GoogleCloudPlatform#189): Use REPO_FULL_NAME default substitution…
Browse files Browse the repository at this point in the history
  • Loading branch information
VuKrampHub committed Feb 26, 2024
1 parent 1a6a48d commit 64b91e2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions githubissues/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion githubissues/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 64b91e2

Please sign in to comment.