Skip to content

Commit

Permalink
feat: add support for user.signingKey #32
Browse files Browse the repository at this point in the history
  • Loading branch information
ayakovlenko committed May 30, 2024
1 parent dde6614 commit 1b934f4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/zit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/urfave/cli/v2"
)

const AppVersion = "v2.6.1+1"
const AppVersion = "v2.7.0"

func main() {
app := &cli.App{
Expand Down
10 changes: 8 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ type HostConfig struct {

// User TODO
type User struct {
Name string `json:"name" yaml:"name"`
Email string `json:"email" yaml:"email"`
Name string `json:"name" yaml:"name"`
Email string `json:"email" yaml:"email"`
Signing *Signing `json:"sign" yaml:"sign"`
}

type Signing struct {
Key string `json:"key" yaml:"key"`
Format string `json:"format" yaml:"format"`
}

// Override TODO
Expand Down
15 changes: 3 additions & 12 deletions internal/identity/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ func findBestMatch(conf config.HostConfig, repo gitutil.RepoInfo) *config.User {
var user *config.User

if conf.Default != nil {
user = &config.User{
Name: conf.Default.Name,
Email: conf.Default.Email,
}
user = conf.Default
}

if conf.Overrides == nil {
Expand All @@ -22,18 +19,12 @@ func findBestMatch(conf config.HostConfig, repo gitutil.RepoInfo) *config.User {
for _, override := range conf.Overrides {
if override.Repo != "" {
if override.Owner == repo.Owner && override.Repo == repo.Name {
return &config.User{
Name: override.User.Name,
Email: override.User.Email,
}
return &override.User
}
}

if override.Owner == repo.Owner {
return &config.User{
Name: override.User.Name,
Email: override.User.Email,
}
return &override.User
}
}

Expand Down
15 changes: 15 additions & 0 deletions internal/identity/set_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,24 @@ defined in the configuration file:
if err := gitutil.SetConfig(gitClient, "--local", "user.name", cred.Name); err != nil {
return err
}

if err := gitutil.SetConfig(gitClient, "--local", "user.email", cred.Email); err != nil {
return err
}

if sign := cred.Signing; sign != nil {
if err := gitutil.SetConfig(gitClient, "--local", "commit.gpgsign", "true"); err != nil {
return err
}

if err := gitutil.SetConfig(gitClient, "--local", "user.signingKey", sign.Key); err != nil {
return err
}

if err := gitutil.SetConfig(gitClient, "--local", "gpg.format", sign.Format); err != nil {
return err
}
}
}

if dryRun {
Expand Down

0 comments on commit 1b934f4

Please sign in to comment.