On GitHub API - what is the best way to get the last commit message associated with each file?

前端 未结 3 1393
感情败类
感情败类 2021-01-31 05:31

So far as I understand it, messages are associated with commits. But when you look at a repo on GitHub it helpfully lists the message by each file, for when it was last changed.

3条回答
  •  感动是毒
    2021-01-31 06:12

    In search of building permanent links, I found one of the easiest way to retrieve the commit sha is to actually parse the html page.

    Benefits:

    • all file/folder pages in a repository have it, even the root
    • single HTTP call
    • no auth login needed
    • will use the right branch (some don't use master as default)
    • works on branches too

    There is a link called Permalink on every file page. If you are looking for ways to identify that link there is the class .js-permalink-shortcut and also the data-hotkey="y" attribute, as described in Getting permanent links to files - Github.

    Permalink
    

    So in this example the sha is a6f4038336ff41463ad527b4ff4fda45642ebc6d.

    Note, it will always be rendered, even if you are already on that commit.

    In case somebody likes to build a permalink from it, the url hash (e.g. line references like #L437-L441) needs to be kept (appended) manually.

提交回复
热议问题