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

前端 未结 3 1339
感情败类
感情败类 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:00

    I'm listing commits on the repository and than grabbing the first one and reading it's SHA and it works great:

    https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository

    In Go it looks something like this:

    func GetLatestCommit(owner, repo string, sgc *github.Client) (string, error) {
        commits, res, err := sgc.Repositories.ListCommits(owner, repo, &github.CommitsListOptions{})
    
        if err != nil {
            log.Printf("err: %s res: %s", err, res)
            return "", err
        }
    
        log.Printf("last commit: %s", *commits[0].SHA)
    
        return *commits[0].SHA, nil
    }
    

提交回复
热议问题