I wanted to answer this exact question so I made a very small demo of how to get the date of the latest commit.
Demo
Output:
ta-dachi
master
2019-03-21T14:50:22Z <----- What you want
b80126c3ea900cd7c92729e652b2e8214ff014d8
https://github.com/ta-dachi/eatsleepcode.tech/tree/master
Github repo
index.html
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>React Local</title>
<script
type="application/javascript"
src="https://unpkg.com/react@16.0.0/umd/react.production.min.js"
></script>
<script
type="application/javascript"
src="https://unpkg.com/react-dom@16.0.0/umd/react-dom.production.min.js"
></script>
<script
type="application/javascript"
src="https://unpkg.com/@babel/standalone/babel.min.js"
></script>
<script
type="application/javascript"
src="https://unpkg.com/whatwg-fetch@3.0.0/dist/fetch.umd.js"
></script>
</head>
<body>
<div id="root"></div>
<script type="text/jsx" src="index.jsx"></script>
</body>
index.jsx
/**
* See https://developer.github.com/v3/repos/branches/#get-branch
*
* Example Github api request:
* https://api.github.com/repos/ta-dachi/eatsleepcode.tech/branches/master
*/
class LatestCommitComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
author: "",
branch: "",
date: "",
sha: "",
link: ""
};
}
componentDidMount() {
// Replace this with your own repo
// https://api.github.com/repos/:owner/:repo/branches/master
fetch(
"https://api.github.com/repos/ta-dachi/eatsleepcode.tech/branches/master"
)
.then(response => {
response.json().then(json => {
console.log(json);
this.setState({
author: json.commit.author.login,
branch: json.name,
date: json.commit.commit.author.date,
sha: json.commit.sha,
link: json._links.html
});
});
})
.catch(error => {
console.log(error);
});
}
render() {
return (
<div>
<div>{this.state.author}</div>
<div>{this.state.branch}</div>
<div>{this.state.date}</div>
<div>{this.state.sha}</div>
<div>{this.state.link}</div>
</div>
);
}
}
ReactDOM.render(<LatestCommitComponent />, document.getElementById("root"));