### Display CLI help instructions Source: https://docs.mergestat.com/mergestat-lite/usage Use this command to view the most up-to-date usage instructions and available flags for the installed version. ```bash mergestat -h ``` -------------------------------- ### Install MergeStat via Go Toolchain Source: https://docs.mergestat.com/mergestat-lite/installation Build and install the binary from source using Go, ensuring libgit2 is available on the system. ```bash CGO_CFLAGS=-DUSE_LIBSQLITE3 CGO_LDFLAGS=-Wl,-undefined,dynamic_lookup go install -tags="sqlite_vtable,vtable,sqlite_json1,static,system_libgit2" github.com/mergestat/mergestat@latest ``` ```bash CGO_CFLAGS=-DUSE_LIBSQLITE3 CGO_LDFLAGS=-Wl,--unresolved-symbols=ignore-in-object-files go install -tags="sqlite_vtable,vtable,sqlite_json1,static,system_libgit2" github.com/mergestat/mergestat@latest ``` -------------------------------- ### Install MergeStat via Homebrew Source: https://docs.mergestat.com/mergestat-lite/installation Use the official tap to install the MergeStat CLI on macOS or Linux. ```bash brew tap mergestat/mergestat brew install mergestat ``` -------------------------------- ### List commits from specific history Source: https://docs.mergestat.com/mergestat-lite/examples/basic-git Filter commits by branch name or starting commit hash using an empty string to infer the repository. ```sql SELECT * FROM commits('', 'some-other-branch') -- list commits of a specific branch SELECT * FROM commits('', 'COMMIT_SHA') -- list commits starting from a commit hash ``` -------------------------------- ### Query NPM package information Source: https://docs.mergestat.com/mergestat-lite/reference/npm-tables Use npm_get_package to fetch metadata for a package by name, optionally specifying a version. ```sql SELECT npm_get_package('jquery') SELECT npm_get_package('jquery', 'latest') ``` -------------------------------- ### List git references Source: https://docs.mergestat.com/mergestat-lite/examples/basic-git Retrieve all git references from a repository. ```sql SELECT * FROM refs('https://github.com/mergestat/mergestat-lite') ``` -------------------------------- ### Load and query MergeStat in Python Source: https://docs.mergestat.com/mergestat-lite/usage/runtime-extension Enable extension loading on the connection object before executing the load_extension command. ```python import sqlite3 con = sqlite3.connect(":memory:") con.enable_load_extension(True) con.execute(f"select load_extension('./libmergestat')") con.enable_load_extension(False) for row in con.cursor().execute("SELECT * FROM commits('https://github.com/mergestat/mergestat')"): print(row) ``` -------------------------------- ### Load and query MergeStat in SQLite shell Source: https://docs.mergestat.com/mergestat-lite/usage/runtime-extension Use the .load command to import the extension and execute repository queries directly. ```sqlite sqlite> .load .build/libmergestat.so sqlite> select count(*) from commits('https://github.com/mergestat/mergestat'); 749 ``` -------------------------------- ### List files in a repository Source: https://docs.mergestat.com/mergestat-lite/examples/basic-git Retrieve file paths from a commit tree. Note that selecting all columns can be memory-intensive due to file contents. ```sql SELECT * FROM files('https://github.com/mergestat/mergestat-lite') LIMIT 10 ``` -------------------------------- ### Querying Git blame information Source: https://docs.mergestat.com/mergestat-lite/reference/git-tables Retrieve line-by-line blame information for files in a repository. ```sql -- return blame information for the first 10 lines of the file `README.md` SELECT * FROM blame('', 'HEAD', 'README.md') LIMIT 10 -- return blame information for lines of files in the repository SELECT files.path, blame.line_no, blame.commit_hash FROM files, blame('', 'HEAD', files.path) LIMIT 10 ``` -------------------------------- ### Clone organization repositories via SQL Source: https://docs.mergestat.com/mergestat-lite/miscellaneous/cloning-all-org-repos Uses the clone() function to download all repositories from the specified GitHub organization. ```sql -- Clone all git repositories in the mergestat GitHub org to disk SELECT clone('https://github.com/mergestat/'|| name) AS path FROM github_org_repos('mergestat') ``` -------------------------------- ### Clone repositories across multiple owners Source: https://docs.mergestat.com/mergestat-lite/miscellaneous/cloning-all-org-repos Uses a UNION ALL query to clone a combined set of repositories from different GitHub owners. ```sql SELECT clone('https://github.com/' || owner || '/' || name) AS path FROM ( SELECT 'mergestat' AS owner, name FROM github_org_repos('mergestat') LIMIT 5 UNION ALL SELECT 'patrickdevivo' AS owner, name FROM github_user_repos('patrickdevivo') LIMIT 5 ) ``` -------------------------------- ### Querying file contents and paths Source: https://docs.mergestat.com/mergestat-lite/reference/git-tables Access file paths and contents. Note that selecting full contents can be memory-intensive. ```sql -- return the attributes of two files SELECT * FROM files LIMIT 2 -- return the file paths modified in individual commits SELECT files.path, commits.hash FROM commits, files('', commits.hash) LIMIT 10 ``` -------------------------------- ### Execute a SQL query against a repository Source: https://docs.mergestat.com/mergestat-lite/usage Runs a SQL query string directly against the git repository in the current working directory. ```bash mergestat "SELECT * FROM commits" ``` -------------------------------- ### Query GitHub repositories Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables Fetches repository data for a specific user or organization, optionally filtered by affiliation. ```sql SELECT * FROM github_user_repos('patrickdevivo') SELECT * FROM github_org_repos('mergestat') SELECT * FROM github_user_repos('patrickdevivo', 'OWNER') SELECT * FROM github_org_repos('mergestat', 'OWNER,COLLABORATOR') ``` -------------------------------- ### Summarize repository commits Source: https://docs.mergestat.com/mergestat-lite/usage/summarize-commits Executes a summary of commits for a specified repository. ```bash mergestat summarize commits --repo "https://github.com/mergestat/mergestat" ``` -------------------------------- ### refs Source: https://docs.mergestat.com/mergestat-lite/reference/git-tables Retrieves all git references available in a repository, similar to git-show-ref. ```APIDOC ## SQL Table: refs ### Description Returns all git references (branches, tags, etc.) in the repository. ### Parameters - **repository** (TEXT) - Optional - Path to a local or remote repository. ### Columns - **name** (TEXT) - **type** (TEXT) - **remote** (TEXT) - **full_name** (TEXT) - **hash** (TEXT) - **target** (TEXT) ``` -------------------------------- ### Query GitHub Starred Repositories Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables Retrieves a list of repositories starred by a specific GitHub user. ```sql SELECT * FROM github_starred_repos('patrickdevivo') ``` -------------------------------- ### Execute repository cloning via CLI Source: https://docs.mergestat.com/mergestat-lite/miscellaneous/cloning-all-org-repos Runs the SQL clone command through the MergeStat CLI, specifying the target directory. ```bash mergestat "SELECT clone('https://github.com/mergestat/'|| name) AS path FROM github_org_repos('mergestat')" -v --clone-dir my-dir ``` -------------------------------- ### Querying with Table-Valued Functions Source: https://docs.mergestat.com/mergestat-lite Use table-valued functions to return result sets from data sources like git repositories. ```sql SELECT * FROM commits('https://github.com/mergestat/mergestat-lite', 'HEAD') SELECT * FROM commits -- no arguments supplied ``` -------------------------------- ### Clone repositories using SSH Source: https://docs.mergestat.com/mergestat-lite/miscellaneous/cloning-all-org-repos Clones organization repositories using the SSH protocol instead of HTTPS. ```sql SELECT clone('ssh://git@github.com:mergestat/'|| name) AS path FROM github_org_repos('mergestat') ``` -------------------------------- ### List commits from a repository Source: https://docs.mergestat.com/mergestat-lite/examples/basic-git Retrieve commit history by specifying a repository URL or using the default context. ```sql SELECT * FROM commits('https://github.com/mergestat/mergestat-lite') ``` ```sql SELECT * FROM commits -- repo is derived from context such as the --repo flag or the current directory ``` -------------------------------- ### Check file properties with enry Source: https://docs.mergestat.com/mergestat-lite/reference/utilities Various functions to classify files based on path or content. ```sql SELECT enry_is_binary('') ``` ```sql SELECT enry_is_configuration('some/path/to/file/config.json') ``` ```sql SELECT enry_is_documentation('some/path/to/file/README.md') ``` ```sql SELECT enry_is_dot_file('some/path/to/file/.gitignore') ``` ```sql SELECT enry_is_generated('some/path/to/file/generated.go', '') ``` ```sql SELECT enry_is_image('some/path/to/file/image.png') ``` ```sql SELECT enry_is_test('some/path/to/file/image.png') ``` ```sql SELECT enry_is_vendor('vendor/file.go') ``` -------------------------------- ### npm_get_package Source: https://docs.mergestat.com/mergestat-lite/reference/npm-tables Queries the NPM registry for package information. Depending on the number of arguments provided, it fetches either general package data or specific version data. ```APIDOC ## npm_get_package ### Description Queries the NPM registry at https://registry.npmjs.org/ and returns the JSON response for a given package or specific version. ### Parameters - **package** (string) - Required - The name of the NPM package. - **version** (string) - Optional - The specific version of the package to query. ### Usage Examples ```sql -- Get package information SELECT npm_get_package('jquery'); -- Get specific version information SELECT npm_get_package('jquery', 'latest'); ``` ``` -------------------------------- ### List file paths across all commits Source: https://docs.mergestat.com/mergestat-lite/examples/basic-git Join commits and files to traverse the file history of a repository. ```sql -- second parameter indicates what commit tree to list files from SELECT commits.hash, files.path FROM commits, files('', commits.hash) ``` -------------------------------- ### files Source: https://docs.mergestat.com/mergestat-lite/reference/git-tables Retrieves file paths and contents from the repository. ```APIDOC ## SQL Table: files ### Description Returns file information including path, executable status, and full contents. ### Parameters - **repository** (TEXT) - Optional - Path to a local or remote repository. - **rev** (TEXT) - Optional - Commit hash or branch/tag name, defaults to HEAD. ### Columns - **path** (TEXT) - **executable** (BOOL) - **contents** (TEXT) ``` -------------------------------- ### Run MergeStat with Docker Source: https://docs.mergestat.com/mergestat-lite/installation Execute queries using the official Docker image, mounting the current directory to allow repository access. ```bash docker run -v "${PWD}:/repo" mergestat/mergestat "select count(*) from commits" ``` -------------------------------- ### Query GitHub user information Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables Retrieves user details as a JSON object using the login identifier. ```sql SELECT github_user('patrickdevivo'); ``` -------------------------------- ### Clone all user repositories Source: https://docs.mergestat.com/mergestat-lite/miscellaneous/cloning-all-org-repos Clones all repositories belonging to a specific GitHub user. ```sql SELECT clone('https://github.com/patrickdevivo/'|| name) AS path FROM github_user_repos('patrickdevivo') ``` -------------------------------- ### Clone repositories filtered by language Source: https://docs.mergestat.com/mergestat-lite/miscellaneous/cloning-all-org-repos Clones only the repositories from an organization that match a specific primary language. ```sql SELECT clone('https://github.com/mergestat/'|| name) AS path FROM github_org_repos('mergestat') WHERE primary_language = 'Go' ``` -------------------------------- ### Query GitHub repository issues Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables Retrieves issues for a repository, supporting either a full name or separate owner and name arguments. ```sql SELECT * FROM github_repo_issues('mergestat/mergestat'); SELECT * FROM github_repo_issues('mergestat', 'mergestat'); -- both are equivalent ``` -------------------------------- ### Querying file statistics Source: https://docs.mergestat.com/mergestat-lite/reference/git-tables Retrieve file addition and deletion statistics for specific commits or history. ```sql -- return stats of HEAD SELECT * FROM stats -- return stats of a specific commit SELECT * FROM stats('', 'COMMIT_HASH') -- return stats for every commit in the current history SELECT commits.hash, stats.* FROM commits, stats('', commits.hash) ``` -------------------------------- ### Search text with grep Source: https://docs.mergestat.com/mergestat-lite/reference/utilities Searches text by line for a regular expression match. The before and after parameters default to 0 if omitted. ```sql SELECT * FROM grep(, , , ) SELECT * FROM grep(, ) -- before and after default to 0 ``` -------------------------------- ### Exporting query results to a SQLite database Source: https://docs.mergestat.com/mergestat-lite/usage/exporting Use the export command with the -e flag to define table names and their corresponding SQL queries. ```bash mergestat export my-export-file -e commits -e "SELECT * FROM commits" -e files -e "SELECT * FROM files" ``` -------------------------------- ### Query GitHub Branch Protections Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables Retrieves branch protection rules for a repository. Requires admin privileges on the GitHub access token. ```sql SELECT * FROM github_repo_branch_protections('mergestat/mergestat'); SELECT * FROM github_repo_branch_protections('mergestat', 'mergestat'); SELECT * FROM github_branch_protections('mergestat/mergestat'); SELECT * FROM github_branch_protections('mergestat', 'mergestat'); -- all are equivalent ``` -------------------------------- ### Load and query MergeStat in Node.js Source: https://docs.mergestat.com/mergestat-lite/usage/runtime-extension Utilize node-sqlite3 to load the extension and perform queries within a callback. ```javascript var sqlite3 = require('sqlite3').verbose(); var db = new sqlite3.Database(':memory:'); // load the extension from a local path db.loadExtension('libmergestat.so', (err) => { if (err) { console.error(err) return } db.each("SELECT * FROM commits('https://github.com/mergestat/mergestat')", (err, row) => { console.log(row); /* prints out all commits looking like: { hash: 'a4562d2d5a35536771745b0aa19d705eb47234e7', message: 'initial commit :tada:\n', author_name: 'Patrick DeVivo', author_email: 'patrick.devivo@gmail.com', author_when: '2020-07-03T15:59:58-04:00', committer_name: 'Patrick DeVivo', committer_email: 'patrick.devivo@gmail.com', committer_when: '2020-07-03T15:59:58-04:00', parents: 0 } */ }) }) db.close(); ``` -------------------------------- ### Convert go.mod to JSON Source: https://docs.mergestat.com/mergestat-lite/reference/utilities Parses a go.mod file content and returns a JSON representation. ```sql SELECT go_mod_to_json('') ``` -------------------------------- ### Detect language with enry Source: https://docs.mergestat.com/mergestat-lite/reference/utilities Detects the programming language of a file based on its path and content. ```sql SELECT enry_detect_language('some/path/to/file.go', '') ``` -------------------------------- ### Pipe a SQL query from stdin Source: https://docs.mergestat.com/mergestat-lite/usage Allows passing a SQL query file or stream into the CLI via standard input. ```bash cat query.sql | mergestat ``` -------------------------------- ### blame Source: https://docs.mergestat.com/mergestat-lite/reference/git-tables Retrieves blame information for files, similar to git blame. ```APIDOC ## SQL Table: blame ### Description Returns line-by-line blame information for files. ### Parameters - **repository** (TEXT) - Optional - Path to a local or remote repository. - **rev** (TEXT) - Optional - Commit hash or branch/tag name, defaults to HEAD. - **file_path** (TEXT) - Required - Path of the file to blame. ### Columns - **line_no** (INT) - **commit_hash** (TEXT) ``` -------------------------------- ### Query GitHub File Content Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables Retrieves the content of a specific file from a GitHub repository using a path or rev-parse expression. ```sql SELECT github_stargazer_count('mergestat', 'mergestat', 'README.md'); SELECT github_stargazer_count('mergestat/mergestat', 'README.md'); -- both are equivalent ``` -------------------------------- ### Query GitHub Branches Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables Retrieves branch information for a specified repository using either a full name or owner/name pair. ```sql SELECT * FROM github_repo_branches('mergestat', 'mergestat'); SELECT * FROM github_repo_branches('mergestat/mergestat'); ``` -------------------------------- ### Executing Scalar Functions Source: https://docs.mergestat.com/mergestat-lite Scalar functions return a single value and require appropriate environment variables like GITHUB_TOKEN to be set. ```sql -- GITHUB_TOKEN env must be set SELECT github_stargazer_count('mergestat/mergestat-lite') ``` -------------------------------- ### Enry Functions Source: https://docs.mergestat.com/mergestat-lite/reference/utilities SQL scalar functions for file analysis and classification based on the Enry project. ```APIDOC ## Enry Functions ### enry_detect_language Detects the language of a file. `SELECT enry_detect_language('', '')` ### enry_is_binary Determines if a blob is a binary file (returns 1 or 0). `SELECT enry_is_binary('')` ### enry_is_configuration Detects if a file path is a configuration file (returns 1 or 0). `SELECT enry_is_configuration('')` ### enry_is_documentation Detects if a file path is a documentation file (returns 1 or 0). `SELECT enry_is_documentation('')` ### enry_is_dot_file Detects if a file path is a dot file (returns 1 or 0). `SELECT enry_is_dot_file('')` ### enry_is_generated Detects if a file path is generated (returns 1 or 0). `SELECT enry_is_generated('', '')` ### enry_is_image Detects if a file path is an image (returns 1 or 0). `SELECT enry_is_image('')` ### enry_is_test Detects if a file path is a test file (returns 1 or 0). `SELECT enry_is_test('')` ### enry_is_vendor Detects if a file path is a vendored file (returns 1 or 0). `SELECT enry_is_vendor('')` ``` -------------------------------- ### github_user_repos and github_org_repos Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables Table-valued functions that return all repositories belonging to a specified user or organization. ```APIDOC ## github_user_repos(login, affiliations) / github_org_repos(login, affiliations) ### Description Returns a table of repositories for a given user or organization. ### Parameters - **login** (TEXT) - Required - The login of a GitHub user or organization. - **affiliations** (TEXT) - Optional - A comma-separated list of repository affiliations (OWNER, COLLABORATOR, ORGANIZATION_MEMBER). ### Example ```sql SELECT * FROM github_user_repos('patrickdevivo'); SELECT * FROM github_org_repos('mergestat', 'OWNER,COLLABORATOR'); ``` ``` -------------------------------- ### Filter tags Source: https://docs.mergestat.com/mergestat-lite/examples/basic-git Retrieve tag references, optionally filtered by name pattern. ```sql SELECT * FROM refs('https://github.com/mergestat/mergestat-lite') WHERE type = 'tag' ``` ```sql -- version tags only SELECT * FROM refs('https://github.com/mergestat/mergestat-lite') WHERE type = 'tag' AND name LIKE 'v%' ``` -------------------------------- ### Filter commits by file path Source: https://docs.mergestat.com/mergestat-lite/usage/summarize-commits Limits the commit summary to files matching a specific pattern or path. ```bash # Only show stats for commits that modify markdown files mergestat summarize commits %.md --repo "https://github.com/mergestat/mergestat" ``` ```bash # Only show stats for commits that modified cmd/root.go mergestat summarize commits cmd/root.go --repo "https://github.com/mergestat/mergestat" ``` -------------------------------- ### Query GitHub Stargazer Count Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables Returns the total number of stars for a repository as a scalar value. ```sql SELECT github_stargazer_count('mergestat', 'mergestat'); SELECT github_stargazer_count('mergestat/mergestat'); -- both are equivalent ``` -------------------------------- ### Filter commits by author Source: https://docs.mergestat.com/mergestat-lite/examples/basic-git Query commits based on author email patterns or specific author names. ```sql -- All commits from authors with '@gmail.com' email addresses SELECT * FROM commits('https://github.com/mergestat/mergestat-lite') WHERE author_email LIKE '%@gmail.com' -- All commits from author with a specific email address SELECT * FROM commits('https://github.com/mergestat/mergestat-lite') WHERE author_email = 'someone@example.com' ``` ```sql SELECT * FROM commits('https://github.com/mergestat/mergestat-lite') WHERE author_name LIKE '%Patrick%' ``` -------------------------------- ### Querying Git commits Source: https://docs.mergestat.com/mergestat-lite/reference/git-tables Retrieve commit history from local or remote repositories using the commits table. ```sql -- return all commits starting at HEAD SELECT * FROM commits -- specify an alternative repo on disk SELECT * FROM commits('/some/path/to/repo') -- clone a remote repo and use it SELECT * FROM commits('https://github.com/mergestat/mergestat-lite') -- use the default repo, but provide an alternate branch/ref -- list available refs and branches with `SELECT * FROM refs('https://github.com/mergestat/mergestat-lite')` SELECT * FROM commits('', 'some-ref') ``` -------------------------------- ### Query GitHub Issue Comments Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables Retrieve comments for a specific issue using the repository name and issue number. ```sql SELECT github_repo_issue_comments('mergestat/mergestat', 100); SELECT github_issue_comments('mergestat/mergestat', 100); ``` -------------------------------- ### github_starred_repos Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables A table-valued function that returns a list of repositories that a specific GitHub user has starred. ```APIDOC ## github_starred_repos ### Description Returns a list of repositories a user has starred. ### Parameters - **login** (TEXT) - Required - The login handle of a GitHub user. ### Example SELECT * FROM github_starred_repos('patrickdevivo'); ``` -------------------------------- ### Split strings with str_split Source: https://docs.mergestat.com/mergestat-lite/reference/utilities Splits string contents into rows based on a delimiter. Defaults to splitting on new lines. ```sql SELECT * FROM str_split(, ) SELECT * FROM str_split() -- splits on new lines ``` -------------------------------- ### Query GitHub Pull Requests Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables Retrieves pull request data for a specified repository using either a full name or owner/name pair. ```sql SELECT * FROM github_repo_prs('mergestat/mergestat'); SELECT * FROM github_repo_prs('mergestat', 'mergestat'); -- both are equivalent ``` -------------------------------- ### Query GitHub Stargazers Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables Retrieves a list of users who have starred a specific repository using either a full name or owner/name pair. ```sql SELECT * FROM github_stargazers('mergestat', 'mergestat'); SELECT * FROM github_stargazers('mergestat/mergestat'); -- both are equivalent ``` -------------------------------- ### grep Source: https://docs.mergestat.com/mergestat-lite/reference/utilities A table-valued function that searches text by line for a string match using regular expressions. ```APIDOC ## grep ### Description A table-valued function that searches text by line for a string match. The search term is a regular expression. ### Syntax `SELECT * FROM grep(, , , )` `SELECT * FROM grep(, )` ### Parameters - **contents** (TEXT) - The text to search in. - **search-term** (TEXT) - The regular expression to search for. - **before** (INT) - Optional, number of lines before match. - **after** (INT) - Optional, number of lines after match. ### Returns - **line_no** (INT) - **line** (TEXT) ``` -------------------------------- ### Query GitHub repository commits Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables Retrieves commit history for a specified repository using either a full name or owner/name pair. ```sql SELECT * FROM github_repo_commits('mergestat/mergestat'); SELECT * FROM github_repo_commits('mergestat', 'mergestat'); ``` -------------------------------- ### stats Source: https://docs.mergestat.com/mergestat-lite/reference/git-tables Retrieves file statistics (additions/deletions) for a repository. ```APIDOC ## SQL Table: stats ### Description Returns file-level statistics for a specific commit or range. ### Parameters - **repository** (TEXT) - Optional - Path to a local or remote repository. - **rev** (TEXT) - Optional - Commit hash or branch/tag name, defaults to HEAD. - **to_rev** (TEXT) - Optional - Commit hash to calculate stats relative to. ### Columns - **file_path** (TEXT) - **additions** (INT) - **deletions** (INT) ``` -------------------------------- ### Convert YAML to JSON Source: https://docs.mergestat.com/mergestat-lite/reference/utilities Converts YAML formatted strings into JSON. ```sql SELECT yaml_to_json('hello: world') -- +------------------------------+ -- | YAML_TO_JSON('HELLO: WORLD') | -- +------------------------------+ -- | {"hello":"world"} | -- +------------------------------+ ``` -------------------------------- ### Filter branches Source: https://docs.mergestat.com/mergestat-lite/examples/basic-git Retrieve branch references or join with commits to find the last commit timestamp. ```sql SELECT * FROM refs('https://github.com/mergestat/mergestat-lite') WHERE type = 'branch' ``` ```sql -- select all branches and the timestamp of their last commit SELECT refs.name, author_when FROM refs, commits WHERE type = 'branch' AND commits.hash = refs.hash ``` -------------------------------- ### Query Sourcegraph search results Source: https://docs.mergestat.com/mergestat-lite/reference/sourcegraph-tables Executes a search query against the Sourcegraph API using the sourcegraph_search function. ```sql SELECT sourcegraph_search('mergestat'); ``` -------------------------------- ### github_repo_branch_protections Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables A table-valued function that returns all branch protection rules for a specified GitHub repository. Requires a GitHub access token with admin privileges. ```APIDOC ## github_repo_branch_protections ### Description Returns all branch protection rules set on a GitHub repository. ### Parameters - **fullNameOrOwner** (TEXT) - Required - Either the full repo name (e.g., 'mergestat/mergestat') or just the owner (e.g., 'mergestat'). - **name** (TEXT) - Optional - The name of the repository (required if the first argument is only the owner). ### Example SELECT * FROM github_repo_branch_protections('mergestat/mergestat'); ``` -------------------------------- ### Filter commits by time range Source: https://docs.mergestat.com/mergestat-lite/usage/summarize-commits Bounds the commit summary to a specific time period using absolute or relative date strings. ```bash # Only show stats for commits authored in the last 30 days mergestat summarize commits --start "-30 days" --repo "https://github.com/mergestat/mergestat" ``` ```bash # Only show stats for commits authored in the 30 day period, starting 60 days ago mergestat summarize commits --start "-60 days" --end "-30 days" --repo "https://github.com/mergestat/mergestat" ``` ```bash # Only show stats for commits authored this year mergestat summarize commits --start "start of year" --repo "https://github.com/mergestat/mergestat" ``` -------------------------------- ### Query GitHub Pull Request Comments Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables Retrieve comments for a specific pull request using the repository name and PR number. ```sql SELECT github_repo_pr_comments('mergestat/mergestat', 200); SELECT github_repo_pr_comments('mergestat', 'mergestat', 200); SELECT github_pr_comments('mergestat/mergestat', 200); SELECT github_pr_comments('mergestat',' mergestat', 200); ``` -------------------------------- ### github_repo_issues Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables A table-valued function that returns all issues associated with a specific GitHub repository. ```APIDOC ## github_repo_issues(fullNameOrOwner, name) ### Description Returns a table of issues for a specified GitHub repository. ### Parameters - **fullNameOrOwner** (TEXT) - Required - The full repository name (e.g., 'owner/repo') or just the owner name. - **name** (TEXT) - Optional - The name of the repository (required if only the owner was provided in the first argument). ### Example ```sql SELECT * FROM github_repo_issues('mergestat/mergestat'); ``` ``` -------------------------------- ### Format Conversion Functions Source: https://docs.mergestat.com/mergestat-lite/reference/utilities Scalar functions to convert various data formats into JSON. ```APIDOC ## Format Conversion Functions ### toml_to_json Converts TOML to JSON. `SELECT toml_to_json('')` ### xml_to_json Converts XML to JSON. `SELECT xml_to_json('')` ### yaml_to_json / yml_to_json Converts YAML to JSON. `SELECT yaml_to_json('')` ### go_mod_to_json Parses a go.mod file content and returns a JSON representation. `SELECT go_mod_to_json('')` ``` -------------------------------- ### Convert TOML to JSON Source: https://docs.mergestat.com/mergestat-lite/reference/utilities Converts TOML formatted strings into JSON. ```sql SELECT toml_to_json('[some-toml]') -- +-----------------------------+ -- | TOML_TO_JSON('[SOME-TOML]') | -- +-----------------------------+ -- | {"some-toml":{}} | -- +-----------------------------+ ``` -------------------------------- ### github_repo_commits Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables Returns all the commits of a GitHub repository. ```APIDOC ## github_repo_commits ### Description Table valued function that returns all the commits of a GitHub repository. ### Parameters - **fullNameOrOwner** (TEXT) - Required - Either the full repo name (e.g., 'mergestat/mergestat') or just the owner. - **name** (TEXT) - Optional - The name of the repo (required if the first argument is only the owner). ### Usage Example SELECT * FROM github_repo_commits('mergestat/mergestat'); SELECT * FROM github_repo_commits('mergestat', 'mergestat'); ``` -------------------------------- ### github_repo_branches Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables A table-valued function that returns branch information for a specified GitHub repository. ```APIDOC ## github_repo_branches ### Description Returns a table containing branch information for a given GitHub repository. ### Parameters - **fullNameOrOwner** (TEXT) - Required - The full repository name (e.g., 'owner/repo') or just the owner name. - **name** (TEXT) - Optional - The name of the repository (required if only the owner is provided in the first parameter). ### Example SELECT * FROM github_repo_branches('mergestat/mergestat'); ``` -------------------------------- ### commits Source: https://docs.mergestat.com/mergestat-lite/reference/git-tables Retrieves all commits in the history of the repository, similar to git log. ```APIDOC ## SQL Table: commits ### Description Returns a list of commits from the repository history. ### Parameters - **repository** (TEXT) - Optional - Path to a local or remote repository. - **rev** (TEXT) - Optional - Revision (branch or SHA) to start from, defaults to HEAD. ### Columns - **hash** (TEXT) - **message** (TEXT) - **author_name** (TEXT) - **author_email** (TEXT) - **author_when** (DATETIME) - **committer_name** (TEXT) - **committer_email** (TEXT) - **committer_when** (DATETIME) - **parents** (INT) ``` -------------------------------- ### sourcegraph_search Source: https://docs.mergestat.com/mergestat-lite/reference/sourcegraph-tables A table-valued function that executes a Sourcegraph search query and returns results as a table. ```APIDOC ## sourcegraph_search ### Description Executes a search query against the Sourcegraph API and returns the results as a table. The results include the type of match and the raw JSON result data. ### Parameters - **query** (TEXT) - Required - A valid Sourcegraph search query string. ### Returns - **__typename** (TEXT) - The type of search result (Repository, CommitSearchResult, or FileMatch). - **results** (TEXT) - The JSON representation of the search result. ### Example ```sql SELECT sourcegraph_search('mergestat'); ``` ``` -------------------------------- ### github_repo_file_content Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables A scalar function that returns the contents of a file in a GitHub repository. ```APIDOC ## github_repo_file_content ### Description Returns the contents of a file in a GitHub repository. ### Parameters - **fullNameOrOwner** (TEXT) - Required - Either the full repo name or just the owner. - **name** (TEXT) - Optional - The name of the repository (required if the first argument is only the owner). - **expression** (TEXT) - Required - A simple file path or a rev-parse suitable expression (e.g., 'HEAD:README.md'). ``` -------------------------------- ### github_repo_issue_comments Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables Retrieves comments for a specific issue in a GitHub repository. ```APIDOC ## github_repo_issue_comments ### Description Table valued function that returns comments on a given issue. ### Parameters - **fullNameOrOwner** (TEXT) - Required - Full repo name (e.g., 'mergestat/mergestat') or owner name. - **name** (TEXT) - Optional - The name of the repo (required if only owner is provided in first argument). - **issue_number** (INT) - Required - The issue number. ### Example ```sql SELECT github_repo_issue_comments('mergestat/mergestat', 100); ``` ``` -------------------------------- ### Convert XML to JSON Source: https://docs.mergestat.com/mergestat-lite/reference/utilities Converts XML formatted strings into JSON. ```sql SELECT xml_to_json('hello') -- +-------------------------------------------+ -- | XML_TO_JSON('HELLO') | -- +-------------------------------------------+ -- | {"some-xml":"hello"} | -- +-------------------------------------------+ ``` -------------------------------- ### github_repo_prs Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables A table-valued function that returns all pull requests for a specified GitHub repository. ```APIDOC ## github_repo_prs ### Description Returns a table containing pull request details for a given GitHub repository. ### Parameters - **fullNameOrOwner** (TEXT) - Required - The full repository name (e.g., 'owner/repo') or just the owner name. - **name** (TEXT) - Optional - The name of the repository (required if only the owner is provided in the first parameter). ### Example SELECT * FROM github_repo_prs('mergestat/mergestat'); ``` -------------------------------- ### str_split Source: https://docs.mergestat.com/mergestat-lite/reference/utilities A table-valued function that splits string contents into rows based on a delimiter. ```APIDOC ## str_split ### Description A table-valued function that splits string contents into rows based on a delimiter (default is newline). ### Syntax `SELECT * FROM str_split(, )` `SELECT * FROM str_split()` ### Parameters - **contents** (TEXT) - The text to split. - **delimiter** (TEXT) - The delimiter to split on. ``` -------------------------------- ### github_repo_pr_comments Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables Retrieves all comments for a specific pull request in a GitHub repository. ```APIDOC ## github_repo_pr_comments ### Description Table valued function that returns all comments on a given pull request. ### Parameters - **fullNameOrOwner** (TEXT) - Required - Full repo name (e.g., 'mergestat/mergestat') or owner name. - **name** (TEXT) - Optional - The name of the repo (required if only owner is provided in first argument). - **number** (INT) - Required - The pull request number. ### Example ```sql SELECT github_repo_pr_comments('mergestat/mergestat', 200); ``` ``` -------------------------------- ### github_stargazers Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables A table-valued function that returns a list of users who have starred a specific GitHub repository. ```APIDOC ## github_stargazers ### Description Returns a list of users who have starred a repository. ### Parameters - **fullNameOrOwner** (TEXT) - Required - Either the full repo name (e.g., 'mergestat/mergestat') or just the owner (e.g., 'mergestat'). - **name** (TEXT) - Optional - The name of the repo (required if the first argument is only the owner). ### Example SELECT * FROM github_stargazers('mergestat', 'mergestat'); ``` -------------------------------- ### github_user Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables A scalar function that returns information about a GitHub user as a JSON object. ```APIDOC ## github_user(login) ### Description Returns information about a GitHub user as JSON. ### Parameters - **login** (TEXT) - Required - The user's login name. ### Example ```sql SELECT github_user('patrickdevivo'); ``` ``` -------------------------------- ### Extract specific split index Source: https://docs.mergestat.com/mergestat-lite/reference/utilities Retrieves a specific segment from a split string by index. ```sql SELECT str_split('hello,world', ',', 0) -- +----------------------------------+ -- | STR_SPLIT('HELLO,WORLD', ',', 0) | -- +----------------------------------+ -- | hello | -- +----------------------------------+ ``` ```sql SELECT str_split('hello,world', ',', 1) -- +----------------------------------+ -- | STR_SPLIT('HELLO,WORLD', ',', 1) | -- +----------------------------------+ -- | world | -- +----------------------------------+ ``` -------------------------------- ### github_stargazer_count Source: https://docs.mergestat.com/mergestat-lite/reference/github-tables A scalar function that returns the total number of stars for a given GitHub repository. ```APIDOC ## github_stargazer_count ### Description Returns the number of stars a GitHub repository has. ### Parameters - **fullNameOrOwner** (TEXT) - Required - Either the full repo name or just the owner. - **name** (TEXT) - Optional - The name of the repo (required if the first argument is only the owner). ### Example SELECT github_stargazer_count('mergestat', 'mergestat'); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.