From afe86c0f4642415760616f9f9fedf68d44ce8c94 Mon Sep 17 00:00:00 2001 From: Greg <2653109+glinton@users.noreply.github.com> Date: Mon, 22 Jul 2019 17:30:53 -0600 Subject: [PATCH] Avoid panic in github input (#6152) --- plugins/inputs/github/github.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/inputs/github/github.go b/plugins/inputs/github/github.go index ff497e55b..4cba9b2d2 100644 --- a/plugins/inputs/github/github.go +++ b/plugins/inputs/github/github.go @@ -148,9 +148,9 @@ func splitRepositoryName(repositoryName string) (string, string, error) { return splits[0], splits[1], nil } -func getLicense(repositoryInfo *github.Repository) string { - if repositoryInfo.GetLicense() != nil { - return *repositoryInfo.License.Name +func getLicense(rI *github.Repository) string { + if licenseName := rI.GetLicense().GetName(); licenseName != "" { + return licenseName } return "None" @@ -158,19 +158,19 @@ func getLicense(repositoryInfo *github.Repository) string { func getTags(repositoryInfo *github.Repository) map[string]string { return map[string]string{ - "owner": *repositoryInfo.Owner.Login, - "name": *repositoryInfo.Name, - "language": *repositoryInfo.Language, + "owner": repositoryInfo.GetOwner().GetLogin(), + "name": repositoryInfo.GetName(), + "language": repositoryInfo.GetLanguage(), "license": getLicense(repositoryInfo), } } func getFields(repositoryInfo *github.Repository) map[string]interface{} { return map[string]interface{}{ - "stars": *repositoryInfo.StargazersCount, - "forks": *repositoryInfo.ForksCount, - "open_issues": *repositoryInfo.OpenIssuesCount, - "size": *repositoryInfo.Size, + "stars": repositoryInfo.GetStargazersCount(), + "forks": repositoryInfo.GetForksCount(), + "open_issues": repositoryInfo.GetOpenIssuesCount(), + "size": repositoryInfo.GetSize(), } }