Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit 40c0541

Browse files
Added User Contributions Over Time
1 parent e1dc3c7 commit 40c0541

2 files changed

Lines changed: 103 additions & 2 deletions

File tree

components/Form.js

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ class Form extends React.Component {
279279
this.state.dropdown === "user+repo" ||
280280
preset_select === "user+repo"
281281
) {
282-
console.log("here");
283282
const octokit = new Octokit({
284283
auth: process.env.NEXT_PUBLIC_GITHUB_API_KEY,
285284
});
@@ -298,8 +297,33 @@ class Form extends React.Component {
298297
repo: input2,
299298
});
300299

300+
const contributors = await octokit.repos.getContributorsStats({
301+
owner: input1,
302+
repo: input2,
303+
});
304+
301305
this.setState({ repo_url: repo["data"]["html_url"] });
302-
console.log(this.state.repo_url);
306+
307+
console.log(contributors);
308+
309+
contributors["data"].forEach((contributor) => {
310+
let contributor_data = {
311+
id: contributor["author"]["login"],
312+
data: [],
313+
};
314+
315+
contributor["weeks"].forEach((week) => {
316+
if (week["c"] > 0) {
317+
contributor_data["data"].push({
318+
x: new Date(week["w"] * 1000).toISOString().split("T")[0],
319+
y: week["a"] - week["d"],
320+
});
321+
}
322+
});
323+
this.setState({
324+
line_data: this.state.line_data.concat(contributor_data),
325+
});
326+
});
303327
} catch (e) {
304328
this.setState({ search_error: true });
305329
}
@@ -526,6 +550,78 @@ class Form extends React.Component {
526550
</a>
527551
</div>
528552
)}
553+
554+
{this.state.line_data.length > 0 && !this.state.search_error && (
555+
<div className={styles.repo_contributions}>
556+
<h4>User Contributions Over Time</h4>
557+
<ResponsiveLine
558+
data={this.state.line_data}
559+
margin={{ top: 20, right: 20, bottom: 60, left: 80 }}
560+
animate={true}
561+
xScale={{
562+
type: "time",
563+
format: "%Y-%m-%d",
564+
useUTC: true,
565+
precision: "day",
566+
}}
567+
xFormat="time:%Y-%m-%d"
568+
yScale={{
569+
type: "linear",
570+
stacked: false,
571+
min: "auto",
572+
max: "auto",
573+
}}
574+
colors={{ scheme: "set1" }}
575+
axisLeft={{
576+
legend: "linear scale",
577+
legendOffset: 12,
578+
}}
579+
axisBottom={{
580+
format: "%b %d",
581+
legend: "time scale",
582+
legendOffset: -12,
583+
tickRotation: 90,
584+
}}
585+
legend="Date"
586+
curve={"monotoneX"}
587+
enablePointLabel={true}
588+
pointSize={16}
589+
pointBorderWidth={1}
590+
pointBorderColor={{
591+
from: "color",
592+
modifiers: [["darker", 0.3]],
593+
}}
594+
useMesh={true}
595+
enableSlices={false}
596+
legends={[
597+
{
598+
anchor: "bottom-right",
599+
direction: "column",
600+
justify: false,
601+
translateX: 100,
602+
translateY: 0,
603+
itemsSpacing: 0,
604+
itemDirection: "left-to-right",
605+
itemWidth: 80,
606+
itemHeight: 20,
607+
itemOpacity: 0.75,
608+
symbolSize: 12,
609+
symbolShape: "circle",
610+
symbolBorderColor: "rgba(0, 0, 0, .5)",
611+
effects: [
612+
{
613+
on: "hover",
614+
style: {
615+
itemBackground: "rgba(0, 0, 0, .03)",
616+
itemOpacity: 1,
617+
},
618+
},
619+
],
620+
},
621+
]}
622+
/>
623+
</div>
624+
)}
529625
{this.state.search_error && (
530626
<div>
531627
<h4>Error in search, try again</h4>

components/Form.module.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@
3131
margin-left: auto;
3232
margin-right: auto;
3333
}
34+
35+
.repo_contributions {
36+
width: 1000px;
37+
height: 600px;
38+
}

0 commit comments

Comments
 (0)