Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: don't remove this newline.

```
$ npm install -g gitlab-search
```
Expand Down Expand Up @@ -39,11 +38,12 @@ $ gitlab-search [options] [command] <search-term>
Options:
-V, --version output the version number
-g, --groups <group-names> group(s) to find repositories in (separated with comma)
-r, --recursive Search recursively in projects in the given groups
-f, --filename <filename> only search for contents in given a file, glob matching with wildcards (*)
-e, --extension <file-extension> only search for contents in files with given extension
-p, --path <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] <personal-access-token> create configuration file
Expand Down Expand Up @@ -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
```
Comment on lines +89 to +99
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a separate commit?

The prerequisites don't list a specific NodeJS version, and it doesn't seem to be required from what I tested.


## License

MIT
9 changes: 7 additions & 2 deletions src/GitLab.re
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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,
)
);
Expand Down
3 changes: 2 additions & 1 deletion src/Main.re
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -63,6 +63,7 @@ Commander.(
"-g, --groups <group-names>",
"group(s) to find repositories in (separated with comma)",
)
|> option("-r, --recursive", "Search recursively in projects in the given groups")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: lowercase is used for the other options (also update README)

|> option(
"-f, --filename <filename>",
"only search for contents in given a file, glob matching with wildcards (*)",
Expand Down