githubgithub-apigit-submodules

How to get a list of submodules through github API?


I'm trying to get a list of submodules of a repository through GitHub API. After reading Github API docs, I did the following things: In Order to access the submodules of the Jquery, I use the following link to get a list of submodules, however, I cannot see any submodules from it. Could anyone please tell me what field should I use to get a list of submodules of a repository from GitHub API?


Solution

  • You can get the list of git submodules using Github GraphQL API v4 with the submodules connection property :

    {
      repository(owner: "bertrandmartel", name: "javacard-tutorial") {
        submodules(first: 100) {
          nodes {
            name
            path
          }
        }
      }
    }
    

    Try this in the explorer

    Output :

    {
      "data": {
        "repository": {
          "submodules": {
            "nodes": [
              {
                "name": "oracle_javacard_sdks",
                "path": "oracle_javacard_sdks"
              }
            ]
          }
        }
      }
    }
    

    Note that this will give only submodules on default branch's HEAD, from the documentation :

    Returns a list of all submodules in this repository parsed from the .gitmodules file as of the default branch's HEAD commit.

    Note that the jquery repository doesn't have any git submodules in its default branch's HEAD (and I don't see any in its other branches)