【问题标题】:how to get the date of a commit using octokit.rb如何使用 octokit.rb 获取提交日期
【发布时间】:2014-04-23 08:58:42
【问题描述】:

所以我可以使用以下方法从 repo 中获取提交:

commits = Octokit.commits('tansaku/gitimmersion')

但我不知道如何获取提交日期。如果我 pp 个人提交,我可以看到日期:

#<Sawyer::Resource:0x007fb045935358 @_agent=<Sawyer::Agent https://api.github.com/>, @_fields=#<Set: {:author, :committer, :message, :tree, :comment_count}>, @_metaclass=#<Class:#<Sawyer::Resource:0x007fb045935358>>, @_rels=#<Sawyer::Relation::Map: [:self]>, @attrs= {:author=> #<Sawyer::Resource:0x007fb045932590 @_agent=<Sawyer::Agent https://api.github.com/>, @_fields=#<Set: {:name, :email, :date}>, @_metaclass=#<Class:#<Sawyer::Resource:0x007fb045932590>>, @_rels=#<Sawyer::Relation::Map: []>, @attrs= {:name=>"Sam Joseph", :email=>"tansaku@gmail.com", :date=>2014-03-10 14:35:53 UTC}>, :committer=> #<Sawyer::Resource:0x007fb0459302b8 @_agent=<Sawyer::Agent https://api.github.com/>, @_fields=#<Set: {:name, :email, :date}>, @_metaclass=#<Class:#<Sawyer::Resource:0x007fb0459302b8>>, @_rels=#<Sawyer::Relation::Map: []>, @attrs= {:name=>"Sam Joseph", :email=>"tansaku@gmail.com", :date=>2014-03-10 14:35:53 UTC}>, :message=>"using command lines", :tree=> #<Sawyer::Resource:0x007fb045927aa0 @_agent=<Sawyer::Agent https://api.github.com/>, @_fields=#<Set: {:sha}>, @_metaclass=#<Class:#<Sawyer::Resource:0x007fb045927aa0>>, @_rels=#<Sawyer::Relation::Map: [:self]>, @attrs={:sha=>"11b345c2fc315b5f7ae6db2e0f6b0570780c20d1"}>, :comment_count=>0}>

但我似乎无法从这些 Sawyer 对象中提取它们。

1.9.3-p392 :043 > pp commits[0].author.date nil => nil

1.9.3-p392 :047 > pp commits[0].committer.date nil => nil

现在显然我真的很愚蠢,但有人可以解释我如何从 Sawyer 对象中获取这些日期吗?

非常感谢提前 干杯>山姆

【问题讨论】:

    标签: ruby github octokit


    【解决方案1】:

    这可以解决您的困境吗?

    commits[0].commit.author[:date]
    =&gt; 2014-03-10 14:35:53 UTC
    commits[0].commit.committer[:date]
    =&gt; 2014-03-10 14:35:53 UTC

    【讨论】:

    • 优秀的@thomas - 非常感谢!有趣的是,尽管基于对象的转储看起来并不直观——我在文档中找不到对此的引用——我是否错过了它的一些重要部分……
    • 是的。我通过老式的尝试和错误发现了它。这不是应该做的。 ;-)
    猜你喜欢
    • 2020-12-31
    • 1970-01-01
    • 1970-01-01
    • 2015-07-02
    • 2020-03-04
    • 1970-01-01
    • 2014-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多