Skip to content

Commit

Permalink
Add networks, subscribers, and watchers to github input (#6161)
Browse files Browse the repository at this point in the history
  • Loading branch information
glinton authored and danielnelson committed Jul 23, 2019
1 parent eb0f493 commit 4e59d51
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
7 changes: 5 additions & 2 deletions plugins/inputs/github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ alternative method for collecting repository information.
- language - The primary language of the repository
- license - The license set for the repository
- fields:
- stars (int)
- forks (int)
- open_issues (int)
- networks (int)
- size (int)
- subscribers (int)
- stars (int)
- watchers (int)

When the [internal][] input is enabled:

Expand All @@ -46,7 +49,7 @@ When the [internal][] input is enabled:
### Example Output

```
github,full_name=influxdata/telegraf,name=telegraf,owner=influxdata,language=Go,license=MIT\ License stars=6401i,forks=2421i,open_issues=722i,size=22611i 1552651811000000000
github_repository,language=Go,license=MIT\ License,name=telegraf,owner=influxdata forks=2679i,networks=2679i,open_issues=794i,size=23263i,stars=7091i,subscribers=316i,watchers=7091i 1563901372000000000
internal_github,access_token=Unauthenticated rate_limit_remaining=59i,rate_limit_limit=60i,rate_limit_blocks=0i 1552653551000000000
```

Expand Down
3 changes: 3 additions & 0 deletions plugins/inputs/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ func getTags(repositoryInfo *github.Repository) map[string]string {
func getFields(repositoryInfo *github.Repository) map[string]interface{} {
return map[string]interface{}{
"stars": repositoryInfo.GetStargazersCount(),
"subscribers": repositoryInfo.GetSubscribersCount(),
"watchers": repositoryInfo.GetWatchersCount(),
"networks": repositoryInfo.GetNetworkCount(),
"forks": repositoryInfo.GetForksCount(),
"open_issues": repositoryInfo.GetOpenIssuesCount(),
"size": repositoryInfo.GetSize(),
Expand Down
16 changes: 12 additions & 4 deletions plugins/inputs/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,17 @@ func TestGetFields(t *testing.T) {
forks := 2
openIssues := 3
size := 4
subscribers := 5
watchers := 6

repository := gh.Repository{
StargazersCount: &stars,
ForksCount: &forks,
OpenIssuesCount: &openIssues,
Size: &size,
StargazersCount: &stars,
ForksCount: &forks,
OpenIssuesCount: &openIssues,
Size: &size,
NetworkCount: &forks,
SubscribersCount: &subscribers,
WatchersCount: &watchers,
}

getFieldsReturn := getFields(&repository)
Expand All @@ -112,8 +117,11 @@ func TestGetFields(t *testing.T) {

correctFieldReturn["stars"] = 1
correctFieldReturn["forks"] = 2
correctFieldReturn["networks"] = 2
correctFieldReturn["open_issues"] = 3
correctFieldReturn["size"] = 4
correctFieldReturn["subscribers"] = 5
correctFieldReturn["watchers"] = 6

require.Equal(t, true, reflect.DeepEqual(getFieldsReturn, correctFieldReturn))
}

0 comments on commit 4e59d51

Please sign in to comment.