1
|
|
|
// Copyright 2018 Fedir RYKHTIK. All rights reserved. |
2
|
|
|
// Use of this source code is governed by the GNU GPL 3.0 |
3
|
|
|
// license that can be found in the LICENSE file. |
4
|
|
|
|
5
|
|
|
package main |
6
|
|
|
|
7
|
|
|
import ( |
8
|
|
|
"fmt" |
9
|
|
|
"sync" |
10
|
|
|
"time" |
11
|
|
|
|
12
|
|
|
"github.com/fedir/ghstat/github" |
13
|
|
|
) |
14
|
|
|
|
15
|
|
|
func repositoryData(rKey string, tmpFolder string, debug bool, dataChan chan Repository, wg *sync.WaitGroup) { |
16
|
|
|
|
17
|
1 |
|
defer wg.Done() |
18
|
|
|
|
19
|
1 |
|
r := new(Repository) |
20
|
|
|
|
21
|
1 |
|
repositoryData := github.GetRepositoryStatistics(rKey, tmpFolder, debug) |
22
|
|
|
|
23
|
1 |
|
r.Name = repositoryData.FullName |
24
|
1 |
|
r.URL = fmt.Sprintf("https://github.com/%s", r.Name) |
25
|
1 |
|
r.MainLanguage = repositoryData.Language |
26
|
1 |
|
r.AllLanguages, r.TotalCodeSize = github.GetRepositoryLanguages(rKey, tmpFolder, debug) |
27
|
1 |
|
r.Description = repositoryData.Description |
28
|
1 |
|
r.CreatedAt = repositoryData.CreatedAt |
29
|
1 |
|
r.Age = int(time.Since(repositoryData.CreatedAt).Seconds() / 86400) |
30
|
1 |
|
r.Watchers = repositoryData.Watchers |
31
|
1 |
|
r.Forks = repositoryData.Forks |
32
|
1 |
|
r.OpenIssues = repositoryData.OpenIssues |
33
|
1 |
|
r.License = "[Custom license]" |
34
|
1 |
|
if repositoryData.License.SPDXID != "" { |
35
|
1 |
|
r.License = repositoryData.License.SPDXID |
36
|
|
|
} |
37
|
1 |
|
r.Author = "[No GitHub account detected]" |
38
|
|
|
|
39
|
1 |
|
r.Author, r.LastCommitDate = github.GetRepositoryCommitsData(rKey, tmpFolder, debug) |
40
|
|
|
|
41
|
1 |
|
r.AuthorsFollowers = 0 |
42
|
1 |
|
r.AuthorLocation = "[Unknown]" |
43
|
1 |
|
if r.Author != "" { |
44
|
1 |
|
r.AuthorsFollowers = github.GetUserFollowers(r.Author, tmpFolder, debug) |
45
|
1 |
|
authorData := github.GetUserData(r.Author, tmpFolder, debug) |
46
|
1 |
|
if authorData.Location != "" { |
47
|
1 |
|
r.AuthorLocation = authorData.Location |
48
|
|
|
} |
49
|
|
|
} else { |
50
|
|
|
r.Author = "[Unknown account]" |
51
|
|
|
} |
52
|
|
|
|
53
|
1 |
|
r.ClosedIssues = 0 |
54
|
1 |
|
if repositoryData.HasIssues { |
55
|
1 |
|
r.ClosedIssues = github.GetRepositoryClosedIssues(rKey, tmpFolder, debug) |
56
|
|
|
} |
57
|
1 |
|
r.TotalIssues = r.OpenIssues + r.ClosedIssues |
58
|
1 |
|
r.Top10ContributorsFollowers, |
59
|
|
|
r.Contributors = github.GetRepositoryContributors(rKey, tmpFolder, debug) |
60
|
1 |
|
r.TotalTags = github.GetRepositoryTagsNumber(rKey, tmpFolder, debug) |
61
|
1 |
|
r.ActiveForkersPercentage = github.GetActiveForkersPercentage(r.Contributors, r.Forks) |
62
|
1 |
|
r.IssueByDay = github.GetIssueByDay(r.ClosedIssues+r.OpenIssues, r.Age) |
63
|
1 |
|
r.ClosedIssuesPercentage = github.GetClosedIssuesPercentage(repositoryData.OpenIssues, int(r.ClosedIssues)) |
64
|
|
|
|
65
|
1 |
|
contributionStatistics := github.GetContributionStatistics(rKey, tmpFolder, debug) |
66
|
1 |
|
r.TotalCommits = contributionStatistics.TotalCommits |
67
|
1 |
|
r.TotalAdditions = contributionStatistics.TotalAdditions |
68
|
1 |
|
r.TotalDeletions = contributionStatistics.TotalDeletions |
69
|
1 |
|
r.TotalCodeChanges = contributionStatistics.TotalCodeChanges |
70
|
1 |
|
r.AverageContributionPeriod = contributionStatistics.AverageContributionPeriod |
71
|
1 |
|
r.ReturningContributors = contributionStatistics.ReturningContributors |
72
|
1 |
|
r.MediCommitSize = contributionStatistics.MediumCommitSize |
73
|
|
|
|
74
|
1 |
|
r.CommitsByDay = github.GetCommitsByDay(contributionStatistics.TotalCommits, r.Age) |
75
|
|
|
|
76
|
1 |
|
dataChan <- *r |
77
|
|
|
} |
78
|
|
|
|