GraphQL - list all branches by repository

Hi,

  The following query lists all the repo.

Is there any way to list branches and the last commit date?

{
  search(query: "org:udayabaski", type: REPOSITORY, last: 100) {
    edges {
      node {
        ... on Repository{
          name
          url
          createdAt
          isArchived
          isDisabled
          updatedAt
          defaultBranchRef {
            name
          }
          branchProtectionRules(first:100) {
             edges {
              node {
                dismissesStaleReviews
              }
            }
          }
          collaborators(first:100) {
            totalCount
            edges {
              node {
                email
              }
            }
          }
          releases(first:10) {
            totalCount
            edges {
              node {
                author {
                  email
                }
                publishedAt
                tagName
                name
                isDraft
                isPrerelease
                tag {
                  id
                }
                tagName
              }
            }
          }
        }
      }
    }
  }
}
1 Like

This query should give you the information that you’re asking for:

{
  search(query: "org:udayabaski", type: REPOSITORY, last: 100) {
    nodes {
      ... on Repository {
        nameWithOwner
        refs(first: 100, refPrefix: "refs/heads/") {
          nodes {
            name
            target {
              ... on Commit {
                oid
                committedDate
              }
            }
          }
        }
      }
    }
  }
}

The thing to know is that branches are a type of ref (short for reference), something that refers to another object in the git database.

I hope that helps!

3 Likes