-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get commiter email dynamically from github application for renovate n…
…udging PRs STONEBLD-3194 Signed-off-by: Robert Cerven <[email protected]>
- Loading branch information
Showing
7 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,7 +108,7 @@ var _ = Describe("Component nudge controller", func() { | |
Token: "some_token", | ||
ID: 1, | ||
Repositories: []*gitgithub.Repository{{Name: &repo_name, FullName: &repo_fullname, DefaultBranch: &repo_defaultbranch}}, | ||
}, "slug", nil | ||
}, TestGitHubAppName, nil | ||
} | ||
}) | ||
|
||
|
@@ -495,6 +495,10 @@ var _ = Describe("Component nudge controller", func() { | |
RenovateConfigMapPlatformAutomergeKey: "false", | ||
RenovateConfigMapIgnoreTestsKey: "true", | ||
} | ||
gitHubAppUsername := fmt.Sprintf("%s[bot]", TestGitHubAppName) | ||
gitHubAppGitAuthor := fmt.Sprintf("%s <%d+%[email protected]>", TestGitHubAppName, TestGitHubAppId, gitHubAppUsername) | ||
gitHubAppSignedOff := fmt.Sprintf("Signed-off-by: %s", gitHubAppGitAuthor) | ||
gitHubAppUsed := 0 | ||
assertRenovateConfiMap(nil, nil, customConfigMapData, imageBuiltFrom) | ||
|
||
renovateConfigMaps := getRenovateConfigMapList() | ||
|
@@ -514,10 +518,16 @@ var _ = Describe("Component nudge controller", func() { | |
Expect(strings.Contains(renovateConfigObj.PackageRules[1].CommitBody, commitBodyValue)).Should(BeTrue()) | ||
Expect(renovateConfigObj.CustomManagers[0].FileMatch).Should(Equal(fileMatchValue)) | ||
Expect(strings.HasSuffix(key, customConfigType)) | ||
if renovateConfigObj.Username == gitHubAppUsername { | ||
gitHubAppUsed++ | ||
Expect(renovateConfigObj.GitAuthor).Should(Equal(gitHubAppGitAuthor)) | ||
Expect(strings.Contains(renovateConfigObj.PackageRules[1].CommitBody, gitHubAppSignedOff)).Should(BeTrue()) | ||
} | ||
} | ||
break | ||
} | ||
} | ||
Expect(gitHubAppUsed).Should(Equal(2)) | ||
}) | ||
|
||
It("Test build performs nudge on success, only component renovate config provided", func() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,6 +259,8 @@ func (u ComponentDependenciesUpdater) GetUpdateTargetsGithubApp(ctx context.Cont | |
// Match installed repositories with Components and get custom branch if defined | ||
targetsToUpdate := []updateTarget{} | ||
var slug string | ||
var appBotName string | ||
var appBotId int64 | ||
for _, comp := range componentList { | ||
component := comp | ||
if component.Spec.Source.GitSource == nil { | ||
|
@@ -287,6 +289,27 @@ func (u ComponentDependenciesUpdater) GetUpdateTargetsGithubApp(ctx context.Cont | |
continue | ||
} | ||
|
||
if appBotId == 0 { | ||
pacConfig := map[string][]byte{PipelinesAsCodeGithubPrivateKey: []byte(privateKey), PipelinesAsCodeGithubAppIdKey: []byte(githubAppIdStr)} | ||
gitClient, err := gitproviderfactory.CreateGitClient(gitproviderfactory.GitClientConfig{ | ||
PacSecretData: pacConfig, | ||
GitProvider: gitProvider, | ||
RepoUrl: url, | ||
IsAppInstallationExpected: true, | ||
}) | ||
if err != nil { | ||
log.Error(err, "error create git client for component", "ComponentName", component.Name, "RepoUrl", component.Spec.Source.GitSource.URL) | ||
continue | ||
} | ||
appBotName = fmt.Sprintf("%s[bot]", slug) | ||
botID, err := gitClient.GetAppUserID(appBotName) | ||
if err != nil { | ||
log.Error(err, "Failed to get application user info", "userName", appBotName) | ||
continue | ||
} | ||
appBotId = botID | ||
} | ||
|
||
branch := gitSource.Revision | ||
if branch == "" { | ||
branch = git.InternalDefaultBranch | ||
|
@@ -320,8 +343,8 @@ func (u ComponentDependenciesUpdater) GetUpdateTargetsGithubApp(ctx context.Cont | |
ComponentName: component.Name, | ||
ComponentCustomRenovateOptions: customRenovateOptions, | ||
GitProvider: gitProvider, | ||
Username: fmt.Sprintf("%s[bot]", slug), | ||
GitAuthor: fmt.Sprintf("%s <126015336+%s[bot]@users.noreply.github.com>", slug, slug), | ||
Username: appBotName, | ||
GitAuthor: fmt.Sprintf("%s <%d+%[email protected]>", slug, appBotId, appBotName), | ||
Token: githubAppInstallation.Token, | ||
Endpoint: git.BuildAPIEndpoint("github").APIEndpoint("github.com"), | ||
Repositories: repositories, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters