如何在我的网站上显示 GitHub 上的最新提交的名称?
How to display the name of the latest commit on GitHub to my website?
我需要简单地从 GitHub 获取最新提交的名称并在 Web 上以静态方式最好 显示它。
就像@MauriceNino 评论的那样,您可以使用https://api.github.com/repos/{user}/{repo}/commits?per_page=1
来获取最新的提交。
下面的示例取自 https://github.com/ChocolateLoverRaj/canvideo and puts the result in a <pre>
. Link to api request。
fetch('https://api.github.com/repos/ChocolateLoverRaj/canvideo/commits?per_page=1')
.then(res => res.json())
.then(res => {
document.getElementById('message').innerHTML = res[0].commit.message
})
<pre id="message">Loading</pre>
我需要简单地从 GitHub 获取最新提交的名称并在 Web 上以静态方式最好 显示它。
就像@MauriceNino 评论的那样,您可以使用https://api.github.com/repos/{user}/{repo}/commits?per_page=1
来获取最新的提交。
下面的示例取自 https://github.com/ChocolateLoverRaj/canvideo and puts the result in a <pre>
. Link to api request。
fetch('https://api.github.com/repos/ChocolateLoverRaj/canvideo/commits?per_page=1')
.then(res => res.json())
.then(res => {
document.getElementById('message').innerHTML = res[0].commit.message
})
<pre id="message">Loading</pre>