Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

define struct types instead of using anonymous structs #1900

Merged
merged 11 commits into from
Jul 8, 2021
Merged

define struct types instead of using anonymous structs #1900

merged 11 commits into from
Jul 8, 2021

Conversation

fho
Copy link
Contributor

@fho fho commented Jun 18, 2021

Some fields were defined inline as anonymous structs.
This made it tedious to use these structs in testcases, because
the anonymous type needed to be redefined (incl the exact same JSON
tags) whenever it was assigned.

Using anonymous struct also does not scale well when the struct changes.
For example when a field is added to an anonymous struct, every place
where the anonymous struct is assigned must also be changed.

Another advantage of using regular types is that accessors will be
generated automatically and can be used instead of having to manually
check for nil values when accessing the struct fields.

Define the types as regular structs instead.


PR Status: PR is finished but I noticed that my company hasn't signed the CA yet. As soon as it is done, I'll transition the PR to "ready for review".

The types of the fields of the EditChange struct were defined inline as
anonymous structs.
This made it tedious to use the EditChange struct in testcases, because
the anonymous type needed to be redefined (incl the exact same JSON
tags) whenever it was assigned. The TestEdit* testcases are good example
for it.

Using anonymous struct also does not scale well when the struct changes.
For example when a field is added to an anonymous struct, every place
where the anonymous struct is assigned must also be changed.

Another advantage of using regular types is that accessors  will be
generated automatically and can be used instead of having to manually
check for nil values when accessing the struct fields.

Define the types as regular structs in event_types.go instead.
@google-cla google-cla bot added the cla: yes Indication that the PR author has signed a Google Contributor License Agreement. label Jun 18, 2021
@codecov
Copy link

codecov bot commented Jun 18, 2021

Codecov Report

Merging #1900 (684b1c9) into master (75644ea) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1900   +/-   ##
=======================================
  Coverage   97.65%   97.65%           
=======================================
  Files         105      105           
  Lines        6786     6786           
=======================================
  Hits         6627     6627           
  Misses         86       86           
  Partials       73       73           
Impacted Files Coverage Δ
github/activity.go 100.00% <ø> (ø)
github/event_types.go 100.00% <ø> (ø)
github/github.go 97.01% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 75644ea...684b1c9. Read the comment docs.

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.

While you are here, do you want to do the same thing for:

  • ProjectChange
  • ProjectCardChange
  • ProjectColumnChange
  • TeamChange
  • RepositoryVulnerabilityAlertEvent

?

github/event_types.go Outdated Show resolved Hide resolved
github/event_types.go Outdated Show resolved Hide resolved
Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com>
@gmlewis gmlewis added the Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s). label Jun 18, 2021
@fho fho changed the title editChange event: define struct types instead of using anonymous structs define struct types instead of using anonymous structs Jun 18, 2021
@fho
Copy link
Contributor Author

fho commented Jun 18, 2021

@gmlewis I also replaced the other anonymous struct types.

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, @fho !
LGTM.

Awaiting second LGTM before merging.

@gmlewis
Copy link
Collaborator

gmlewis commented Jun 18, 2021

Also, @fho - could you please remove the "Draft" setting when you are ready?

@fho
Copy link
Contributor Author

fho commented Jun 18, 2021

@gmlewis I'll remove the draft status as soon as my employer signed the CA, probably beginning of next week. I only noticed that it was missing after I created it. :-)

@gmlewis
Copy link
Collaborator

gmlewis commented Jun 18, 2021

@gmlewis I'll remove the draft status as soon as my employer signed the CA, probably beginning of next week. I only noticed that it was missing after I created it. :-)

Interesting - the googlebot marked the PR as having passed the CLA test. OK, sounds good.

@fho
Copy link
Contributor Author

fho commented Jun 18, 2021

@gmlewis I'll remove the draft status as soon as my employer signed the CA, probably beginning of next week. I only noticed that it was missing after I created it. :-)

Interesting - the googlebot marked the PR as having passed the CLA test. OK, sounds good.

It's because I signed the CA for myself already in the past.

@gmlewis gmlewis requested a review from wesleimp June 24, 2021 00:10
@fho
Copy link
Contributor Author

fho commented Jun 29, 2021

@gmlewis my employer signed the CLA now also.
I can't see it on https://cla.developers.google.com/clas for my account but I'm in the contributors google-group of the CLA.

Update: now it shows up, yesterday was still one signature missing

@fho fho marked this pull request as ready for review June 29, 2021 07:20
@gmlewis
Copy link
Collaborator

gmlewis commented Jun 29, 2021

Friendly ping, @wesleimp

@sagar23sj
Copy link
Contributor

If we are expecting to replace all anonymous structs with defined struct types, then I guess a few are still missing in this PR.
I am listing them below :

  1. File: github.go / ErrorResponse
  2. File: activity.go / Feeds

@gmlewis

@fho
Copy link
Contributor Author

fho commented Jul 8, 2021

@sagar23sj thanks, I'll update the PR and also replace those anonymous structs.

It was not my initial intent of the PR to replace all anonymous structs but it makes sense to have a consistent solution.

fho added 4 commits July 8, 2021 10:48
This fixes the following golint warning:
	update-urls/main.go:658:1: receiver name ep should be consistent
				   with previous receiver name e for
				   Endpoint
@fho
Copy link
Contributor Author

fho commented Jul 8, 2021

done

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, @fho !
LGTM.

Awaiting second LGTM before merging.

Copy link

@Parker77 Parker77 left a comment

Choose a reason for hiding this comment

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

LGTM.

@gmlewis
Copy link
Collaborator

gmlewis commented Jul 8, 2021

@fho - would you like to resolve the merge conflicts, or would you like me to do that? I'm fine either way.

@fho
Copy link
Contributor Author

fho commented Jul 8, 2021

@gmlewis also both fine with me, feel free to do changes :-)
Otherwise I can solve the conflict tomorrow

gmlewis added a commit that referenced this pull request Jul 8, 2021
@gmlewis gmlewis merged commit 684b1c9 into google:master Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s). cla: yes Indication that the PR author has signed a Google Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants