【问题标题】:get time last updated github repository获取上次更新 github 存储库的时间
【发布时间】:2021-08-17 02:25:57
【问题描述】:

如何获取自 github 存储库中上次更新以来经过的时间。我也想获得主要语言。 Picture of what i mean

我想要这些数据,以便能够在其他网站上使用它

我想过用 JS 来做,查看“id”和“class”标签,但我在 github web 上找到了这段代码:

<li class="col-12 d-flex width-full py-4 border-bottom color-border-secondary private source" itemprop="owns" itemscope itemtype="http://schema.org/Code">
  <div class="col-10 col-lg-9 d-inline-block">
    <div class="d-inline-block mb-1">
      <h3 class="wb-break-all">
        <a href="/nameRepo" itemprop="name codeRepository" >nameRepo</a>
      </h3>
    </div>
    <div>
        <p class="col-9 d-inline-block color-text-secondary mb-2 pr-4" itemprop="description">
           Description
        </p>
    </div>
    <div class="f6 color-text-secondary mt-2">
        <span class="ml-0 mr-3">
  <span class="repo-language-color" style="background-color: #f1e05a"></span>
    <span itemprop="programmingLanguage">JavaScript</span>
  </span>
Updated <relative-time datetime="2021-05-27T08:02:25Z" class="no-wrap">May 27, 2021</relative-time>
    </div>
  </div>

我意识到这是不可行的,即使可行,也根本不实用。

我认为也许可以使用“ssh”的 API,但这也不能说服我,因为我不想要一个不断消耗这些资源的网站。

你可以集思广益,没有任何问题

【问题讨论】:

  • 日期可以这样格式化:momentjsdocument.getElementById(id).innerHTML = 'Updated on ' + dateMoment.fromNow(true);document.getElementById(id).innerHTML = dateMoment.format("[Updated on] D MMM");document.getElementById(id).innerHTML = dateMoment.format("[Updated on] D MMM YYYY");

标签: javascript jquery ajax git github


【解决方案1】:

您可以将 github API 与 JS 一起使用

任何公开且特定的 git 存储库。例如:

https://api.github.com/repos/USER/REPOSITORY/commits

此信息在commit.committer.date 中,文件为 JSON

如果它是在本地文件中找到的 git repo,则可以使用(在终端中):

git --no-pager log -1 --format="%ai"

【讨论】:

  • 我认为这是可以给出的最佳答案。如果 google 用户很着急,这里有一个示例,说明如何使用它以及应该修改什么:$.getJSON('https://api.github.com/repos/USER/REPO/commits', function (data) {// JSON result in data` variable});`
猜你喜欢
  • 2018-10-16
  • 2015-05-20
  • 2013-04-18
  • 1970-01-01
  • 2017-09-01
  • 2011-04-23
  • 2022-11-22
  • 1970-01-01
相关资源
最近更新 更多