Skip to content

Commit

Permalink
refactor: Remove redundant local vars in examples (#3303)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored Oct 3, 2024
1 parent 54eecb8 commit c0f593d
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 17 deletions.
5 changes: 2 additions & 3 deletions example/basicauth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ func main() {
username, _ := r.ReadString('\n')

fmt.Print("GitHub Password: ")
bytePassword, _ := term.ReadPassword(int(os.Stdin.Fd()))
password := string(bytePassword)
password, _ := term.ReadPassword(int(os.Stdin.Fd()))

tp := github.BasicAuthTransport{
Username: strings.TrimSpace(username),
Password: strings.TrimSpace(password),
Password: strings.TrimSpace(string(password)),
}

client := github.NewClient(tp.Client())
Expand Down
3 changes: 1 addition & 2 deletions example/codespaces/newreposecretwithxcrypto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ func encryptSecretWithPublicKey(publicKey *github.PublicKey, secretName string,

var boxKey [32]byte
copy(boxKey[:], decodedPublicKey)
secretBytes := []byte(secretValue)
encryptedBytes, err := box.SealAnonymous([]byte{}, secretBytes, &boxKey, crypto_rand.Reader)
encryptedBytes, err := box.SealAnonymous([]byte{}, []byte(secretValue), &boxKey, crypto_rand.Reader)
if err != nil {
return nil, fmt.Errorf("box.SealAnonymous failed with error %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions example/codespaces/newusersecretwithxcrypto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ func encryptSecretWithPublicKey(publicKey *github.PublicKey, secretName string,

var boxKey [32]byte
copy(boxKey[:], decodedPublicKey)
secretBytes := []byte(secretValue)
encryptedBytes, err := box.SealAnonymous([]byte{}, secretBytes, &boxKey, crypto_rand.Reader)
encryptedBytes, err := box.SealAnonymous([]byte{}, []byte(secretValue), &boxKey, crypto_rand.Reader)
if err != nil {
return nil, fmt.Errorf("box.SealAnonymous failed with error %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions example/newreposecretwithlibsodium/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ func encryptSecretWithPublicKey(publicKey *github.PublicKey, secretName string,
return nil, fmt.Errorf("base64.StdEncoding.DecodeString was unable to decode public key: %v", err)
}

secretBytes := []byte(secretValue)
encryptedBytes, exit := sodium.CryptoBoxSeal(secretBytes, decodedPublicKey)
encryptedBytes, exit := sodium.CryptoBoxSeal([]byte(secretValue), decodedPublicKey)
if exit != 0 {
return nil, errors.New("sodium.CryptoBoxSeal exited with non zero exit code")
}
Expand Down
3 changes: 1 addition & 2 deletions example/newreposecretwithxcrypto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ func encryptSecretWithPublicKey(publicKey *github.PublicKey, secretName string,

var boxKey [32]byte
copy(boxKey[:], decodedPublicKey)
secretBytes := []byte(secretValue)
encryptedBytes, err := box.SealAnonymous([]byte{}, secretBytes, &boxKey, crypto_rand.Reader)
encryptedBytes, err := box.SealAnonymous([]byte{}, []byte(secretValue), &boxKey, crypto_rand.Reader)
if err != nil {
return nil, fmt.Errorf("box.SealAnonymous failed with error %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions example/tagprotection/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ func main() {
pattern = strings.TrimSpace(pattern)

fmt.Print("GitHub Token: ")
byteToken, _ := term.ReadPassword(int(os.Stdin.Fd()))
token, _ := term.ReadPassword(int(os.Stdin.Fd()))
println()
token := string(byteToken)

ctx := context.Background()
client := github.NewClient(nil).WithAuthToken(token)
client := github.NewClient(nil).WithAuthToken(string(token))

// create new tag protection
if pattern != "" {
Expand Down
5 changes: 2 additions & 3 deletions example/tokenauth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ import (

func main() {
fmt.Print("GitHub Token: ")
byteToken, _ := term.ReadPassword(int(os.Stdin.Fd()))
token, _ := term.ReadPassword(int(os.Stdin.Fd()))
println()
token := string(byteToken)

ctx := context.Background()
client := github.NewClient(nil).WithAuthToken(token)
client := github.NewClient(nil).WithAuthToken(string(token))

user, resp, err := client.Users.Get(ctx, "")
if err != nil {
Expand Down

0 comments on commit c0f593d

Please sign in to comment.