Skip to content

Commit e29efb2

Browse files
committed
Use new endpoint for fetching contributors data
1 parent c75b7a5 commit e29efb2

File tree

2 files changed

+54
-32
lines changed

2 files changed

+54
-32
lines changed

routers/web/repo/contributors.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package repo
22

33
import (
44
"net/http"
5-
"time"
65

7-
contributors_model "code.gitea.io/gitea/models/contributors"
86
"code.gitea.io/gitea/modules/base"
97
"code.gitea.io/gitea/modules/context"
108
)
@@ -26,22 +24,7 @@ func Contributors(ctx *context.Context) {
2624

2725
ctx.Data["ContributionTypeText"] = ctx.Tr("repo.contributors.contribution_type." + ctx.Data["ContributionType"].(string))
2826

29-
if contributor_stats, err := contributors_model.GetContributorStats(ctx, ctx.Repo.Repository, ""); err != nil {
30-
ctx.ServerError("GetContributorStats", err)
31-
return
32-
} else {
33-
total_stats, ok := contributor_stats["Total"]
34-
if ok {
35-
delete(contributor_stats, "Total")
36-
}
37-
ctx.PageData["repoTotalStats"] = total_stats
38-
ctx.PageData["repoContributorsStats"] = contributor_stats
39-
40-
timeFrom := time.UnixMilli(total_stats.Weeks[0].Week)
41-
timeUntil := time.Now()
42-
ctx.Data["DateFrom"] = timeFrom.UTC().Format(time.RFC3339)
43-
ctx.Data["DateUntil"] = timeUntil.UTC().Format(time.RFC3339)
44-
}
27+
ctx.PageData["repoLink"] = ctx.Repo.RepoLink
4528

4629
ctx.HTML(http.StatusOK, tplContributors)
4730
}

web_src/js/components/RepoContributors.vue

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<template>
22
<div>
3-
<Line :data="toGraphData(totalStats.weeks, 'main')" :options="getOptions('main')"/>
3+
<Line
4+
v-if="Object.keys(totalStats).length !== 0"
5+
:data="toGraphData(totalStats.weeks, 'main')"
6+
:options="getOptions('main')"
7+
/>
48

59
<div class="ui attached segment two column grid">
610
<div
@@ -21,7 +25,8 @@
2125
<div class="gt-ml-3">
2226
<a :href="contributor.home_link"><h4>{{ contributor.name }}</h4></a>
2327
<p class="gt-font-12">
24-
<strong>{{ contributor.total_commits.toLocaleString() }} commits </strong>
28+
<strong>{{ contributor.total_commits.toLocaleString() }} commits
29+
</strong>
2530
<strong class="text green">{{ additions(contributor.weeks).toLocaleString() }}++
2631
</strong>
2732
<strong class="text red">
@@ -30,7 +35,10 @@
3035
</div>
3136
</div>
3237
<div class="ui attached segment">
33-
<Line :data="toGraphData(contributor.weeks, 'contributor')" :options="getOptions('contributor')"/>
38+
<Line
39+
:data="toGraphData(contributor.weeks, 'contributor')"
40+
:options="getOptions('contributor')"
41+
/>
3442
</div>
3543
</div>
3644
</div>
@@ -56,6 +64,8 @@ import zoomPlugin from 'chartjs-plugin-zoom';
5664
import {Line} from 'vue-chartjs';
5765
import 'chartjs-adapter-dayjs-4/dist/chartjs-adapter-dayjs-4.esm';
5866
67+
const {pageData} = window.config;
68+
5969
Chart.register(
6070
TimeScale,
6171
CategoryScale,
@@ -72,25 +82,51 @@ Chart.register(
7282
7383
const sfc = {
7484
components: {Line},
75-
data: () => ({
76-
totalStats: window.config.pageData.repoTotalStats || [],
77-
type: window.config.pageData.contributionType,
78-
contributorsStats:
79-
window.config.pageData.repoContributorsStats || [],
80-
}),
85+
data: () => {
86+
return {
87+
isLoading: false,
88+
totalStats: {},
89+
repoLink: pageData.repoLink || [],
90+
type: pageData.contributionType,
91+
contributorsStats: [],
92+
};
93+
},
94+
mounted() {
95+
this.fetchGraphData();
96+
},
8197
computed: {
8298
sortedContributors() {
8399
return Object.values(this.contributorsStats)
84-
.sort((a, b) => (a.total_commits > b.total_commits ? -1 : a.total_commits === b.total_commits ? 0 : 1))
100+
.sort((a, b) =>
101+
a.total_commits > b.total_commits ?
102+
-1 :
103+
a.total_commits === b.total_commits ?
104+
0 :
105+
1
106+
)
85107
.slice(0, 100);
86108
},
87109
},
88110
methods: {
111+
async fetchGraphData() {
112+
this.isLoading = true;
113+
fetch(`/api/v1/repos/${this.repoLink}/contributors`)
114+
.then((response) => response.json())
115+
.then((data) => {
116+
const {Total, ...rest} = data;
117+
this.contributorsStats = rest;
118+
this.totalStats = Total;
119+
this.isLoading = false;
120+
});
121+
},
89122
maxMainGraph() {
90123
const maxValue = Math.max(
91124
...this.totalStats.weeks.map((o) => o[this.type])
92125
);
93-
const [cooefficient, exp] = maxValue.toExponential().split('e').map(Number);
126+
const [cooefficient, exp] = maxValue
127+
.toExponential()
128+
.split('e')
129+
.map(Number);
94130
if (cooefficient % 1 === 0) {
95131
return maxValue;
96132
}
@@ -117,7 +153,10 @@ const sfc = {
117153
pointRadius: 0,
118154
pointHitRadius: 0,
119155
fill: 'start',
120-
backgroundColor: type === 'main' ? 'rgba(137, 191, 154, 0.6)' : 'rgba(96, 153, 38, 0.7)',
156+
backgroundColor:
157+
type === 'main' ?
158+
'rgba(137, 191, 154, 0.6)' :
159+
'rgba(96, 153, 38, 0.7)',
121160
borderWidth: 0,
122161
tension: 0.3,
123162
},
@@ -157,7 +196,7 @@ const sfc = {
157196
mode: 'x',
158197
threshold: 20,
159198
160-
onPan: this.updateOtherCharts
199+
onPan: this.updateOtherCharts,
161200
},
162201
limits: {
163202
x: {
@@ -175,7 +214,7 @@ const sfc = {
175214
},
176215
mode: 'x',
177216
178-
onZoomComplete: this.updateOtherCharts
217+
onZoomComplete: this.updateOtherCharts,
179218
},
180219
},
181220
},

0 commit comments

Comments
 (0)