For the lookout-sdk library to develop new analyzers go to lookout-sdk repository.
lookout-sdk binary is a simplified version of the lookoutd server that works with a local git repository and does not need access to Github.
You can think about lookout-sdk as a curl-like tool to call an analyzer gRPC endpoint with a ReviewEvent or a PushEvent, from a local git repository, and send it to an analyzer without accessing GitHub at all. For convenience, lookout-sdk also exposes a source{d} Lookout DataService backed by the same git repository.
You can download the latest lookout-sdk from the src-d/lookout releases page.
This is the sequence diagram of the ReviewEvent made by lookout-sdk review. You can compare it with a regular source{d} Lookout installation at the Architecture documentation.
You can edit this image using mermaid. (sourcecode)
You will need to run an analyzer to be called by lookout-sdk. You can run one of our example analyzers, any of the already available analyzers or the one that you're developing.
If your analyzer makes use of UAST, you will also need a Babelfish server running.
To start it using Docker Compose clone this repository, or download docker-compose.yml, and run:
$ docker-compose up bblfshThis will create the bblfshd container listening on localhost:9432.
To perform a NotifyReviewEvent call to an analyzer and serve the source{d} Lookout DataService endpoint, run:
$ lookout-sdk reviewTo perform a NotifyPushEvent call to an analyzer and serve the source{d} Lookout DataService endpoint, run:
$ lookout-sdk pushlookout-sdk will exit with a non 0 exit code if the gRPC call to the analyzer ends with an error or it could not be performed.
In the next section, you will find a more detailed example considering the most usual options for running lookout-sdk against any analyzer from two given revisions.
If we look at this example history of a given local repository stored at /somewhere/repo/path:
$ git log --pretty=oneline --graph
* d036524c463227524f4bbd7b207fb87bb8b89ee3 (HEAD -> master) Merge pull request #3
|\
| * 045a24828327ac35a28186f9b9b437adc3f7b7a3 (branch-b) message
| * 804cbd94869cb173494ce1de410f2b48674bc772 message
|/
* 9294ddb13cc7c8acd2db480c9e5c1396cd85e50a Merge pull request #2
|\
| * 355f001d719bd0368c0469acd1a46298a80bacc0 (branch-a) message
| * 7f2ee64cd0a5891900cc368ae35e60a61c262060 message
|/
* fa97fa19e5c9b3482e5f88e264fb62b1e7fc6d8f Merge pull request #1
*
*
...If your current directory is this repository's path, and your analyzer is listening on the default port 9930, you can run:
$ lookout-sdk reviewDoing so, lookout-sdk will:
- start a gRPC source{d} Lookout DataService endpoint backed by the repository stored at your current directory.
- send a gRPC
NotifyReviewEventcall to your analyzer listening onipv4://localhost:9930. TheReviewEventargument will contain acommit_revisionfield made of:basepointing toHEAD^(9294ddb...)headpointing toHEAD(d036524...)
- wait until the analyzer sends a response with the comments. The analyzer will be able to request file contents, file language or UASTs to the gRPC source{d} Lookout DataService endpoint exposed by
lookout-sdk - once the analyzer sends the response,
lookout-sdkwill put it into theSTDOUT, stop the source{d} Lookout DataService and exit.
Use the different options to trigger a different analysis. For example:
$ lookout-sdk review \
--git-dir=/somewhere/repo/path \
--from=fa97fa19e5c9b3482e5f88e264fb62b1e7fc6d8f \
--to=branch-a \
"ipv4://localhost:9999"For more options to run lookout-sdk, take a look into lookout-sdk Command Options
- If analyzer gRPC address is omitted, it will be
ipv4://localhost:9930. - If
--git-diris omitted, the current dir will be used. - If
--fromis omitted, it will beHEAD^. - If
--tois omitted, it will beHEAD. - Both
--fromand--tocan be any git revision. For example a tag name, branch name or the full commit SHA-1.
Everything explained above for lookout-sdk review calling NotifyReviewEvent, applies also to NotifyPushEvent when using lookout-sdk push.
lookout-sdk binary include some subcommands as described above, and they accept many different options; you can use:
lookout-sdk -h, to see all the available subcommands.lookout-sdk subcommand -h, to see all the options for the given subcommand.
Here are some of the most relevant options for both lookout-sdk push and lookout-sdk review:
| Env var | Option | Description | Default |
|---|---|---|---|
LOOKOUT_BBLFSHD |
--bblfshd= |
gRPC URL of the Bblfshd server | ipv4://localhost:9432 |
GIT_DIR |
--git-dir= |
path to the Git directory to analyze | . (current dir) |
--from= |
name of the base git revision for event | HEAD^ |
|
--to= |
name of the head git revision for event | HEAD |
|
--config-json= |
arbitrary JSON configuration for request to an analyzer |
| Env var | Option | Description | Default |
|---|---|---|---|
LOG_LEVEL |
--log-level= |
Logging level (info, debug, warning or error) |
info |
LOG_FORMAT |
--log-format= |
log format (text or json), defaults to text on a terminal and json otherwise |
|
LOG_FIELDS |
--log-fields= |
default fields for the logger, specified in json | |
LOG_FORCE_FORMAT |
--log-force-format |
ignore if it is running on a terminal or not |
