Skip to content

Commit

Permalink
goordinator: reduce unnecessary nil-checks when parsing gh events
Browse files Browse the repository at this point in the history
The github event Getter() handle safely nil fields and are returning an empty
value when called on a nil-field.

Reduce the unnecessary nil checks, when multiple Get calls are done on the same
field the nil check is still done, to reduce the number of calls.
(won't really make a difference)
  • Loading branch information
fho committed Jul 9, 2021
1 parent 00c861f commit 45adb38
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions internal/goordinator/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,12 @@ func extractEventInfo(ghEvent interface{}) *Event {
if v, ok := ghEvent.(pushEventRepoGetter); ok {
if repo := v.GetRepo(); repo != nil {
result.Repository = repo.GetName()

if owner := repo.GetOwner(); owner != nil {
result.RepositoryOwner = owner.GetLogin()
}
result.RepositoryOwner = repo.GetOwner().GetLogin()
}
} else if v, ok := ghEvent.(repoGetter); ok {
if repo := v.GetRepo(); repo != nil {
result.Repository = repo.GetName()

if owner := repo.GetOwner(); owner != nil {
result.RepositoryOwner = owner.GetLogin()
}
result.RepositoryOwner = repo.GetOwner().GetLogin()
}
}

Expand All @@ -114,9 +108,7 @@ func extractEventInfo(ghEvent interface{}) *Event {
result.Branch = head.GetRef()
}

if base := pr.GetBase(); base != nil {
result.BaseBranch = base.GetRef()
}
result.BaseBranch = pr.GetBase().GetRef()
}
}

Expand Down

0 comments on commit 45adb38

Please sign in to comment.