Package: net.gleske.jervis.remotes

[Groovy] Class GitHubGraphQL

    • Property Detail

      • TokenCredential credential

        A credential for interacting with an external credential store. If this is defined or set, then token is ignored and not used. Default: null

      • String token

        The API token, which can be used to communicate with GitHub using authentication. Default: null

    • Method Detail

      • @Override String baseUrl()

        A method which returns the base URL for the GitHub v4 GraphQL API. This method is not meant to be called by end users.

        Returns:
        Returns gh_api.

      • String getGqlData(String query, String variables = '')

        Transforms a GraphQL query and variables into data which can be submitted with a POST request. This is used by sendGQL to submit transformed GraphQL to the GitHub API v4 GraphQL.

        Parameters:
        query - A GraphQL query.
        variables - GraphQL variables meant to be used by a GraphQL query.
        Returns:
        Stringified data which can be submitted directly to a remote HTTP service that accepts GraphQL.

      • Map getJervisYamlFiles(String owner, String repository, List gitRefs = ['refs/heads/main'], List yamlFiles = ['.jervis.yml')

        Get Jervis YAML from a remote repository. It supports getting YAML from multiple branches at once (gitRefs and from multiple alternate YAML file locations (yamlFiles).

        Parameters:
        owner - GitHub repository owner such as an Organization or User. e.g. GitHub user samrocketman.
        repository - The name of the repository. e.g. jervis.
        gitRefs - A list of get references (branches, tags, commits, etc) in order to retrieve files. By default, the value ['refs/heads/main'].
        yamlFiles - A list of YAML files to try getting the Jervis YAML contents from. By default, the value is ['.jervis.yml', '.travis.yml'].
        Returns:
        Returns a fully formed graphql response. The following is an example when calling with defaults.

        Call with default arguments

        
        import net.gleske.jervis.remotes.GitHubGraphQL
        
        GitHubGraphQL github = new GitHubGraphQL()
        github.token = new File('../github_token').text.trim()
        
        
        // Make an API call to GitHub
        Map response = github.getJervisYamlFiles('samrocketman', 'jervis')
        

        Responds with parsed data

        
        [
            gitRef0: [
                jervisYaml0: null,
                jervisYaml1: [
                    text: 'language: groovy\\n'
                ]
                rootFolder: [
                    file: [
                        [
                            name: ".travis.yml",
                            type: "blob"
                        ],
                        [
                            name: "src",
                            type: "tree"
                        ]
                    ]
                ]
            ]
        ]
        

        The above response indicates there was no .jervis.yml, but there was a .travis.yml file.

        Files returned are typically one of three types:

        • blob - A file which has contents.
        • tree - A folder which can be recursed into.
        • commit - A Git submodule to a referenced repository.

      • Map getJervisYamlFiles(String repositoryWithOwner, List gitRefs = ['refs/heads/main'], List yamlFiles = ['.jervis.yml')

        Get Jervis YAML from a remote repository. It supports getting YAML from multiple branches at once (gitRefs and from multiple alternate YAML file locations (yamlFiles).

        Parameters:
        repositoryWithOwner - A repository URL which includes the GitHub owner. e.g. samrocketman/jervis.
        gitRefs - A list of get references (branches, tags, commits, etc) in order to retrieve files. By default, the value ['refs/heads/main'].
        yamlFiles - A list of YAML files to try getting the Jervis YAML contents from. By default, the value is ['.jervis.yml', '.travis.yml'].
        Returns:
        See other getJervisYamlFiles which returns the same thing. This method is just overloading the other.

      • String getToken()

        Retrieves the token used to authenticate with GitHub. If credential is set, then this will get the credential token, instead of token.

        Returns:
        A personal access token or an OAuth access token typically.

      • @Override Map header(Map http_headers = [:])

        A method which sets authentication headers. This method is not meant to be called by end users.

        Returns:
        Returns HTTP header map with authentication headers set.

      • def sendGQL(String graphql, String variables = '', String http_method = 'POST', Map http_headers = [:])

        A method for calling the GitHub v4 GraphQL API with a GraphQL query and variables.

        Parameters:
        graphql - A GraphQL query.
        variables - GraphQL variables meant to be used by a GraphQL query.
        http_method - Customize the method to be submitted to the GitHub GraphQL API. Typically POST, but could be another method if performing a mutation.
        http_headers - Add custom HTTP headers. This does not normally need to be called but is available for customization.
        Returns:
        A parsed response from the GitHub v4 GraphQL API.

      • def sendGQL(String graphql, Map variables, String http_method = 'POST', Map http_headers = [:])

        A method for calling the GitHub v4 GraphQL API with a GraphQL query and variables.

        Parameters:
        graphql - A GraphQL query.
        variables - GraphQL variables meant to be used by a GraphQL query.
        http_method - Customize the method to be submitted to the GitHub GraphQL API. Typically POST, but could be another method if performing a mutation.
        http_headers - Add custom HTTP headers. This does not normally need to be called but is available for customization.
        Returns:
        A parsed response from the GitHub v4 GraphQL API.

      • void setToken(String token)

        Sets the token to be used by GitHub. If credential is set then this will set the credential token, instead of token.

        Parameters:
        token - A personal access token or an OAuth access token typically.