# neetob The `neetob` gem gives different commands for interacting with Github and Heroku instances of existing neeto projects. ## Table of Contents 1. [Getting Started](#getting-started) 1. [Installation](#installation) 2. [Usage](#usage) 3. [Working with GitHub](#working-with-github) 1. [Issues](#issues) 2. [Labels](#labels) 3. [Search](#search) 4. [Protect Branch](#protect-branch) 5. [Make PR](#make-pr) 6. [Login](#login) 4. [Working with Heroku](#working-with-heroku) 1. [Config Vars](#config-vars) 2. [Access](#access) 3. [Execute](#execute) 5. [Working with Users](#working-with-users) 1. [Audit](#audit) 2. [Commits](#commits) 6. [Working with Make Repos Uptodate](#working-with-make-repos-uptodate) 7. [Working with local Repos](#working-with-local-repos) 1. [ls](#ls) 8. [Testing](#testing) ## Getting started ### Installation Clone the repository onto your system using the following command: ```sh git clone https://github.com/bigbinary/neetob.git ``` Navigate to the root of the application directory. ```sh cd neetob ``` To set up `neetob`, execute the below command from the root of the application directory. ```sh bin/setup ``` ## Usage Utilize the `help` keyword to access a comprehensive list of all the available commands and options. ``` neetob help Commands: neetob github # Interact with any resource in Github neetob help [COMMAND] # Describe available commands or one specific command neetob heroku # Interact with any resource in Heroku neetob users # Interact with the contributors of neeto apps neetob make-repos-uptodate # Update all neeto repos Options: [--sandbox] # All the commands in sandbox mode will run only on the "neeto-dummy" app. ``` **By default, all commands will be executed in non-sandbox mode.** ### Useful command-line options | Option | Meaning | | ------------ | --------------------------------- | | --apps | Target app names | | --sandbox | Sandbox mode | | --no-sandbox | Non-Sandbox mode | | --help | Provides information on a command | **Note:** The commands within `neetob` should be used with caution, as improper usage may result in unintended consequences, and some actions may not be reversible. ## Working with GitHub Efficiently gain access to a comprehensive list of all the available subcommands for the `github` command by utilizing the `help` keyword. ```sh neetob github help ``` ### Issues The `issues` command offers valuable insights into GitHub issues. ```sh # To efficiently list and count all the open issues that are currently unassigned neetob github issues list --count --state open --assignee none --apps "neeto-*-web" # To list, count and filter all unassigned open issues that are labeled as "bug" . neetob github issues list --count --label bug --state open --assignee none --apps "neeto-*-web" ``` ### Labels The `labels` command provides an intuitive interface for interacting with Github labels. ```sh # The `list` command lists the details of all the labels in the Github repo. neetob github labels list --apps "neeto-*-web" # The `show` command gives the details for a specific label in the Github repo. neetob github labels show --name priority --apps "neeto-*-web" # The `update` command can be used to update the name of a label. neetob github labels update --old-name "High Priority" --new-name \ "high-priority" --apps neeto-dummy # The `upsert` command updates and inserts all the labels mentioned in default # labels JSON file that is "github-labels.json" file inside "data" directory. neetob github labels upsert --apps neeto-dummy # The `upsert` command can also be used with a different JSON file using `path` option. neetob github labels upsert --path ~/Desktop/labels.json --apps neeto-dummy # The `delete` command deletes the given labels from the Github repos. neetob github labels delete --labels "High Priority" "Priority 1" "bug" \ --apps neeto-dummy # The `delete_all` command deletes all the labels from the Github repos. neetob github labels delete_all --apps neeto-dummy ``` Check out the default labels [file](data/github-labels.json) for the required JSON file structure. ### Search Easily search for keywords across multiple neeto projects within specified files by utilizing the `search` command. ```sh neetob github search --keyword neeto --path README.md --apps "neeto-*-web" ``` ### Protect branch Efficiently update branch protection rules across various neeto applications by utilizing the `protect_branch` command. ```sh neetob github protect_branch --branch main --apps neeto-dummy ``` By default, this [file](data/branch-protection-rules.json) will be used for updating the branch protection rules. The `protect_branch` command can also be used with a different JSON file using `path` option. For example, assume we have a file named `branch-protection-rules.json` on the `Desktop` with the following rules: ```json { "required_conversation_resolution": true, "has_required_deployments": true } ``` To update the above-mentioned branch protection rules for the `main` branch of all the neeto applications, use the following command: ```sh neetob github protect_branch --branch main --path ~/Desktop/branch-protection-rules.json \ --apps neeto-dummy ``` **Note:** Unfortunately, utilizing the Github API, we are unable to update the `Require deployments to succeed before merging` rule, as it is currently not defined as a parameter within the API. For further information on available options to update different branch protection rules, kindly refer to the official Github [documentation](https://docs.github.com/en/rest/branches/branch-protection#update-branch-protection). ### Make PR The `make-pr` command can create pull requests across Github repos. ```sh # The `compliance-fix` command will do a `bundle` inside all repos and create a PR. neetob github make-pr compliance-fix # The `script` command will run the given script for each product and create a PR. neetob github make-pr script --path ~/Desktop/fix-folders.sh --branch "neetob-test" \ --title "PR title" ``` ### Login Authenticate through your browser and update your Github access token by utilizing the `login` command. ```sh neetob github login ``` ## Working with Heroku Utilize the `help` command to list all the available subcommands under the Heroku module for interacting with the Heroku resources. ```sh neetob heroku help ``` ### Config vars The `config_vars` command is useful to interact with Heroku config variables. ```sh # The `list` command lists all the Heroku config variables. neetob heroku config_vars list --apps "neeto-*-production" # We can list specific Heroku config variables using `keys` option. neetob heroku config_vars list --apps "neeto-*-production" --keys key1 key2 key3 # We can also use a file to specify required config vars for `list` command # Checkout the `data/config-vars-list.json` file for the required structure. neetob heroku config_vars list --apps "neeto-*-production" --path \ neetob/data/config-vars-list.json # The `audit` command will check the config variables against the JSON file named as # `required-config-vars.json` that is present inside the `data` directory at the root of # installed `neetob` gem. neetob heroku config_vars audit --apps "neeto-*-production" # The `audit` command can also be used with a different JSON file using `--path` option. neetob heroku config_vars audit --path ~/Desktop/config.json --apps "neeto-*-production" # The `upsert` command adds or updates the config variables from the # `data/config-vars-upsert.json` file present at the root of installed `neetob` gem. neetob heroku config_vars upsert --apps "neeto-*-staging" # The `remove` command is used to delete `config_vars`. neetob heroku config_vars remove --keys=TEST_KEY_1 TEST_KEY_2 --apps "neeto-*-staging" ``` We can use a custom JSON file with `upsert` command using the `path` option. For example, assume we have a file named `config.json` on the Desktop, like so: ```json { "NEETO_WIDGET_API_KEY": "jh4c1SC5cS5BvRbcBk4LD", "NEETO_KB_API_KEY": "Lxh7vUKkRewfxSg4dg834", "NEETO_CHAT_API_KEY": "sYnMTSCWLxkNbkHRXL1Xtd" } ``` To update the above-mentioned config variables to all staging apps, we can use the upsert command like so: ```sh neetob heroku config_vars upsert --path ~/Desktop/config.json --apps "neeto-*-staging" ``` The `upsert` command can also be used to update and insert project-specific config variables. For example, assume we have a file named `config.json` on the `Desktop` with the following properties: ```json { "neeto-chat-web-staging": { "NEETO_WIDGET_API_KEY": "jh4c1SC5cS5BvRbcBk4LD" }, "neeto-testify-web-production": { "NEETO_KB_API_KEY": "Lxh7vUKkRewfxSg4dg834" }, "neeto-desk-web-staging": { "NEETO_CHAT_API_KEY": "sYnMTSCWLxkNbkHRXL1Xtd" } } ``` To update the above-mentioned config variables under the defined project, we can use the upsert command like so: ```sh neetob heroku config_vars upsert --path_with_project_keys ~/Desktop/config.json ``` ### Access We can list, add, and remove users from multiple Heroku apps using the `access` command. ```sh # The `list` command retrieves a list of all the users from Heroku apps. neetob heroku access list --apps "neeto-*-production" # Add new users to the Heroku apps. neetob heroku access add --users oliver@bigbinary.com eve@bigbinary.com --apps "neeto-*-staging" # Remove the users from the Heroku apps. neetob heroku access remove --users oliver@bigbinary.com eve@bigbinary.com --apps \ "neeto-*-staging" ``` ### Execute Utilize the `execute` command to run a Heroku CLI command or a Rails console command for multiple neeto apps in one go. ```sh # We can check who has access to the neeto Heroku apps like so: neetob heroku execute -c "heroku access" --apps "neeto-*-production" # We can run a command in the Rails console for different neeto Heroku apps like so: neetob heroku execute -c "Sidekiq::Cron::Job.destroy \"server_side_worker\"" --apps \ "neeto-*-staging" --rails ``` ## Working with users Using the `users` command, we can interact with the contributors of neeto applications. ### Audit The `audit` command enables the ability to comprehensively audit contributors across all neeto applications by providing functionality to check for contributors with multiple emails and users with third-party domain emails. This command will search and use the neeto repos in the current working directory. To fetch and update all neeto repos execute [make_repos_uptodate](#working-with-make-repos-uptodate) command before the `audit` command. ```sh neetob users audit ``` ### Commits Using `commits` command we can list the commits for a user in a defined duration. This command will search and use the neeto repos in the current working directory. To fetch and update all neeto repos execute [make_repos_uptodate](#working-with-make-repos-uptodate) command before the `commits` command. ```sh # The below mentioned command will open a list of all the commits across neeto # repos made by "udai1931" in the duration of last 6 months neetob users commits --author udai1931 --duration 6.months # We can list commits for a specific product using `--apps` option neetob users commits --author udai1931 --duration 6.months --apps neeto-kb-web ``` ## Working with Make Repos Uptodate Using the `make_repos_uptodate` command, we can uptodate all neeto repos. The list of neeto repos is picked up from [neeto_compliance](https://github.com/bigbinary/neeto-compliance/blob/main/lib/neeto_compliance/neeto_repos.rb). ```sh neetob make_repos_uptodate ``` Executing the above mentioned command will check and clone all the missing neeto repos in the current working directory and will update all of them to the latest version. After the execution of command the directories will look something like this: ``` neeto-chat-web neeto-desk-web neeto-kb-web ``` ## Working with local Repos Using the `local` command, we can interact with the local neeto repos. ### ls The `ls` command can list the files from all the local neeto repos. This command will search and use the neeto repos in the current working directory. To fetch and update all neeto repos execute [make_repos_uptodate](#working-with-make-repos-uptodate) command before the `ls` command. ```sh # The `ls` command will list all the files in the root directory of neeto repos. neetob local ls --apps "*" # The `ls` command can also list files in a specific directory using the # `--dir` option. neetob local ls --dir public --apps "*" # We can also list files in a nested directory. neetob local ls --dir app/controllers --apps "*" ``` ## Testing For testing `github` commands use - [neeto-dummy](https://github.com/bigbinary/neeto-dummy) repo. For testing `heroku` commands use - [neeto-dummy](https://dashboard.heroku.com/apps/neeto-dummy) app. **Note:** Contact your respective Team Lead if you don't have access..