How can I get last commit from GitHub API

前端 未结 2 1132
春和景丽
春和景丽 2020-12-31 04:35

Which is the best way to get the latest commit information from a git repository using GitHub API (Rest API v3).

Option 1: GET /repos/:owner/:repo/commits/mast

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-31 05:27

    You can also use Github GraphQL v4 to get the last commit of the default branch :

    {
      repository(name: "linux", owner: "torvalds") {
        defaultBranchRef {
          target {
            ... on Commit {
              history(first: 1) {
                nodes {
                  message
                  committedDate
                  authoredDate
                  oid
                  author {
                    email
                    name
                  }
                }
              }
            }
          }
        }
      }
    }
    

    Or for all branches :

    {
      repository(name: "material-ui", owner: "mui-org") {
        refs(first: 100, refPrefix: "refs/heads/") {
          edges {
            node {
              name
              target {
                ... on Commit {
                  history(first: 1) {
                    nodes {
                      message
                      committedDate
                      authoredDate
                      oid
                      author {
                        email
                        name
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    

    Try it in the explorer

提交回复
热议问题