Skip to content

Conversation

Pedja-Djape
Copy link
Contributor

@Pedja-Djape Pedja-Djape commented Jul 24, 2025

This pull request aims to implement the API for social accounts mentioned in Issue-3634

Fixes: #3634.

@Pedja-Djape Pedja-Djape marked this pull request as draft July 24, 2025 21:24
@Pedja-Djape Pedja-Djape changed the title Issue-3634: Api For Social Accounts with example Issue-3634: Api For Social Accounts Jul 24, 2025
@gmlewis gmlewis changed the title Issue-3634: Api For Social Accounts Add Social Accounts API Jul 25, 2025
Copy link

codecov bot commented Jul 25, 2025

Codecov Report

❌ Patch coverage is 88.23529% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.24%. Comparing base (d1d6f45) to head (f3b7477).
⚠️ Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
github/users_social_accounts.go 88.23% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3647      +/-   ##
==========================================
- Coverage   91.25%   91.24%   -0.01%     
==========================================
  Files         184      185       +1     
  Lines       16311    16362      +51     
==========================================
+ Hits        14884    14929      +45     
- Misses       1245     1249       +4     
- Partials      182      184       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @Pedja-Djape.
I realize this is in Draft mode, but wanted to give you some guidance before you finish the PR by writing unit tests.

@gmlewis
Copy link
Collaborator

gmlewis commented Jul 28, 2025

Please switch this from "Draft" to "Ready for review" when you are ready, @Pedja-Djape. Thank you!

@Pedja-Djape Pedja-Djape marked this pull request as ready for review July 28, 2025 13:39
@Pedja-Djape
Copy link
Contributor Author

Please switch this from "Draft" to "Ready for review" when you are ready, @Pedja-Djape. Thank you!

Done! Thank you for all the help :)

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Jul 28, 2025
accounts, err := fetchSocialAccounts(username)
if err != nil {
log.Fatalf("Error: %v\n", err)
return
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can delete this line. The nice thing about log.Fatalf is that it immediately kills the program, so the return is not necessary.

Also, please be sure to run gofmt on this file after you edit it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't know about that log.Fatalf behavior, nice. Thanks for the heads up

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest moving this example to examples_test.go, since it looks quite straightforward:

func ExampleUsersService_ListUserSocialAccounts() {
	client := github.NewClient(nil)
	users, _, err := client.Users.ListUserSocialAccounts(context.Background(), username, &github.ListOptions{})
	if err != nil {
		log.Fatalf("Failed to list user social accounts: %v", err)
	}
	// ...
}

See

func ExampleUsersService_ListAll() {
client := github.NewClient(nil)
opts := &github.UserListOptions{}
for {
ctx := context.Background()
users, _, err := client.Users.ListAll(ctx, opts)
if err != nil {
log.Fatalf("error listing users: %v", err)
}
if len(users) == 0 {
break
}
opts.Since = *users[len(users)-1].ID
// Process users...
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @alexandear thanks for the review. Just want to clarify something before making changes: Are you saying that I should add the test in the examples_test.go file and remove this file? Or add the test in examples_test.go file and keep this file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should add the test in the examples_test.go file and remove this file

This is what I mean.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome thanks!

// GitHub API docs: https://docs.github.com/rest/users/social-accounts#add-social-accounts-for-the-authenticated-user
//
//meta:operation POST /user/social_accounts
func (s *UsersService) AddSocialAccounts(ctx context.Context, accountURLsToAdd []string) ([]*SocialAccount, *Response, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's simplify naming:

Suggested change
func (s *UsersService) AddSocialAccounts(ctx context.Context, accountURLsToAdd []string) ([]*SocialAccount, *Response, error) {
func (s *UsersService) AddSocialAccounts(ctx context.Context, accountURLs []string) ([]*SocialAccount, *Response, error) {

return nil, nil, err
}

var addedAccounts []*SocialAccount
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's simplify:

Suggested change
var addedAccounts []*SocialAccount
var accounts []*SocialAccount

// GitHub API docs: https://docs.github.com/rest/users/social-accounts#delete-social-accounts-for-the-authenticated-user
//
//meta:operation DELETE /user/social_accounts
func (s *UsersService) DeleteSocialAccounts(ctx context.Context, accountsToDelete []string) (*Response, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with CreateSocialAccounts:

Suggested change
func (s *UsersService) DeleteSocialAccounts(ctx context.Context, accountsToDelete []string) (*Response, error) {
func (s *UsersService) DeleteSocialAccounts(ctx context.Context, accountURLs []string) (*Response, error) {

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @Pedja-Djape!
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.

@gmlewis
Copy link
Collaborator

gmlewis commented Jul 29, 2025

Whups, sorry, it looks like there are some linter errors that need addressing first. Please take a look at these and push the necessary changes, @Pedja-Djape.

@Pedja-Djape
Copy link
Contributor Author

Pedja-Djape commented Jul 29, 2025

Whups, sorry, it looks like there are some linter errors that need addressing first. Please take a look at these and push the necessary changes, @Pedja-Djape.

Hey @gmlewis it seems like the lint job isn't failing because of lint errors but rather due to a 429 error here:

validating openapi_operations.yaml
unexpected status code: 429 Too Many Requests
failed validating openapi_operations.yaml

EDIT: NVM!

@Pedja-Djape
Copy link
Contributor Author

Whups, sorry, it looks like there are some linter errors that need addressing first. Please take a look at these and push the necessary changes, @Pedja-Djape.

Hey @gmlewis I noticed the lint job isn't failing becuse of lint issues but rather due to a

Whups, sorry, it looks like there are some linter errors that need addressing first. Please take a look at these and push the necessary changes, @Pedja-Djape.

Hey @gmlewis it seems like the lint job isn't failing because of lint errors but rather due to a 429 error here:

validating openapi_operations.yaml
unexpected status code: 429 Too Many Requests
failed validating openapi_operations.yaml

EDIT: NVM!

Actually @gmlewis I confirmed my openapi_operations.yaml is up-to-date with what's in prod ... I don't see a way for me to re-run the job, can we rerun this somehow? I ran all the scripts locally and see no issues.

@gmlewis
Copy link
Collaborator

gmlewis commented Jul 29, 2025

Thank you, @Pedja-Djape and @alexandear!
Merging.

@gmlewis gmlewis removed the NeedsReview PR is awaiting a review before merging. label Jul 29, 2025
@gmlewis gmlewis merged commit d93435a into google:master Jul 29, 2025
5 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: API for social accounts
3 participants