← 输入框|github.com|刷新
Skip to content

define struct types instead of using anonymous structs - #1900

Merged
gmlewis merged 11 commits into
google:masterfrom
simplesurance:edit_change_defined_structs
Jul 8, 2021
Merged

gmlewis merged 11 commits into
google:masterfrom
simplesurance:edit_change_defined_structs

Conversation

@fho

@fho fho commented Jun 18, 2021 •

Copy link
Copy Markdown

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

codecov Bot commented Jun 18, 2021 •

Copy link
Copy Markdown

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.

@gmlewis gmlewis left a comment

Copy link
Copy Markdown
Collaborator

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

?

Comment thread github/event_types.go Resolved
Comment thread github/event_types.go 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

fho commented Jun 18, 2021

Copy link
Copy Markdown
Author

@gmlewis I also replaced the other anonymous struct types.

@gmlewis gmlewis left a comment

Copy link
Copy Markdown
Collaborator

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

gmlewis commented Jun 18, 2021

Copy link
Copy Markdown
Collaborator

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

@fho

fho commented Jun 18, 2021

Copy link
Copy Markdown
Author

@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

gmlewis commented Jun 18, 2021

Copy link
Copy Markdown
Collaborator

@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

fho commented Jun 18, 2021 •

Copy link
Copy Markdown
Author

@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

fho commented Jun 29, 2021 •

Copy link
Copy Markdown
Author

@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

gmlewis commented Jun 29, 2021

Copy link
Copy Markdown
Collaborator

Friendly ping, @wesleimp

@sagar23sj

Copy link
Copy Markdown
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

fho commented Jul 8, 2021 •

Copy link
Copy Markdown
Author

@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.

Fabian Holler added 4 commits July 8, 2021 10:48
…ucts

Fix wrong struct name in godoc comment
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

fho commented Jul 8, 2021

Copy link
Copy Markdown
Author

done

@gmlewis gmlewis left a comment

Copy link
Copy Markdown
Collaborator

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.

@Parker77 Parker77 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM.

@gmlewis

gmlewis commented Jul 8, 2021

Copy link
Copy Markdown
Collaborator

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

@fho

fho commented Jul 8, 2021

Copy link
Copy Markdown
Author

@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
jlaportebot added a commit to jlaportebot/go-github that referenced this pull request Jun 28, 2026
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