Skip to content

Usage Examples

Tak Tran edited this page May 10, 2019 · 22 revisions

Prerequisites

Before the usage examples below work, you will need:

  • A $GITHUB_PERSONAL_ACCESS_TOKEN stored as an environment variable.

    See the README for more information on this and the fallback option.

  • ebi to be installed globally with npm install --global ebi. Otherwise substituting ebi with npx ebi works too.

Searching Financial Times Customer-Products repositories

Ebi uses a list of new line separated repos in stdout as its input. Tako can be used to pipe all customer-products repos to ebi via stdout using the following command:

curl https://customer-products-tako.in.ft.com/tako/repositories -H "Authorization:Bearer $(heroku config:get --app ft-next-tako BEARER_TOKEN)" \
| jq -r '.repositories[] | "\(.owner)/\(.name)"' \
| <ebi command>

To use this command you will need to have installed jq using brew install jq.

In the examples below this command will be referred to as <customer_products_repos>

contents command

General usage

<newline_separated_list_of_repositories> | ebi contents <filepath> [search]
ebi contents <filepath> [search] <space_separated_list_of_repositories>

For each repository the contents command will return:

  • The repository name if there was a match
  • A 404 error message if the filepath was not found
  • An info statement if a search argument was provided and the string was not matched in the given filepath

Specific examples

Search all customer-products repos for whether a Procfile exists

<customer_products_repos> | ebi contents Procfile

Because no search term was provided this command will search only whether the file exists in each repository, so will return:

...
Financial-Times/kat-groups
404 ERROR: file 'Procfile' not found in 'Financial-Times/kat-kinesis-reader'
Financial-Times/kat-myft
Financial-Times/kat-usage
...

Search all customer-products repos for Procfiles which contain the string web

<customer_products_repos> | ebi contents Procfile web

Will return:

...
Financial-Times/next-api
Financial-Times/next-article
404 ERROR: file 'Procfile' not found in 'Financial-Times/next-article-email-api'
INFO: 'Procfile' has no match for 'web' in 'Financial-Times/bivalve'
...

Search a list of repos contained within a .txt file for READMEs which contain the string yak button, returning only 5 results

cat ../repositories.txt | ebi contents --limit=5 README.md "Yak button"

Will return:

...
Financial-Times/next-article
Financial-Times/next-front-page
Financial-Times/next-search-page
INFO: 'README.md' has no match for 'Yak button' in 'Financial-Times/next-signup'
...

NB the --limit flag is useful for when you want to check that your query works and don't want to return hundreds of potentially wrong results

package command

General usage

<newline_separated_list_of_repositories> | ebi package <search>
ebi package <search> <space_separated_list_of_repositories>

For each repository the package command will return:

  • The repository name if there was a match
  • An info statement if the string was not matched in package.json
  • A 404 error message if package.json was not found in the repository

Specific examples

Search a pre-defined list of repos for whether the string forever exists in their package.json files

cat ../repositories.txt | ebi package forever
...
INFO: 'package.json' has no match for 'forever' in 'Financial-Times/next-signup'
Financial-Times/next-signup-api
Financial-Times/next-stream-page
...

Search all customer-products repos for whether the string scripts exists in the package.json file

<customer_products_repos> | ebi package scripts

Will return:

...
Financial-Times/next-flag-expiry-notifier
Financial-Times/next-flags-api
404 ERROR: file 'package.json' not found in 'Financial-Times/next-flags-cli'
...

package:engines command

General usage

<newline_separated_list_of_repositories> | ebi package:engines [search]
ebi package:engines [search] <space_separated_list_of_repositories>

For each repository the package:engines command will return:

  • If there's a match: the repository name, the matching engine names, and the versions of the matching engines in the format repository_name engine1_name@engine1_version engine2_name@engine2_version
  • An info statement if the search value was not matched in the engines field of package.json
  • An info statement if the engines field is not found in package.json
  • A 404 error message if package.json was not found in the repository

Specific examples

Search all customer-products repos that contain node in the engines field of package.json

<customer_products_repos> | ebi package:engines node

Will return:

...
404 ERROR: file 'package.json' not found in 'Financial-Times/probot-config-next'
NOT FOUND: engines field not found in 'package.json' in 'Financial-Times/shorthand-lambda'
Financial-Times/spoor-api	node@^6.5.0
Financial-Times/spoor-consumer-lambda	node@6.10.3
...

Search all customer-products repos that contain 6 in the engines field of package.json

<customer_products_repos> | ebi package:engines 6

Will return:

...
Financial-Times/ft-app	npm@^5.0.0 || ^6.0.0
INFO: engines field not found in 'package.json' in 'Financial-Times/ft-app-node-reporter'
404 ERROR: file 'package.json' not found in 'Financial-Times/ft_app_automation'
Financial-Times/github-merge-jira-fixversion	node@^6.0.0
Financial-Times/google-amp	npm@^6.5.0
...

Search all customer-products repos for the contents of the engines field in package.json

<customer_products_repos> | ebi package:engines

Note - not providing a search string will return all contents of the engines field:

...
Financial-Times/github-merge-jira-fixversion	node@^6.0.0
Financial-Times/google-amp	node@^10.15.0	npm@^6.5.0
INFO: engines field not found in 'package.json' in 'Financial-Times/js-abbreviate'
Financial-Times/kat-groups	node@^8.2.1
Financial-Times/kat-router	node@^8.10.0	precommit@node_modules/.bin/secret-squirrel	prepush@make verify -j3
...

JSON output option

By adding a --json option, you can output as JSON for further processing.

In combination with jq, you can run quite powerful queries eg,

Show all the package.json contents (using the fileContents field)

<customer_products_repos> |\
  ebi package --json |\
  jq 'select(.type == "match") | .fileContents' --raw-output

Show some arbitrary package.json field eg, 'license' in the format [name]: [license] (using a 2nd jq command to further parse the JSON of fileContents)

<customer_products_repos> |\
  ebi package --json |\
  jq 'select(.type == "match") | .fileContents' --raw-output |\
  jq '"\(.name): \(.license)"'

List all repositories without package.json files (using the error type value)

<customer_products_repos> |\
  ebi package --json |\
  jq 'select(.type == "error") | .repository'