-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add GitHub stats to the status dashboard #2466
Conversation
I haven't found a way to get the total number of contributors since Github only returns a max of 100: |
Request 1 item per page, and then look at the last page you're given for pagination in the
I think we have some other code that parses this, which you can steal. Hey, I love what you're doing above! Some initial thoughts
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome!
It may look better with all the cards having the same height. Suck that I don't have a better way to show you my changes, but here it is.
- Add
height:100%
to the tag with classcard
- Add
justify-content: space-between
to the tag with classcard
- Add
margin-bottom: auto
to the tag with classcard-header
, ormargin-top: auto
to thehr
.
@humphd Thanks for the help on getting the total contributors! |
let weeklyCommits = 0; | ||
|
||
// get weekly commits for last year: https://docs.github.com/en/rest/reference/repos#get-the-weekly-commit-count | ||
fetch(`https://api.github.com/repos/Seneca-CDOT/${repo}/stats/participation`, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write a function to build your GitHub API urls for you vs. hard-coding below:
const ghApiUrl = (repo = 'Seneca-CDOT', path) => `https://api.github.com/repos/Seneca-CDOT/${repo}{path}`
Then you can use it like fetch(ghApiUrl('/stats/participation))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading further down, you can actually reuse a bunch of code here:
const fetchGitHubApi = (repo = 'Seneca-CDOT', path) =>
fetch(`https://api.github.com/repos/${repo}{path}`, {
headers: { Accept: 'application/vnd.github.v3+json', }
})
.then(res => {
if(!res.ok) {
throw new Error(`unable to get ${path}`);
}
return res.json()
)
.catch(err => console.error(err));
Now you can do:
fetchGitHubApi('/stats/participation')
.then(data => { /* process data here */);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes that's much better!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't reuse some parts because I don't always return res.json()
.
src/api/status/public/index.html
Outdated
@@ -1222,6 +1284,7 @@ <h6 class="mt-3">Thank you for sharing!</h6> | |||
<script src="assets/js/plugins/chartjs.min.js"></script> | |||
<script src="assets/js/demo-chart.js"></script> | |||
<script src="assets/js/demo-sidenav.js"></script> | |||
<script src="assets/js/gitHubStats.js"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a section specifically for our Telescope stuff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inside assets/js
? What should I call it?
connectSrc: [ | ||
"'self'", | ||
'*.fontawesome.com', | ||
`${process.env.API_HOST.replace(/(^\w+:|^)\/\//, '')}:4000`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this fixed in another PR already? cc @manekenpix
@@ -5006,6 +5006,8 @@ fieldset:disabled .btn { | |||
position: relative; | |||
display: flex; | |||
flex-direction: column; | |||
height: 100%; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't recommend overriding styles in the default asset, as it will affect other components. You can add another stylesheet to override the default.
This will be merged with the base style...
/* homepage.css */
.card {
height: 100%;
justify-content: space-between
}
...or make another class to make it clear (BEM style)
/* homepage.css */
.card--dashboard {
height: 100%;
justify-content: space-between
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put telescope-
in the name somehow, and maybe in a different directory, so it's clear that we are overriding the upstream styles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put it in /public/css/homepage.css
, and import it after the default assets.
For the class name, .card--dashboard
should be clear about the override. Breakdown: "card" is the component, "dashboard" is the modifier. The modifier indicates that it must be used with the "card" class and goes after the "card" class (i.e. className="card card--dashboard"). This follows the popular BEM methodology, which makes it easy for new contributors to follow.
EDIT: "dashboard" because these are changes for the cards in the dashboard only. If we use the cards somewhere else in the homepage, we may not need this "dashboard" modifier.
This needs a rebase too, to pick up the changes in server.js |
I rebased and moved the js and css files based on the recommendations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, looking forward to seeing it live.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small nit, otherwise this looks ready to go.
@@ -0,0 +1,68 @@ | |||
const fetchGitHubApi = (owner, repo, path) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If your arrow function immediately returns the result of an expression, you don't need a body or return
:
const fetchGitHubApi = (owner, repo, path) =>
fetch(`https://api.github.com/repos/${owner}/${repo}/${path}`, {
headers: { Accept: 'application/vnd.github.v3+json' },
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
Issue This PR Addresses
Fixes #2417
Type of Change
Description
This PR adds GitHub stats for Telescope and Satellite.
Stats available: yearly/weekly number of commits, weekly lines added/removed and latest contributor.
Checklist