fix(archied): sign connection commits with the connection account (#1815)
This commit is contained in:
2 files changed
+21
-4
No files matched your search
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/domain/org"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
"github.com/samcharles93/archie-core/internal/forge"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/controlplanestore"
|
||||
"github.com/samcharles93/archie-core/internal/worktree"
|
||||
)
|
||||
@@ -106,7 +107,8 @@ func (b *boot) openRepositoryConnection(ctx context.Context, principal access.Pr
|
||||
}
|
||||
}
|
||||
cfg := b.cfgHolder.Get()
|
||||
out.Trees = &worktree.Manager{WorkDir: worktree.OrgWorkDir(cfg.WorkDir, string(principal.Org)), Token: token, AuthUser: username, BaseURL: host, BotUser: cfg.BotUser, BotEmail: cfg.BotEmail, Log: b.log}
|
||||
botUser, botEmail := commitIdentity(cfg, connection.Type, username)
|
||||
out.Trees = &worktree.Manager{WorkDir: worktree.OrgWorkDir(cfg.WorkDir, string(principal.Org)), Token: token, AuthUser: username, BaseURL: host, BotUser: botUser, BotEmail: botEmail, Log: b.log}
|
||||
out.Forge = b.connectionForge(ctx, connection, principal.Org, token)
|
||||
if operation == config.OperationPR {
|
||||
if _, disabled := out.Forge.(*forge.NoopForge); disabled {
|
||||
@@ -115,3 +117,17 @@ func (b *boot) openRepositoryConnection(ctx context.Context, principal access.Pr
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// commitIdentity is the author of commits made through a connection. A
|
||||
// control-plane connection leaves the root bot fields empty, so its account
|
||||
// signs the commits instead of nobody.
|
||||
func commitIdentity(cfg config.Config, forgeType, account string) (string, string) {
|
||||
if cfg.BotUser != "" {
|
||||
return cfg.BotUser, cfg.BotEmail
|
||||
}
|
||||
user := account
|
||||
if user == "" {
|
||||
user = "archie"
|
||||
}
|
||||
return user, configuration.DefaultBotEmail(forgeType, user, "")
|
||||
}
|
||||
@@ -298,7 +298,7 @@ func applyDispatchDefaults(cfg *config.Config) {
|
||||
func applyIdentityDefaults(cfg *config.Config) {
|
||||
if len(cfg.Identities) > 0 {
|
||||
for i := range cfg.Identities {
|
||||
cfg.Identities[i].BotEmail = defaultBotEmail(cfg.Forge.Type, cfg.Identities[i].BotUser, cfg.Identities[i].BotEmail)
|
||||
cfg.Identities[i].BotEmail = DefaultBotEmail(cfg.Forge.Type, cfg.Identities[i].BotUser, cfg.Identities[i].BotEmail)
|
||||
}
|
||||
if len(cfg.Identities) == 1 && cfg.BotUser == "" {
|
||||
cfg.BotUser = cfg.Identities[0].BotUser
|
||||
@@ -307,10 +307,11 @@ func applyIdentityDefaults(cfg *config.Config) {
|
||||
}
|
||||
}
|
||||
}
|
||||
cfg.BotEmail = defaultBotEmail(cfg.Forge.Type, cfg.BotUser, cfg.BotEmail)
|
||||
cfg.BotEmail = DefaultBotEmail(cfg.Forge.Type, cfg.BotUser, cfg.BotEmail)
|
||||
}
|
||||
|
||||
func defaultBotEmail(forgeType, user, email string) string {
|
||||
// DefaultBotEmail is the forge-appropriate commit email for user when email is empty.
|
||||
func DefaultBotEmail(forgeType, user, email string) string {
|
||||
if user == "" || email != "" {
|
||||
return email
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user