neetob 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +4 -4
- data/README.md +14 -0
- data/lib/neetob/cli/base.rb +5 -0
- data/lib/neetob/cli/github/commands.rb +2 -1
- data/lib/neetob/cli/github/make_pr/base.rb +12 -0
- data/lib/neetob/cli/github/make_pr/commands.rb +2 -1
- data/lib/neetob/cli/github/make_pr/compliance_fix.rb +1 -3
- data/lib/neetob/cli/github/make_pr/script.rb +5 -5
- data/lib/neetob/cli/github/search.rb +73 -11
- data/lib/neetob/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 9fd60283a5ac6d285fe20a16357e39d0c72d9c48964d44016915eda55cd41a41
         | 
| 4 | 
            +
              data.tar.gz: dc89a8882804bd9d774c6ae8e7f91760fb15ad000a7d0eb6ec89d7bb447c717d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 3a373c5ca6a6e9a77071e5714d7b08c9ebdd03e2c0567ac1b7280233d28659c7491255ede9d20a185bdb5764b7d6b6746ce31a0ab43333a02f4f16fce77edf55
         | 
| 7 | 
            +
              data.tar.gz: 1208e7c0d1dc21e242bbcaa68b58e07f4e4d544f39e63582599b85597c0340effa7fb8ff10a78fce4f0456b20569eba442d85a2f077772b57a437b9b7d1db01b
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,5 +1,19 @@ | |
| 1 1 | 
             
            ## [Unreleased]
         | 
| 2 2 |  | 
| 3 | 
            +
            ### [0.4.3](https://www.github.com/bigbinary/neetob/compare/v0.4.2...v0.4.3) (2023-04-25)
         | 
| 4 | 
            +
             | 
| 5 | 
            +
             | 
| 6 | 
            +
            ### Bug Fixes
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            * Added frontend packages option for make-pr command ([#255](https://www.github.com/bigbinary/neetob/issues/255)) ([a884e24](https://www.github.com/bigbinary/neetob/commit/a884e24a5160ba28cae90ba73e9a4853587be4e6))
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            ### [0.4.2](https://www.github.com/bigbinary/neetob/compare/v0.4.1...v0.4.2) (2023-04-14)
         | 
| 11 | 
            +
             | 
| 12 | 
            +
             | 
| 13 | 
            +
            ### Bug Fixes
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            * Allow regex values for path and keyword in github search command. ([#233](https://www.github.com/bigbinary/neetob/issues/233)) ([f6866db](https://www.github.com/bigbinary/neetob/commit/f6866dbe3decf897c483a5b77aaa8989a21192d4))
         | 
| 16 | 
            +
             | 
| 3 17 | 
             
            ### [0.4.1](https://www.github.com/bigbinary/neetob/compare/v0.4.0...v0.4.1) (2023-04-05)
         | 
| 4 18 |  | 
| 5 19 |  | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                neetob (0.4. | 
| 4 | 
            +
                neetob (0.4.3)
         | 
| 5 5 | 
             
                  brakeman (~> 5.0)
         | 
| 6 6 | 
             
                  chronic
         | 
| 7 7 | 
             
                  dotenv (~> 2.8.1)
         | 
| @@ -148,9 +148,9 @@ GEM | |
| 148 148 | 
             
                net-smtp (0.3.3)
         | 
| 149 149 | 
             
                  net-protocol
         | 
| 150 150 | 
             
                nio4r (2.5.8)
         | 
| 151 | 
            -
                nokogiri (1. | 
| 151 | 
            +
                nokogiri (1.14.3-x86_64-darwin)
         | 
| 152 152 | 
             
                  racc (~> 1.4)
         | 
| 153 | 
            -
                nokogiri (1. | 
| 153 | 
            +
                nokogiri (1.14.3-x86_64-linux)
         | 
| 154 154 | 
             
                  racc (~> 1.4)
         | 
| 155 155 | 
             
                octokit (4.25.1)
         | 
| 156 156 | 
             
                  faraday (>= 1, < 3)
         | 
| @@ -166,7 +166,7 @@ GEM | |
| 166 166 | 
             
                  coderay (~> 1.1)
         | 
| 167 167 | 
             
                  method_source (~> 1.0)
         | 
| 168 168 | 
             
                public_suffix (5.0.0)
         | 
| 169 | 
            -
                racc (1.6. | 
| 169 | 
            +
                racc (1.6.2)
         | 
| 170 170 | 
             
                rack (2.2.6.4)
         | 
| 171 171 | 
             
                rack-test (2.0.2)
         | 
| 172 172 | 
             
                  rack (>= 1.3)
         | 
    
        data/README.md
    CHANGED
    
    | @@ -164,6 +164,16 @@ Searches for keywords across multiple neeto projects within specified files by u | |
| 164 164 | 
             
            neetob github search --keyword neeto --path README.md --repos "neeto-*-staging"
         | 
| 165 165 | 
             
            ```
         | 
| 166 166 |  | 
| 167 | 
            +
            We can also use regular-expressions as the value for both the keyword and the path of the file.
         | 
| 168 | 
            +
             | 
| 169 | 
            +
            ```sh
         | 
| 170 | 
            +
            neetob github search --keyword "ne*to" --path ".*\.md$" --repos "neeto-*-staging"
         | 
| 171 | 
            +
            ```
         | 
| 172 | 
            +
             | 
| 173 | 
            +
            The above command searches for all occurrences of any word matching the given reg-expression in all files with the extension ".md".
         | 
| 174 | 
            +
             | 
| 175 | 
            +
            We can pass the `--replace` option to replace all found instances of the keyword with another word.
         | 
| 176 | 
            +
             | 
| 167 177 | 
             
            ### Protect branch
         | 
| 168 178 |  | 
| 169 179 | 
             
            Updates branch protection rules in neeto repos by using the `protect_branch` command.
         | 
| @@ -218,6 +228,10 @@ neetob github make-pr compliance-fix --nanos | |
| 218 228 | 
             
            # The `script` command runs the given script for each product and create a PR
         | 
| 219 229 | 
             
            neetob github make-pr script --path ~/Desktop/fix-folders.sh --branch "neetob-test" \
         | 
| 220 230 | 
             
            --title "PR title" --description "PR description"
         | 
| 231 | 
            +
             | 
| 232 | 
            +
            # Create PRs using script in neeto frontend packages
         | 
| 233 | 
            +
            neetob github make-pr script --path ~/Desktop/fix-folders.sh --branch "neetob-test" \
         | 
| 234 | 
            +
            --title "PR title" --description "PR description" --frontend-packages
         | 
| 221 235 | 
             
            ```
         | 
| 222 236 |  | 
| 223 237 | 
             
            ### Gems
         | 
    
        data/lib/neetob/cli/base.rb
    CHANGED
    
    | @@ -100,5 +100,10 @@ module Neetob | |
| 100 100 | 
             
                    all_available_gems = NeetoCompliance::NeetoRepos.nanos_backend
         | 
| 101 101 | 
             
                    match_apps(gems || ["*"], all_available_gems)
         | 
| 102 102 | 
             
                  end
         | 
| 103 | 
            +
             | 
| 104 | 
            +
                  def find_all_matching_frontend_packages(packages = ["*"])
         | 
| 105 | 
            +
                    all_available_packages = NeetoCompliance::NeetoRepos.nanos_frontend
         | 
| 106 | 
            +
                    match_apps(packages || ["*"], all_available_packages)
         | 
| 107 | 
            +
                  end
         | 
| 103 108 | 
             
              end
         | 
| 104 109 | 
             
            end
         | 
| @@ -31,8 +31,9 @@ module Neetob | |
| 31 31 | 
             
                    option :keyword, type: :string, aliases: "-k", desc: "Keyword which needs to be searched", required: true
         | 
| 32 32 | 
             
                    option :path, type: :string, aliases: "-p",
         | 
| 33 33 | 
             
                      desc: "Path of the file in which you want to search the given keyword.", required: true
         | 
| 34 | 
            +
                    option :replace, type: :string, aliases: "-s", desc: "Word with which you want to replace the found instances of the keyword"
         | 
| 34 35 | 
             
                    def search
         | 
| 35 | 
            -
                      Search.new(options[:repos], options[:keyword], options[:path], options[:sandbox]).run
         | 
| 36 | 
            +
                      Search.new(options[:repos], options[:keyword], options[:path], options[:replace], options[:sandbox]).run
         | 
| 36 37 | 
             
                    end
         | 
| 37 38 |  | 
| 38 39 | 
             
                    desc "login", "Update the Github access token by authenticating via browser"
         | 
| @@ -36,6 +36,10 @@ module Neetob | |
| 36 36 | 
             
                          `git clone --quiet --depth 1 git@github.com:#{repo}.git /tmp/neetob/#{repo_name_without_org_suffix(repo)}`
         | 
| 37 37 | 
             
                        end
         | 
| 38 38 |  | 
| 39 | 
            +
                        def clone_repo_in_tmp_dir(repo)
         | 
| 40 | 
            +
                          `git clone --quiet git@github.com:#{repo}.git /tmp/neetob/#{repo_name_without_org_suffix(repo)}`
         | 
| 41 | 
            +
                        end
         | 
| 42 | 
            +
             | 
| 39 43 | 
             
                        def add_commmit_and_push_changes(repo)
         | 
| 40 44 | 
             
                          `#{cd_to_repo_in_tmp_dir(repo)} && git add . && \\
         | 
| 41 45 | 
             
                          git commit -m "#{pr_title}" && git push -u origin #{branch_name} --force`
         | 
| @@ -74,6 +78,14 @@ module Neetob | |
| 74 78 | 
             
                        def add_org_suffix(repos)
         | 
| 75 79 | 
             
                          repos.map { |repo| "bigbinary/#{repo}" }
         | 
| 76 80 | 
             
                        end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                        def build_matching_repos_list(should_fix_nanos, should_fix_frontend_packages = false)
         | 
| 83 | 
            +
                          return add_org_suffix(find_all_matching_gems) if should_fix_nanos
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                          return add_org_suffix(find_all_matching_frontend_packages) if should_fix_frontend_packages
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                          find_all_matching_apps_or_repos(repos, :github, sandbox)
         | 
| 88 | 
            +
                        end
         | 
| 77 89 | 
             
                    end
         | 
| 78 90 | 
             
                  end
         | 
| 79 91 | 
             
                end
         | 
| @@ -27,10 +27,11 @@ module Neetob | |
| 27 27 | 
             
                      option :title, type: :string, aliases: "-t", desc: "Title for the PR"
         | 
| 28 28 | 
             
                      option :branch, type: :string, aliases: "-b", desc: "Feature branch name for the PR"
         | 
| 29 29 | 
             
                      option :description, type: :string, aliases: "-d", desc: "Description of the PR"
         | 
| 30 | 
            +
                      option :frontend_packages, type: :boolean, aliases: "-f", default: false, desc: "Use this flag to make PRs for the neeto frontend packages"
         | 
| 30 31 | 
             
                      def script
         | 
| 31 32 | 
             
                        Script.new(
         | 
| 32 33 | 
             
                          options[:repos], options[:path], options[:title], options[:branch], options[:description],
         | 
| 33 | 
            -
                          options[:nanos], options[:sandbox]).run
         | 
| 34 | 
            +
                          options[:nanos], options[:frontend_packages], options[:sandbox]).run
         | 
| 34 35 | 
             
                      end
         | 
| 35 36 | 
             
                    end
         | 
| 36 37 | 
             
                  end
         | 
| @@ -20,9 +20,7 @@ module Neetob | |
| 20 20 | 
             
                      end
         | 
| 21 21 |  | 
| 22 22 | 
             
                      def run
         | 
| 23 | 
            -
                        matching_repos = should_fix_nanos | 
| 24 | 
            -
                          add_org_suffix(find_all_matching_gems) :
         | 
| 25 | 
            -
                          find_all_matching_apps_or_repos(repos, :github, sandbox)
         | 
| 23 | 
            +
                        matching_repos = build_matching_repos_list(should_fix_nanos)
         | 
| 26 24 | 
             
                        @failed_repos = matching_repos.clone
         | 
| 27 25 | 
             
                        delete_and_create_temp_neetob_dir
         | 
| 28 26 | 
             
                        matching_repos.each do |repo|
         | 
| @@ -9,22 +9,22 @@ module Neetob | |
| 9 9 | 
             
                module Github
         | 
| 10 10 | 
             
                  module MakePr
         | 
| 11 11 | 
             
                    class Script < Base
         | 
| 12 | 
            -
                      attr_accessor :repos, :sandbox, :path_to_the_script_file, :pr_description, :should_fix_nanos
         | 
| 12 | 
            +
                      attr_accessor :repos, :sandbox, :path_to_the_script_file, :pr_description, :should_fix_nanos,
         | 
| 13 | 
            +
                        :should_fix_frontend_packages
         | 
| 13 14 |  | 
| 14 15 | 
             
                      def initialize(repos, path_to_the_script_file, pr_title,
         | 
| 15 | 
            -
                        branch_name, pr_description, should_fix_nanos, sandbox = false)
         | 
| 16 | 
            +
                        branch_name, pr_description, should_fix_nanos, should_fix_frontend_packages = false, sandbox = false)
         | 
| 16 17 | 
             
                        super(pr_title, branch_name)
         | 
| 17 18 | 
             
                        @repos = repos
         | 
| 18 19 | 
             
                        @sandbox = sandbox
         | 
| 19 20 | 
             
                        @path_to_the_script_file = path_to_the_script_file
         | 
| 20 21 | 
             
                        @pr_description = pr_description
         | 
| 21 22 | 
             
                        @should_fix_nanos = should_fix_nanos
         | 
| 23 | 
            +
                        @should_fix_frontend_packages = should_fix_frontend_packages
         | 
| 22 24 | 
             
                      end
         | 
| 23 25 |  | 
| 24 26 | 
             
                      def run
         | 
| 25 | 
            -
                        matching_repos = should_fix_nanos  | 
| 26 | 
            -
                          add_org_suffix(find_all_matching_gems) :
         | 
| 27 | 
            -
                          find_all_matching_apps_or_repos(repos, :github, sandbox)
         | 
| 27 | 
            +
                        matching_repos = build_matching_repos_list(should_fix_nanos, should_fix_frontend_packages)
         | 
| 28 28 | 
             
                        delete_and_create_temp_neetob_dir
         | 
| 29 29 | 
             
                        matching_repos.each do |repo|
         | 
| 30 30 | 
             
                          ui.info("\n  Working on #{repo}  \n")
         | 
| @@ -1,37 +1,99 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
            require_relative "base"
         | 
| 3 | 
            +
            require_relative "./make_pr/base"
         | 
| 4 4 |  | 
| 5 5 | 
             
            module Neetob
         | 
| 6 6 | 
             
              class CLI
         | 
| 7 7 | 
             
                module Github
         | 
| 8 | 
            -
                  class Search < Base
         | 
| 9 | 
            -
                    attr_accessor :repos, :key_to_search, :search_file_path, :sandbox
         | 
| 8 | 
            +
                  class Search < MakePr::Base
         | 
| 9 | 
            +
                    attr_accessor :repos, :key_to_search, :search_file_path, :replacement_term, :sandbox
         | 
| 10 10 |  | 
| 11 | 
            -
                    def initialize(repos, key_to_search, search_file_path, sandbox = false)
         | 
| 12 | 
            -
                      super()
         | 
| 13 | 
            -
                      @repos = repos
         | 
| 11 | 
            +
                    def initialize(repos, key_to_search, search_file_path, replacement_term, sandbox = false)
         | 
| 14 12 | 
             
                      @key_to_search = key_to_search
         | 
| 13 | 
            +
                      @replacement_term = replacement_term
         | 
| 14 | 
            +
                      branch_name = build_branch_name
         | 
| 15 | 
            +
                      pr_title = build_pr_title
         | 
| 16 | 
            +
                      super(pr_title, branch_name)
         | 
| 15 17 | 
             
                      @search_file_path = search_file_path
         | 
| 18 | 
            +
                      @repos = repos
         | 
| 16 19 | 
             
                      @sandbox = sandbox
         | 
| 17 20 | 
             
                    end
         | 
| 18 21 |  | 
| 19 22 | 
             
                    def run
         | 
| 20 23 | 
             
                      matching_repos = find_all_matching_apps_or_repos(repos, :github, sandbox)
         | 
| 21 24 | 
             
                      matching_repos.each do |repo|
         | 
| 25 | 
            +
                        ui.info("\nSearching in #{repo}")
         | 
| 26 | 
            +
                        clone_repo_in_tmp_dir(repo)
         | 
| 22 27 | 
             
                        begin
         | 
| 23 | 
            -
                           | 
| 24 | 
            -
             | 
| 25 | 
            -
                           | 
| 28 | 
            +
                          if replacement_term.nil?
         | 
| 29 | 
            +
                            find_and_print_matching_lines(repo)
         | 
| 30 | 
            +
                          else
         | 
| 31 | 
            +
                            check_and_delete_remote_branch(repo)
         | 
| 32 | 
            +
                            find_and_replace_keyword(repo)
         | 
| 33 | 
            +
                            ui.say("No changes were made to #{repo}, check if keyword exists.") and next if !are_changes_made?(repo)
         | 
| 26 34 |  | 
| 27 | 
            -
             | 
| 28 | 
            -
                             | 
| 35 | 
            +
                            ui.info(add_commmit_and_push_changes(repo))
         | 
| 36 | 
            +
                            delete_local_feature_branch(repo)
         | 
| 37 | 
            +
                            pull_request = client.create_pull_request(repo, "main", branch_name, pr_title)
         | 
| 38 | 
            +
                            ui.success("Successfully replaced \"#{key_to_search}\" with \"#{replacement_term}\" in #{repo}")
         | 
| 39 | 
            +
                            ui.success("PR Link:- #{pull_request.html_url}")
         | 
| 29 40 | 
             
                          end
         | 
| 30 41 | 
             
                        rescue StandardError => e
         | 
| 31 42 | 
             
                          ExceptionHandler.new(e).process
         | 
| 32 43 | 
             
                        end
         | 
| 33 44 | 
             
                      end
         | 
| 45 | 
            +
                      `rm -rf /tmp/neetob`
         | 
| 34 46 | 
             
                    end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                    private
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                      def search_for_keyword(repo)
         | 
| 51 | 
            +
                        `#{cd_to_repo_in_tmp_dir(repo)} && \
         | 
| 52 | 
            +
                          find . -type f -iregex "#{search_file_path}" | xargs grep -E "#{key_to_search}"`
         | 
| 53 | 
            +
                      end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                      def find_and_print_matching_lines(repo)
         | 
| 56 | 
            +
                        files_with_matching_lines = find_matching_files(repo)
         | 
| 57 | 
            +
                        files_with_matching_lines.empty? ? ui.error("Keyword not found")
         | 
| 58 | 
            +
                          : print_matching_lines(files_with_matching_lines)
         | 
| 59 | 
            +
                      end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                      def find_matching_files(repo)
         | 
| 62 | 
            +
                        result = search_for_keyword(repo)
         | 
| 63 | 
            +
                        result.each_line.reduce({}) do |lines_by_file, line|
         | 
| 64 | 
            +
                          filename, content = line.split(":", 2)
         | 
| 65 | 
            +
                          lines_by_file[filename] ||= []
         | 
| 66 | 
            +
                          lines_by_file[filename] << content.strip
         | 
| 67 | 
            +
                          lines_by_file
         | 
| 68 | 
            +
                        end
         | 
| 69 | 
            +
                      end
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                      def print_matching_lines(files_with_matching_lines)
         | 
| 72 | 
            +
                        files_with_matching_lines.each do |file, list_of_lines|
         | 
| 73 | 
            +
                          ui.info("#{file}")
         | 
| 74 | 
            +
                          list_of_lines.each { |line| ui.success(" ↳#{line}") }
         | 
| 75 | 
            +
                        end
         | 
| 76 | 
            +
                      end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                      def are_changes_made?(repo)
         | 
| 79 | 
            +
                        changes_made = `#{cd_to_repo_in_tmp_dir(repo)} && git checkout #{branch_name} && git status`
         | 
| 80 | 
            +
                        !changes_made.include?("nothing to commit")
         | 
| 81 | 
            +
                      end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                      def find_and_replace_keyword(repo)
         | 
| 84 | 
            +
                        `#{cd_to_repo_in_tmp_dir(repo)} && \
         | 
| 85 | 
            +
                         find . -type f -regex #{search_file_path} -print0 | \
         | 
| 86 | 
            +
                         xargs -0 sed -i '' 's/#{key_to_search}/#{replacement_term}/g'`
         | 
| 87 | 
            +
                      end
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                      def build_pr_title
         | 
| 90 | 
            +
                        "Replaced \"#{key_to_search}\" with \"#{replacement_term}\""
         | 
| 91 | 
            +
                      end
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                      def build_branch_name
         | 
| 94 | 
            +
                        branch_name = "search-#{key_to_search}-and-replace-with-#{replacement_term}"
         | 
| 95 | 
            +
                        branch_name.gsub(/\W/, "_")
         | 
| 96 | 
            +
                      end
         | 
| 35 97 | 
             
                  end
         | 
| 36 98 | 
             
                end
         | 
| 37 99 | 
             
              end
         | 
    
        data/lib/neetob/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: neetob
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.4. | 
| 4 | 
            +
              version: 0.4.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Udai Gupta
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2023-04- | 
| 11 | 
            +
            date: 2023-04-25 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: thor
         |