diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 521a87e44..0a7f8ba2e 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -711,8 +711,11 @@ insights.contributor.num_of_deletions = "%d --" insights.commits = Commits insights.commits_by_week = "Commits by Week" insights.commits_in_a_week = "Commits in a Week" -insights.code_frequency = Code Frequency +insights.code_frequency = "Code Frequency" +insights.code_frequency_header = "Code frequency over the history of %s" insights.contributors_desc = Contributions to branch %s, excluding merge commits +insights.additions = "Additions" +insights.deletions = "Deletions" settings = Settings settings.options = Options diff --git a/internal/route/repo/insight.go b/internal/route/repo/insight.go index 13a1e08cf..1147d54ce 100644 --- a/internal/route/repo/insight.go +++ b/internal/route/repo/insight.go @@ -176,6 +176,27 @@ func InsightCodeFrequencyPage(c *context.Context) { c.Title("repo.insights.code_frequency") c.PageIs("InsightsCodeFrequency") + // Get commit data for the default branch + commits, err := getCommitData(c, c.Repo.Repository.DefaultBranch, true) + if err != nil { + c.Error(err, "get commits") + return + } + + // sort commits + sort.Slice(commits, func(i, j int) bool { + return commits[i].Commit.Author.When.After(commits[j].Commit.Author.When) + }) + + // get adition and deletion data + contributorChartData := getContributorChartData(commits, nil, nil) + c.Data["AdditionsChartData"] = contributorChartData.Additions + for i := range contributorChartData.Deletions.Dataset.Data { + contributorChartData.Deletions.Dataset.Data[i] = -contributorChartData.Deletions.Dataset.Data[i] + } + c.Data["DeletionsChartData"] = contributorChartData.Deletions + + c.Data["RepositoryName"] = fmt.Sprintf("%s/%s", c.Repo.Owner.Name, c.Repo.Repository.Name) c.Data["RequireChartJS"] = true c.RequireAutosize() c.Success(INSIGHT_CODE_FREQUENCY) diff --git a/templates/repo/insights/code_frequency.tmpl b/templates/repo/insights/code_frequency.tmpl new file mode 100644 index 000000000..636f2a9df --- /dev/null +++ b/templates/repo/insights/code_frequency.tmpl @@ -0,0 +1,74 @@ +{{template "base/head" .}} +{{$root := .}} +