Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

refactor: Remove redundant local vars in examples #3303

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions example/basicauth/main.go
Original file line number Diff line number Diff line change
@@ -31,12 +31,11 @@
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()))

Check warning on line 34 in example/basicauth/main.go

Codecov / codecov/patch

example/basicauth/main.go#L34

Added line #L34 was not covered by tests

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

Check warning on line 38 in example/basicauth/main.go

Codecov / codecov/patch

example/basicauth/main.go#L38

Added line #L38 was not covered by tests
}

client := github.NewClient(tp.Client())
3 changes: 1 addition & 2 deletions example/codespaces/newreposecretwithxcrypto/main.go
Original file line number Diff line number Diff line change
@@ -147,8 +147,7 @@

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)

Check warning on line 150 in example/codespaces/newreposecretwithxcrypto/main.go

Codecov / codecov/patch

example/codespaces/newreposecretwithxcrypto/main.go#L150

Added line #L150 was not covered by tests
if err != nil {
return nil, fmt.Errorf("box.SealAnonymous failed with error %w", err)
}
3 changes: 1 addition & 2 deletions example/codespaces/newusersecretwithxcrypto/main.go
Original file line number Diff line number Diff line change
@@ -154,8 +154,7 @@

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)

Check warning on line 157 in example/codespaces/newusersecretwithxcrypto/main.go

Codecov / codecov/patch

example/codespaces/newusersecretwithxcrypto/main.go#L157

Added line #L157 was not covered by tests
if err != nil {
return nil, fmt.Errorf("box.SealAnonymous failed with error %w", err)
}
3 changes: 1 addition & 2 deletions example/newreposecretwithlibsodium/main.go
Original file line number Diff line number Diff line change
@@ -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")
}
3 changes: 1 addition & 2 deletions example/newreposecretwithxcrypto/main.go
Original file line number Diff line number Diff line change
@@ -147,8 +147,7 @@

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)

Check warning on line 150 in example/newreposecretwithxcrypto/main.go

Codecov / codecov/patch

example/newreposecretwithxcrypto/main.go#L150

Added line #L150 was not covered by tests
if err != nil {
return nil, fmt.Errorf("box.SealAnonymous failed with error %w", err)
}
5 changes: 2 additions & 3 deletions example/tagprotection/main.go
Original file line number Diff line number Diff line change
@@ -38,12 +38,11 @@
pattern = strings.TrimSpace(pattern)

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

Check warning on line 41 in example/tagprotection/main.go

Codecov / codecov/patch

example/tagprotection/main.go#L41

Added line #L41 was not covered by tests
println()
token := string(byteToken)

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

Check warning on line 45 in example/tagprotection/main.go

Codecov / codecov/patch

example/tagprotection/main.go#L45

Added line #L45 was not covered by tests

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

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

Check warning on line 24 in example/tokenauth/main.go

Codecov / codecov/patch

example/tokenauth/main.go#L24

Added line #L24 was not covered by tests
println()
token := string(byteToken)

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

Check warning on line 28 in example/tokenauth/main.go

Codecov / codecov/patch

example/tokenauth/main.go#L28

Added line #L28 was not covered by tests

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