diff --git a/README.md b/README.md index 6537aaa..136f54a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ when needed. 2. Create a [personal GitLab access token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#creating-a-personal-access-token) with the `read_api` scope. ## Installation - ``` $ npm install -g gitlab-search ``` @@ -39,11 +38,12 @@ $ gitlab-search [options] [command] Options: -V, --version output the version number -g, --groups group(s) to find repositories in (separated with comma) + -r, --recursive Search recursively in projects in the given groups -f, --filename only search for contents in given a file, glob matching with wildcards (*) -e, --extension only search for contents in files with given extension -p, --path only search in files in the given path - -a, --archive [all,only,exclude] search only in archived projects, exclude archived projects, search in all projects (default is all) - -h, --help output usage information + -a, --archive [all,only,exclude] to only search on archived repositories, or to exclude them, by default the search will be apply to all repositories (default: "all") + -h, --help display help for command Commands: setup [options] create configuration file @@ -86,6 +86,18 @@ Requesting: GET https://gitlab.com/api/v4/projects/666/search?scope=blobs&search Requesting: GET https://gitlab.com/api/v4/projects/999/search?scope=blobs&search=here-is-my-search-term ``` +## Installing from source +1. Install node 14.x +2. Clone this repository +3. Build with + ```sh + $ npm run build + ``` +4. Run from bin directory + ```sh + $ bin/gitlab-search.js -h + ``` + ## License MIT diff --git a/src/GitLab.re b/src/GitLab.re index 858b0cc..9dcd94b 100644 --- a/src/GitLab.re +++ b/src/GitLab.re @@ -227,7 +227,12 @@ let fetchGroups = (groupsNames: option(string)) => { }; // https://docs.gitlab.com/ee/api/groups.html#list-a-groups-projects -let fetchProjectsInGroups = (archiveArgument: option(string), groups: array(group)) => { +let fetchProjectsInGroups = (archiveArgument: option(string), isRecursive: option(string), groups: array(group)) => { + let recursiveParam = switch (isRecursive) { + | None => ""; + | _ => "&include_subgroups=true"; + }; + let archiveQueryParam = switch (archiveArgument) { | Some("only") => "&archived=true"; | Some("exclude") => "&archived=false"; @@ -241,7 +246,7 @@ let fetchProjectsInGroups = (archiveArgument: option(string), groups: array(grou // explicit information about the incoming function argument is a list of groups (group: group) => paginatedRequest( - RelativeUrl("/groups/" ++ group.id ++ "/projects?per_page=100" ++ archiveQueryParam), + RelativeUrl("/groups/" ++ group.id ++ "/projects?per_page=100" ++ archiveQueryParam ++ recursiveParam), Decode.projects, ) ); diff --git a/src/Main.re b/src/Main.re index 7e70259..8006150 100644 --- a/src/Main.re +++ b/src/Main.re @@ -19,7 +19,7 @@ let main = (args, options) => { Js.Promise.( GitLab.fetchGroups(groups) - |> then_(GitLab.fetchProjectsInGroups(getOption("archive"))) + |> then_(GitLab.fetchProjectsInGroups(getOption("archive"), getOption("recursive"))) |> then_(GitLab.searchInProjects(criterias)) |> then_(results => resolve(Print.searchResults(criterias.term, results)) @@ -63,6 +63,7 @@ Commander.( "-g, --groups ", "group(s) to find repositories in (separated with comma)", ) + |> option("-r, --recursive", "Search recursively in projects in the given groups") |> option( "-f, --filename ", "only search for contents in given a file, glob matching with wildcards (*)",