From f8ef70bd06cee2a63d3beed9c3c7be22d5e1588c Mon Sep 17 00:00:00 2001 From: Magne Land Date: Fri, 26 Mar 2021 14:39:24 -0700 Subject: [PATCH 1/3] Fix JRuby job and refactor CircleCI config Bump CircleCI ruby orb to `circleci/ruby@1.1.2` Combine `lint` and `test` / `test_jruby` jobs. JRuby job now installs "java" gems correctly. Heavily inspired by `rubocop-rails` config. See: https://github.com/rubocop/rubocop-rails/blob/f3a00977d8621a2af037cc8625cd2734e2c11a56/.circleci/config.yml --- .circleci/config.yml | 75 ++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 48 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3f16f92a8..d3de2fc07 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,61 +4,40 @@ # version: 2.1 orbs: - ruby: circleci/ruby@0.2.2 - -shared_steps: &shared_steps - steps: - - run: ruby -v - - checkout - - ruby/load-cache - - run: gem install bundler:2.1.4 - - ruby/install-deps - - ruby/save-cache - - ruby/run-tests + ruby: circleci/ruby@1.1.2 jobs: - lint: - environment: - BUNDLE_PATH: vendor/bundle - executor: ruby/default - steps: - - run: ruby -v - - checkout - - ruby/load-cache - - ruby/install-deps - - run: bundle exec rubocop - - test: + rspec: parameters: - tag: + image: + description: "Name of the Docker image." type: string + default: "cimg/ruby" + docker: + - image: << parameters.image >> environment: - BUNDLE_PATH: vendor/bundle - executor: - name: ruby/default - tag: << parameters.tag >> - parallelism: 1 - <<: *shared_steps - - test_jruby: - environment: - BUNDLE_PATH: vendor/bundle JRUBY_OPTS: "--debug" - docker: - - image: circleci/jruby:9.2 - <<: *shared_steps + steps: + - checkout + - run: bundle install + - run: bundle exec rubocop + - run: bundle exec rspec workflows: - version: 2 build: jobs: - - lint - - test_jruby: - requires: - - lint - - test: - matrix: - parameters: - tag: ["2.5", "2.6", "2.7"] - requires: - - lint + - rspec: + name: Ruby 2.5 + image: cimg/ruby:2.5 + - rspec: + name: Ruby 2.6 + image: cimg/ruby:2.6 + - rspec: + name: Ruby 2.7 + image: cimg/ruby:2.7 + - rspec: + name: Ruby 3.0 + image: cimg/ruby:3.0 + - rspec: + name: JRuby 9.2 + image: circleci/jruby:9.2 From 2528b1a49ae7d9c0af79cc1db64a0bb16bb9c799 Mon Sep 17 00:00:00 2001 From: Magne Land Date: Fri, 26 Mar 2021 18:12:23 -0700 Subject: [PATCH 2/3] Fix Ruby 3 kwargs usage See: https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/ --- lib/github_changelog_generator/octo_fetcher.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/github_changelog_generator/octo_fetcher.rb b/lib/github_changelog_generator/octo_fetcher.rb index 641245154..95b48ab7d 100644 --- a/lib/github_changelog_generator/octo_fetcher.rb +++ b/lib/github_changelog_generator/octo_fetcher.rb @@ -161,7 +161,7 @@ def fetch_closed_issues_and_pr page_i = 0 count_pages = calculate_pages(client, "issues", closed_pr_options) - iterate_pages(client, "issues", closed_pr_options) do |new_issues| + iterate_pages(client, "issues", **closed_pr_options) do |new_issues| page_i += PER_PAGE_NUMBER print_in_same_line("Fetching issues... #{page_i}/#{count_pages * PER_PAGE_NUMBER}") issues.concat(new_issues) @@ -185,7 +185,7 @@ def fetch_closed_pull_requests page_i = 0 count_pages = calculate_pages(client, "pull_requests", options) - iterate_pages(client, "pull_requests", options) do |new_pr| + iterate_pages(client, "pull_requests", **options) do |new_pr| page_i += PER_PAGE_NUMBER log_string = "Fetching merged dates... #{page_i}/#{count_pages * PER_PAGE_NUMBER}" print_in_same_line(log_string) @@ -215,7 +215,7 @@ def fetch_events_async(issues) issues.each do |issue| semaphore.async do issue["events"] = [] - iterate_pages(client, "issue_events", issue["number"], preview) do |new_event| + iterate_pages(client, "issue_events", issue["number"], **preview) do |new_event| issue["events"].concat(new_event) end issue["events"] = issue["events"].map { |event| stringify_keys_deep(event.to_hash) } From d7a7b50b6e4702141a4b6af344080a662139d2e8 Mon Sep 17 00:00:00 2001 From: Magne Land Date: Fri, 26 Mar 2021 18:13:20 -0700 Subject: [PATCH 3/3] Fix YARD comments Using RubyMine feature to correct this. See: https://www.jetbrains.com/help/ruby/documenting-source-code.html --- .../generator/generator_processor.rb | 3 ++- lib/github_changelog_generator/octo_fetcher.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/github_changelog_generator/generator/generator_processor.rb b/lib/github_changelog_generator/generator/generator_processor.rb index f452f0133..a3bb31976 100644 --- a/lib/github_changelog_generator/generator/generator_processor.rb +++ b/lib/github_changelog_generator/generator/generator_processor.rb @@ -156,7 +156,7 @@ def include_issues_by_labels(issues) filter_wo_labels(filtered_issues) end - # @param [Array] issues Issues & PRs to filter when without labels + # @param [Array] items Issues & PRs to filter when without labels # @return [Array] Issues & PRs without labels or empty array if # add_issues_wo_labels or add_pr_wo_labels are false def filter_wo_labels(items) @@ -170,6 +170,7 @@ def filter_wo_labels(items) end # @todo Document this + # @param [Object] issues def filter_by_include_labels(issues) if options[:include_labels].nil? issues diff --git a/lib/github_changelog_generator/octo_fetcher.rb b/lib/github_changelog_generator/octo_fetcher.rb index 95b48ab7d..57a15590d 100644 --- a/lib/github_changelog_generator/octo_fetcher.rb +++ b/lib/github_changelog_generator/octo_fetcher.rb @@ -105,6 +105,9 @@ def get_all_tags # Returns the number of pages for a API call # # @return [Integer] number of pages for this API call in total + # @param [Object] request_options + # @param [Object] method + # @param [Object] client def calculate_pages(client, method, request_options) # Makes the first API call so that we can call last_response check_github_response do @@ -335,6 +338,7 @@ def default_branch @default_branch ||= client.repository(user_project)[:default_branch] end + # @param [Object] name def commits_in_branch(name) @branches ||= client.branches(user_project).map { |branch| [branch[:name], branch] }.to_h @@ -357,6 +361,8 @@ def fetch_tag_shas(tags) private + # @param [Set] shas + # @param [Object] sha def commits_in_tag(sha, shas = Set.new) # Reduce multiple runs for the same tag return @commits_in_tag_cache[sha] if @commits_in_tag_cache.key?(sha) @@ -382,6 +388,7 @@ def commits_in_tag(sha, shas = Set.new) shas end + # @param [Object] indata def stringify_keys_deep(indata) case indata when Array @@ -405,10 +412,13 @@ def stringify_keys_deep(indata) # # @param [Octokit::Client] client # @param [String] method (eg. 'tags') + # @param [Array] arguments + # @param [Async::Semaphore] parent # # @yield [Sawyer::Resource] An OctoKit-provided response (which can be empty) # # @return [void] + # @param [Hash] options def iterate_pages(client, method, *arguments, parent: nil, **options) options = DEFAULT_REQUEST_OPTIONS.merge(options) @@ -442,6 +452,7 @@ def iterate_pages(client, method, *arguments, parent: nil, **options) # This is wrapper with rescue block # # @return [Object] returns exactly the same, what you put in the block, but wrap it with begin-rescue block + # @param [Proc] block def check_github_response(&block) Retriable.retriable(retry_options, &block) rescue MovedPermanentlyError => e @@ -453,6 +464,8 @@ def check_github_response(&block) end # Presents the exception, and the aborts with the message. + # @param [Object] message + # @param [Object] error def fail_with_message(error, message) Helper.log.error("#{error.class}: #{error.message}") sys_abort(message) @@ -483,6 +496,7 @@ def retry_callback end end + # @param [Object] msg def sys_abort(msg) abort(msg) end