Skip to content

Commit

Permalink
Update top contributors as well as add new contributors
Browse files Browse the repository at this point in the history
Signed-off-by: isamrish <askmaurya48@gmail.com>
  • Loading branch information
isamrish committed Aug 30, 2021
1 parent d1f9a13 commit 76cb29b
Show file tree
Hide file tree
Showing 9 changed files with 442 additions and 60 deletions.
2 changes: 0 additions & 2 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ module.exports = {
onBrokenLinks: 'log',
customFields: {
openebsLogo: "/docs/img/openebs-logo.svg",
githubApiContributors:
"https://api.github.com/repos/openebs/openebs-docs/contributors?q=contributions&order=desc",
footbarLinks: {
gettingStarted: [
{
Expand Down
4 changes: 4 additions & 0 deletions docs/i18n/en/code.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,9 @@
"theme.common.skipToMainContent": {
"message": "Skip to main content",
"description": "The skip to content label used for accessibility, allowing to rapidly navigate to main content with keyboard tab/enter navigation"
},
"component.Footer.newContributors": {
"message": "New contributors",
"description": "New contributors label in footer"
}
}
6 changes: 4 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
"docusaurus": "docusaurus",
"prestart": "yarn run write-translations",
"start": "docusaurus start",
"prebuild": "yarn run write-translations",
"prebuild": "yarn run write-translations && yarn run get-contributors-info",
"build": "docusaurus build",
"previewBuild": "docusaurus build --out-dir docs",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "docusaurus clear",
"serve": "docusaurus serve",
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids"
"write-heading-ids": "docusaurus write-heading-ids",
"get-contributors-info": "node static/getContributors.js"
},
"dependencies": {
"@docusaurus/core": "2.0.0-beta.0",
Expand All @@ -30,6 +31,7 @@
"react-dropdown": "^1.9.2",
"react-feather": "^2.0.9",
"react-github-btn": "^1.2.0",
"request": "^2.88.2",
"sass": "^1.32.13",
"url-loader": "^4.1.1"
},
Expand Down
112 changes: 63 additions & 49 deletions docs/src/components/Footer/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// [TODO] -- use scss module
import React, { useEffect, useState } from "react";
import React from "react";
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
import Link from "@docusaurus/Link";
import { useViewport } from "@site/src/hooks/useViewport";
import Translate, { translate } from '@docusaurus/Translate';
import topContributors from '../../data/topContributors.json';
import newContributors from '../../data/newContributors.json';
import { githubProfile } from "../../utils/githubProfile";

const FooterLogo = () => {
const { siteConfig } = useDocusaurusContext();
Expand Down Expand Up @@ -108,54 +110,62 @@ const LinksContactUs = () => {
</div>
);
};
const Contributors = () => {
const { siteConfig } = useDocusaurusContext();
const githubApiContributors = siteConfig?.customFields?.githubApiContributors;
const [isLoaded, setIsLoaded] = useState(false);
const [items, setItems] = useState([]);
//getting the top contributors from github by sending the api order as desc
useEffect(() => {
fetch(githubApiContributors)
.then((res) => res?.json())
.then(
(result) => {
setIsLoaded(true);
setItems(result);
},
(error) => {
setIsLoaded(true);
console.error(error);
}
);
return () => {
setItems([]);
};
}, []);
const Contributors = ({ isTopContributors }) => {
return (
<div className="col">
{isLoaded && items.length && (
{(
<>
<span className="footer__title">
<Translate
id="component.Footer.topContributors"
description="Top contributors label in footer"
>Top contributors</Translate>
</span>
<ul className="footer__items">
{items?.slice(0, 3).map((item) => {
return (
<li className="footer__item" key={item.login}>
<Link
className="footer__link-item"
to={item.html_url}
target="_blank"
>
{item.login}
</Link>
</li>
);
})}
</ul>
{
isTopContributors ? (
<>
<span className="footer__title">
<Translate
id="component.Footer.topContributors"
description="Top contributors label in footer"
>Top contributors</Translate>
</span>
<ul className="footer__items">
{topContributors?.slice(0, 6).map((item) => {
return (
<li className="footer__item" key={item}>
<Link
className="footer__link-item"
to={githubProfile(item)}
target="_blank"
>
{item}
</Link>
</li>
);
})}
</ul>
</>
) : (
<>
<span className="footer__title">
<Translate
id="component.Footer.newContributors"
description="New contributors label in footer"
>New contributors</Translate>
</span>
<ul className="footer__items">
{newContributors?.slice(0, 6).map((item) => {
return (
<li className="footer__item" key={item}>
<Link
className="footer__link-item"
to={githubProfile(item)}
target="_blank"
>
{item}
</Link>
</li>
);
})}
</ul>
</>
)
}
</>
)}
</div>
Expand Down Expand Up @@ -278,7 +288,10 @@ const FooterMobileView = () => {
<LinksGettingStarted />
</div>
<div className="col col-6">
<Contributors />
<Contributors isTopContributors={true} />
</div>
<div className="col col-6">
<Contributors isTopContributors={false} />
</div>
</div>
<div className="margin-vert--md">
Expand Down Expand Up @@ -306,7 +319,8 @@ const FooterDesktopView = () => {
<SocialMedia />
</div>
<LinksGettingStarted />
<Contributors />
<Contributors isTopContributors={true} />
<Contributors isTopContributors={false} />
<FooterBottom />
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions docs/src/data/newContributors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["fengye87","Nivedita Prasad (Nivedita-coder)","zeenix","liuminjian","Almas Ahmad (almas33)","dsavitskiy","sbidoul","aamirqs","burntcarrot","huangfangfeng"]
1 change: 1 addition & 0 deletions docs/src/data/topContributors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["rakeshPRaghu","prateekpandey14","w3aman","Abhinandan-Purkait","nsathyaseelan","mynktl","niladrih","shubham14bajpai","satyapriyamishra222","AVRahul","Pallavi-PH","paulyoong","IsAmrish","tiagolobocastro","Ab-hishek","kmova","vharsh","cjones1024","gila","mittachaitu","rajaSahil","zeenix","jonathan-teh","pawanpraka1","dsavitskiy","mtzaurus","z0marlin","aamirqs","Abhishek-kumar09","akhilerm","almas33","AmitKumarDas","anupriya0703","fengye87","payes","shovanmaity"]
6 changes: 6 additions & 0 deletions docs/src/utils/githubProfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const githubProfile = function(id) {
if (id.indexOf('(') > -1) {
id = id.substring(id.lastIndexOf('(') + 1, id.lastIndexOf(')')).trim();
}
return `https://github.com/${id}`
}
105 changes: 105 additions & 0 deletions docs/static/getContributors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
const request = require("request");
const fs = require("fs");

const getdatesForContribution = (dateRange) => {
const today = new Date();
const priorDate = new Date();
priorDate.setDate(priorDate.getDate() - dateRange);
return {
today,
priorDate,
todayTimestamp: today.valueOf(),
priorDateTimestamp: priorDate.valueOf(),
};
};

const dateRanges = {
topContributors: 30, // last 30 days
newContributors: 60, // last 60 days
};

const rawSql = {
topContributors:
"select\n row_number() over (order by value desc) as \"Rank\",\n name,\n value\nfrom\n shpr_auth\nwhere\n series = 'hpr_authall'\n and period = 'm'",
newContributors:
"select str, dt from \"snew_contributors_data\" where $__timeFilter(dt) and series = 'ncdall' and period = 'd'",
};

const reqBodyToFetchContributors = (type) => ({
queries: [
{
refId: "A",
datasourceId: 1,
rawSql:
type === "topContributors"
? rawSql.topContributors
: rawSql.newContributors,
format: "table",
intervalMs: 86400000,
maxDataPoints: 1255,
},
],
range: {
from:
type === "topContributors"
? `${getdatesForContribution(dateRanges.topContributors).priorDate}`
: `${getdatesForContribution(dateRanges.newContributors).priorDate}`,
to: `${getdatesForContribution().today}`,
raw: {
from:
type === "topContributors"
? `now-${dateRanges.topContributors}d`
: `now-${dateRanges.newContributors}d`,
to: "now",
},
},
from:
type === "topContributors"
? `${
getdatesForContribution(dateRanges.topContributors).priorDateTimestamp
}`
: `${
getdatesForContribution(dateRanges.newContributors).priorDateTimestamp
}`,
to: `${getdatesForContribution().todayTimestamp}`,
});

const settings = (type) => ({
url: "https://openebs.devstats.cncf.io/api/ds/query",
method: "POST",
json: true,
headers: {
"Content-Type": "application/json",
},
body: reqBodyToFetchContributors(type),
});

const fetchContributors = async () => {
await request.post(
settings("topContributors"),
function (error, response, body) {
if (error) {
console.error(error);
return;
}
const data = JSON.stringify(body?.results?.A?.frames[0]?.data?.values[1]);
data && fs.writeFileSync("src/data/topContributors.json", data);
}
);

await request.post(
settings("newContributors"),
function (error, response, body) {
if (error) {
console.error(error);
return;
}
const data = JSON.stringify(
body?.results?.A?.frames[0]?.data?.values[0]?.reverse()
);
data && fs.writeFileSync("src/data/newContributors.json", data);
}
);
};

fetchContributors();
Loading

0 comments on commit 76cb29b

Please sign in to comment.