From db4b05b0a3d42a6d4cbb4ae6317b9283725691b4 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Fri, 21 Feb 2020 17:35:58 +0700 Subject: [PATCH 001/128] add Marco Ferrari as co-author to gemspec --- github_changelog_generator.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github_changelog_generator.gemspec b/github_changelog_generator.gemspec index 638b2c5..bb54b0c 100644 --- a/github_changelog_generator.gemspec +++ b/github_changelog_generator.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |spec| spec.version = GitHubChangelogGenerator::VERSION spec.required_ruby_version = ">= 2.3.0" - spec.authors = ["Petr Korolev", "Olle Jonsson"] + spec.authors = ["Petr Korolev", "Olle Jonsson", "Marco Ferrari"] spec.email = "sky4winder+github_changelog_generator@gmail.com" spec.summary = "Script, that automatically generate changelog from your tags, issues, labels and pull requests." From 6f161ef7ee19984b3b03f270c7e59dc855e581a7 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Sat, 22 Feb 2020 15:16:16 +0700 Subject: [PATCH 002/128] added gitter --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 68082f1..87a8c83 100644 --- a/README.md +++ b/README.md @@ -348,6 +348,9 @@ We have collected notes on how to contribute to this project in [CONTRIBUTING.md [CONTRIBUTING.md]: CONTRIBUTING.md +## Contact us +Feel free to ask your questions [gitter.im chat])https://gitter.im/github-changelog-generator) + ## License Github Changelog Generator is released under the [MIT License](http://www.opensource.org/licenses/MIT). From 78a21d2b330ed3bcdb92722eab5c2f8fb03212a3 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Sat, 22 Feb 2020 15:20:23 +0700 Subject: [PATCH 003/128] remove outdated info --- CONTRIBUTING.md | 28 ++++++++++++++++++++++++++++ README.md | 28 +--------------------------- bin/git-generate-changelog | 5 ----- bin/github_changelog_generator | 5 ----- 4 files changed, 29 insertions(+), 37 deletions(-) delete mode 100755 bin/git-generate-changelog delete mode 100755 bin/github_changelog_generator diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4ce1d49..6d5b641 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,6 +11,34 @@ Bug reports and pull requests from users are what keep this project working. 5. Publish the branch (`git push origin my-new-feature`) 6. Create a new Pull Request +## Running for development + +Make sure you have `ruby`, `gem` and `bundle` installed locally. + +If you don't: `gem install bundler` + +#### Step 1: Install requirements + +``` +bundle install +``` + +#### Step 2: Install linters: overcommit, rubocop + +``` +overcommit --install +``` + +#### Step 3: Run & debug + +TBD + +#### Step 4: Test it + +``` +bundle exec rake +``` + ## Checking your work You can test your workflow with changelog generator with diff --git a/README.md b/README.md index 87a8c83..02faed8 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,6 @@ # github-changelog-generator ![GitHub Logo](../master/images/logo.jpg) -#### Update: - -🖖 Keep it alive: We need more Collaborators to github-changelog-generator [#727](https://github.com/github-changelog-generator/github-changelog-generator/issues/727) - ---- Gitlab for GitlabFetcher --- .../generator/generator.rb | 2 +- .../gitlab_fetcher.rb | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/github_changelog_generator/generator/generator.rb b/lib/github_changelog_generator/generator/generator.rb index 14e5b4f..80723c7 100644 --- a/lib/github_changelog_generator/generator/generator.rb +++ b/lib/github_changelog_generator/generator/generator.rb @@ -41,7 +41,7 @@ class Generator def initialize(options = {}) @options = options @tag_times_hash = {} - @fetcher = options[:gitlab] ? GitHubChangelogGenerator::GitlabFetcher.new(options) : GitHubChangelogGenerator::OctoFetcher.new(options) + @fetcher = options[:gitlab] ? GitLabChangelogGenerator::GitlabFetcher.new(options) : GitHubChangelogGenerator::OctoFetcher.new(options) @sections = [] end diff --git a/lib/github_changelog_generator/gitlab_fetcher.rb b/lib/github_changelog_generator/gitlab_fetcher.rb index ab35059..7305c0b 100644 --- a/lib/github_changelog_generator/gitlab_fetcher.rb +++ b/lib/github_changelog_generator/gitlab_fetcher.rb @@ -4,18 +4,18 @@ require "retriable" require "gitlab" -module GitHubChangelogGenerator +module GitLabChangelogGenerator # A Fetcher responsible for all requests to GitHub and all basic manipulation with related data # (such as filtering, validating, e.t.c) # # Example: - # fetcher = GitHubChangelogGenerator::OctoFetcher.new(options) + # fetcher = GitLabChangelogGenerator::GitlabFetcher.new(options) class GitlabFetcher PER_PAGE_NUMBER = 100 MAX_THREAD_NUMBER = 25 MAX_FORBIDDEN_RETRIES = 100 CHANGELOG_GITHUB_TOKEN = "CHANGELOG_GITHUB_TOKEN" - GH_RATE_LIMIT_EXCEEDED_MSG = "Warning: Can't finish operation: GitHub API rate limit exceeded, changelog may be " \ + RATE_LIMIT_EXCEEDED_MSG = "Warning: Can't finish operation: GitHub API rate limit exceeded, changelog may be " \ "missing some issues. You can limit the number of issues fetched using the `--max-issues NUM` argument." NO_TOKEN_PROVIDED = "Warning: No token provided (-t option) and variable $CHANGELOG_GITHUB_TOKEN was not found. " \ "This script can make only 50 requests to GitHub API per hour without token!" @@ -55,7 +55,7 @@ def find_project_id def gitlab_options result = {} - access_token = fetch_github_token + access_token = fetch_auth_token result[:private_token] = access_token if access_token endpoint = @options[:github_endpoint] result[:endpoint] = endpoint if endpoint @@ -371,7 +371,7 @@ def check_response rescue Gitlab::Error::Forbidden => e fail_with_message(e, "Exceeded retry limit") rescue Gitlab::Error::Unauthorized => e - fail_with_message(e, "Error: wrong GitHub token") + fail_with_message(e, "Error: wrong GitLab token") end # Presents the exception, and the aborts with the message. @@ -400,7 +400,7 @@ def retry_callback proc do |exception, try, elapsed_time, next_interval| Helper.log.warn("RETRY - #{exception.class}: '#{exception.message}'") Helper.log.warn("#{try} tries in #{elapsed_time} seconds and #{next_interval} seconds until the next try") - Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG + Helper.log.warn RATE_LIMIT_EXCEEDED_MSG Helper.log.warn @client.rate_limit end end @@ -425,15 +425,15 @@ def print_empty_line # otherwise try to fetch it from CHANGELOG_GITHUB_TOKEN env variable. # # @return [String] - def fetch_github_token - env_var = @options[:token].presence || ENV["CHANGELOG_GITHUB_TOKEN"] + def fetch_auth_token + env_var = @options[:token].presence || ENV["CHANGELOG_GITLAB_TOKEN"] Helper.log.warn NO_TOKEN_PROVIDED unless env_var env_var end - # @return [String] helper to return Github "user/project" + # @return [String] "user/project" slug def user_project "#{@options[:user]}/#{@options[:project]}" end From 5056f1d71dacb06c7a68abd00abc96151083dc09 Mon Sep 17 00:00:00 2001 From: kreczko Date: Thu, 1 Nov 2018 11:03:29 +0000 Subject: [PATCH 115/128] added Gitlab URI example --- lib/github_changelog_generator/gitlab_fetcher.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/github_changelog_generator/gitlab_fetcher.rb b/lib/github_changelog_generator/gitlab_fetcher.rb index 7305c0b..997ce7d 100644 --- a/lib/github_changelog_generator/gitlab_fetcher.rb +++ b/lib/github_changelog_generator/gitlab_fetcher.rb @@ -440,7 +440,7 @@ def user_project # Returns Hash of all querystring variables in given URI. # - # @param [String] uri eg. https://api.github.com/repositories/43914960/tags?page=37&foo=1 + # @param [String] uri eg. https://gitlab.example.com/api/v4/projects/43914960/repository/tags?page=37&foo=1 # @return [Hash] of all GET variables. eg. { 'page' => 37, 'foo' => 1 } def querystring_as_hash(uri) Hash[URI.decode_www_form(URI(uri).query || "")] From 0330e6140045fea7feec30a4b2139dc0a41fe939 Mon Sep 17 00:00:00 2001 From: kreczko Date: Thu, 1 Nov 2018 14:12:03 +0000 Subject: [PATCH 116/128] missing change from Github->Gitlab change: Helper --> GitHubChangelogGenerator::Helper --- .../gitlab_fetcher.rb | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/github_changelog_generator/gitlab_fetcher.rb b/lib/github_changelog_generator/gitlab_fetcher.rb index 997ce7d..7655a6b 100644 --- a/lib/github_changelog_generator/gitlab_fetcher.rb +++ b/lib/github_changelog_generator/gitlab_fetcher.rb @@ -85,10 +85,10 @@ def fetch_tags print_empty_line if tags.count == 0 - Helper.log.warn "Warning: Can't find any tags in repo. \ + GitHubChangelogGenerator::Helper.log.warn "Warning: Can't find any tags in repo. \ Make sure, that you push tags to remote repo via 'git push --tags'" else - Helper.log.info "Found #{tags.count} tags" + GitHubChangelogGenerator::Helper.log.info "Found #{tags.count} tags" end # tags are a Sawyer::Resource. Convert to hash tags.map { |resource| stringify_keys_deep(resource.to_hash) } @@ -117,7 +117,7 @@ def fetch_closed_issues_and_pr end print_empty_line - Helper.log.info "Received issues: #{issues.count}" + GitHubChangelogGenerator::Helper.log.info "Received issues: #{issues.count}" # separate arrays of issues and pull requests: [issues.map { |issue| stringify_keys_deep(issue.to_hash) }, fetch_closed_pull_requests] @@ -145,7 +145,7 @@ def fetch_closed_pull_requests print_empty_line - Helper.log.info "Pull Request count: #{pull_requests.count}" + GitHubChangelogGenerator::Helper.log.info "Pull Request count: #{pull_requests.count}" pull_requests.map { |pull_request| stringify_keys_deep(pull_request.to_hash) } end @@ -193,7 +193,7 @@ def fetch_events_async(issues) # to clear line from prev print print_empty_line - Helper.log.info "Fetching events for issues and PR: #{i}" + GitHubChangelogGenerator::Helper.log.info "Fetching events for issues and PR: #{i}" end # Fetch comments for PRs and add them to "comments" @@ -325,7 +325,7 @@ def fetch_tag_shas_async(tags) # to clear line from prev print print_empty_line - Helper.log.info "Fetching SHAs for tags: #{i}" + GitHubChangelogGenerator::Helper.log.info "Fetching SHAs for tags: #{i}" nil end @@ -376,7 +376,7 @@ def check_response # Presents the exception, and the aborts with the message. def fail_with_message(error, message) - Helper.log.error("#{error.class}: #{error.message}") + GitHubChangelogGenerator::Helper.log.error("#{error.class}: #{error.message}") sys_abort(message) end @@ -398,10 +398,10 @@ def sleep_base_interval def retry_callback proc do |exception, try, elapsed_time, next_interval| - Helper.log.warn("RETRY - #{exception.class}: '#{exception.message}'") - Helper.log.warn("#{try} tries in #{elapsed_time} seconds and #{next_interval} seconds until the next try") - Helper.log.warn RATE_LIMIT_EXCEEDED_MSG - Helper.log.warn @client.rate_limit + GitHubChangelogGenerator::Helper.log.warn("RETRY - #{exception.class}: '#{exception.message}'") + GitHubChangelogGenerator::Helper.log.warn("#{try} tries in #{elapsed_time} seconds and #{next_interval} seconds until the next try") + GitHubChangelogGenerator::Helper.log.warn RATE_LIMIT_EXCEEDED_MSG + GitHubChangelogGenerator::Helper.log.warn @client.rate_limit end end @@ -428,7 +428,7 @@ def print_empty_line def fetch_auth_token env_var = @options[:token].presence || ENV["CHANGELOG_GITLAB_TOKEN"] - Helper.log.warn NO_TOKEN_PROVIDED unless env_var + GitHubChangelogGenerator::Helper.log.warn NO_TOKEN_PROVIDED unless env_var env_var end From 612c9db3eb7b72154e2f02bd739b147677cf5d34 Mon Sep 17 00:00:00 2001 From: kreczko Date: Thu, 1 Nov 2018 14:37:15 +0000 Subject: [PATCH 117/128] CHANGELOG_GITHUB_TOKEN --> CHANGELOG_AUTH_TOKEN for gitlab fetcher --- lib/github_changelog_generator/gitlab_fetcher.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/github_changelog_generator/gitlab_fetcher.rb b/lib/github_changelog_generator/gitlab_fetcher.rb index 7655a6b..3bb9fce 100644 --- a/lib/github_changelog_generator/gitlab_fetcher.rb +++ b/lib/github_changelog_generator/gitlab_fetcher.rb @@ -14,10 +14,10 @@ class GitlabFetcher PER_PAGE_NUMBER = 100 MAX_THREAD_NUMBER = 25 MAX_FORBIDDEN_RETRIES = 100 - CHANGELOG_GITHUB_TOKEN = "CHANGELOG_GITHUB_TOKEN" + CHANGELOG_AUTH_TOKEN = "CHANGELOG_AUTH_TOKEN" RATE_LIMIT_EXCEEDED_MSG = "Warning: Can't finish operation: GitHub API rate limit exceeded, changelog may be " \ "missing some issues. You can limit the number of issues fetched using the `--max-issues NUM` argument." - NO_TOKEN_PROVIDED = "Warning: No token provided (-t option) and variable $CHANGELOG_GITHUB_TOKEN was not found. " \ + NO_TOKEN_PROVIDED = "Warning: No token provided (-t option) and variable $CHANGELOG_AUTH_TOKEN was not found. " \ "This script can make only 50 requests to GitHub API per hour without token!" # @param options [Hash] Options passed in @@ -422,11 +422,11 @@ def print_empty_line end # Returns GitHub token. First try to use variable, provided by --token option, - # otherwise try to fetch it from CHANGELOG_GITHUB_TOKEN env variable. + # otherwise try to fetch it from CHANGELOG_AUTH_TOKEN env variable. # # @return [String] def fetch_auth_token - env_var = @options[:token].presence || ENV["CHANGELOG_GITLAB_TOKEN"] + env_var = @options[:token].presence || ENV["CHANGELOG_AUTH_TOKEN"] GitHubChangelogGenerator::Helper.log.warn NO_TOKEN_PROVIDED unless env_var From 3557c26b8d291598e26b24b2c58782cfddac9184 Mon Sep 17 00:00:00 2001 From: kreczko Date: Thu, 1 Nov 2018 15:03:16 +0000 Subject: [PATCH 118/128] fixed RuboCop issues for gitlab_fetcher --- .../generator/generator_fetcher.rb | 17 +++++++++++------ .../gitlab_fetcher.rb | 14 +++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/github_changelog_generator/generator/generator_fetcher.rb b/lib/github_changelog_generator/generator/generator_fetcher.rb index 73d4d5c..ddc2b54 100644 --- a/lib/github_changelog_generator/generator/generator_fetcher.rb +++ b/lib/github_changelog_generator/generator/generator_fetcher.rb @@ -73,12 +73,7 @@ def associate_tagged_prs(tags, prs, total) # https://developer.github.com/v3/pulls/#get-a-single-pull-request vs. # https://developer.github.com/v3/pulls/#list-pull-requests # gitlab API has this - merge_commit_sha = nil - if pr.has_key?("merge_commit_sha") - merge_commit_sha = pr["merge_commit_sha"] - elsif pr["events"] && (event = pr["events"].find { |e| e["event"] == "merged" }) - merge_commit_sha = event["commit_id"] - end + merge_commit_sha = try_merge_commit_sha_from_gitlab(pr) if merge_commit_sha # Iterate tags.reverse (oldest to newest) to find first tag of each PR. if (oldest_tag = tags.reverse.find { |tag| tag["shas_in_tag"].include?(merge_commit_sha) }) @@ -101,6 +96,16 @@ def associate_tagged_prs(tags, prs, total) end end + def try_merge_commit_sha_from_gitlab(merge_request) + merge_commit_sha = nil + if merge_request.key?("merge_commit_sha") + merge_commit_sha = merge_request["merge_commit_sha"] + elsif merge_request["events"] && (event = merge_request["events"].find { |e| e["event"] == "merged" }) + merge_commit_sha = event["commit_id"] + end + merge_commit_sha + end + # Associate merged PRs by the HEAD of the release branch. If no # --release-branch was specified, then the github default branch is used. # diff --git a/lib/github_changelog_generator/gitlab_fetcher.rb b/lib/github_changelog_generator/gitlab_fetcher.rb index 3bb9fce..06a095d 100644 --- a/lib/github_changelog_generator/gitlab_fetcher.rb +++ b/lib/github_changelog_generator/gitlab_fetcher.rb @@ -46,9 +46,7 @@ def initialize(options = {}) def find_project_id project_id = nil @client.project_search(@project).auto_paginate do |project| - if project.namespace.name.eql? @user - project_id = project.id - end + project_id = project.id if project.namespace.name.eql? @user end project_id end @@ -79,7 +77,7 @@ def get_all_tags def fetch_tags tags = [] - @client.tags(@project_id, DEFAULT_REQUEST_OPTIONS).auto_paginate do |new_tag| + @client.tags(@project_id, DEFAULT_REQUEST_OPTIONS).auto_paginate do |new_tag| tags.push(new_tag) end print_empty_line @@ -139,7 +137,7 @@ def fetch_closed_pull_requests new_pr["pull_request"] = true new_pr["user"] = { login: new_pr["author"]["username"], html_url: new_pr["author"]["web_url"] } # to make it work with older gitlab version or repos that lived across versions - new_pr["merge_commit_sha"] = new_pr["merge_commit_sha"].nil? ? new_pr["sha"]: new_pr["merge_commit_sha"] + new_pr["merge_commit_sha"] = new_pr["merge_commit_sha"].nil? ? new_pr["sha"] : new_pr["merge_commit_sha"] pull_requests.push(new_pr) end @@ -156,10 +154,8 @@ def fetch_closed_pull_requests def fetch_events_async(issues) i = 0 threads = [] - options = { } - if issues.empty? - return - end + options = {} + return if issues.empty? options[:target_type] = issues.first["merged_at"].nil? ? "issue" : "merge_request" issue_events = [] @client.project_events(@project_id, options).auto_paginate do |event| From 0a3082bbbe4eb7d1b3ccfbd7a3d100cb42a9cae9 Mon Sep 17 00:00:00 2001 From: kreczko Date: Thu, 1 Nov 2018 16:38:24 +0000 Subject: [PATCH 119/128] preliminary tests for gitlab_fetcher --- spec/unit/gitlab_fetcher_spec.rb | 541 +++++++++++++++++++++++++++++++ 1 file changed, 541 insertions(+) create mode 100644 spec/unit/gitlab_fetcher_spec.rb diff --git a/spec/unit/gitlab_fetcher_spec.rb b/spec/unit/gitlab_fetcher_spec.rb new file mode 100644 index 0000000..1935206 --- /dev/null +++ b/spec/unit/gitlab_fetcher_spec.rb @@ -0,0 +1,541 @@ +# frozen_string_literal: true + +describe GitLabChangelogGenerator::GitlabFetcher do + let(:options) do + { + user: "kreczko", + project: "changelog-testrepo", + github_endpoint: "https://gitlab.com/api/v4" + } + end + + let(:fetcher) { GitLabChangelogGenerator::GitlabFetcher.new(options) } + + describe "#check_response" do + context "when returns successfully" do + it "returns block value" do + expect(fetcher.send(:check_response) { 1 + 1 }).to eq(2) + end + end + + context "when raises GitLab::MissingCredentials" do + it "aborts" do + expect(fetcher).to receive(:sys_abort).with("Error: wrong AUTH token") + fetcher.send(:check_response) { raise(GitLab::MissingCredentials) } + end + end + + context "when raises GitLab::Forbidden" do + it "sleeps and retries and then aborts" do + retry_limit = GitLabChangelogGenerator::GitlabFetcher::MAX_FORBIDDEN_RETRIES - 1 + allow(fetcher).to receive(:sleep_base_interval).exactly(retry_limit).times.and_return(0) + + expect(fetcher).to receive(:sys_abort).with("Exceeded retry limit") + fetcher.send(:check_response) { raise(GitLab::Forbidden) } + end + end + end + + describe "#fetch_auth_token" do + token = GitLabChangelogGenerator::GitlabFetcher::CHANGELOG_AUTH_TOKEN + context "when token in ENV exist" do + before { stub_const("ENV", ENV.to_hash.merge(token => VALID_TOKEN)) } + subject { fetcher.send(:fetch_auth_token) } + it { is_expected.to eq(VALID_TOKEN) } + end + + context "when token in ENV is nil" do + before { stub_const("ENV", ENV.to_hash.merge(token => nil)) } + subject { fetcher.send(:fetch_auth_token) } + it { is_expected.to be_nil } + end + + context "when token in options and ENV is nil" do + let(:options) { { token: VALID_TOKEN } } + + before do + stub_const("ENV", ENV.to_hash.merge(token => nil)) + end + + subject { fetcher.send(:fetch_auth_token) } + it { is_expected.to eq(VALID_TOKEN) } + end + + context "when token in options and ENV specified" do + let(:options) { { token: VALID_TOKEN } } + + before do + stub_const("ENV", ENV.to_hash.merge(token => "no_matter_what")) + end + + subject { fetcher.send(:fetch_auth_token) } + it { is_expected.to eq(VALID_TOKEN) } + end + end + + describe "#get_all_tags" do + context "when fetch_tags returns tags" do + it "returns tags" do + mock_tags = ["tag"] + allow(fetcher).to receive(:fetch_tags).and_return(mock_tags) + expect(fetcher.get_all_tags).to eq(mock_tags) + end + end + end + + describe "#fetch_tags" do + context "when wrong token provided", :vcr do + let(:options) do + { + user: "skywinder", + project: "changelog_test", + token: INVALID_TOKEN, + github_endpoint: "https://gitlab.com/api/v4" + } + end + + it "should raise Unauthorized error" do + expect { fetcher.fetch_tags }.to raise_error SystemExit, "Error: wrong AUTH token" + end + end + + # TODO: swap for Gitlab API + context "when API call is valid", :vcr do + it "should return tags" do + expected_tags = [{ "name" => "v0.0.3", + "zipball_url" => + "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.3", + "tarball_url" => + "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.3", + "commit" => + { "sha" => "a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90", + "url" => + "https://api.github.com/repos/skywinder/changelog_test/commits/a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90" } }, + { "name" => "v0.0.2", + "zipball_url" => + "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.2", + "tarball_url" => + "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.2", + "commit" => + { "sha" => "9b35bb13dcd15b68e7bcbf10cde5eb937a54f710", + "url" => + "https://api.github.com/repos/skywinder/changelog_test/commits/9b35bb13dcd15b68e7bcbf10cde5eb937a54f710" } }, + { "name" => "v0.0.1", + "zipball_url" => + "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.1", + "tarball_url" => + "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.1", + "commit" => + { "sha" => "4c2d6d1ed58bdb24b870dcb5d9f2ceed0283d69d", + "url" => + "https://api.github.com/repos/skywinder/changelog_test/commits/4c2d6d1ed58bdb24b870dcb5d9f2ceed0283d69d" } }, + { "name" => "0.0.4", + "zipball_url" => + "https://api.github.com/repos/skywinder/changelog_test/zipball/0.0.4", + "tarball_url" => + "https://api.github.com/repos/skywinder/changelog_test/tarball/0.0.4", + "commit" => + { "sha" => "ece0c3ab7142b21064b885061c55ede00ef6ce94", + "url" => + "https://api.github.com/repos/skywinder/changelog_test/commits/ece0c3ab7142b21064b885061c55ede00ef6ce94" } }] + + expect(fetcher.fetch_tags).to eq(expected_tags) + end + + it "should return tags count" do + tags = fetcher.fetch_tags + expect(tags.size).to eq(4) + end + end + end + + describe "#fetch_closed_issues_and_pr" do + context "when API call is valid", :vcr do + it "returns issues" do + issues, pull_requests = fetcher.fetch_closed_issues_and_pr + expect(issues.size).to eq(7) + expect(pull_requests.size).to eq(14) + end + + it "returns issue with proper key/values" do + issues, _pull_requests = fetcher.fetch_closed_issues_and_pr + + expected_issue = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", + "repository_url" => "https://api.github.com/repos/skywinder/changelog_test", + "labels_url" => + "https://api.github.com/repos/skywinder/changelog_test/issues/14/labels{/name}", + "comments_url" => + "https://api.github.com/repos/skywinder/changelog_test/issues/14/comments", + "events_url" => + "https://api.github.com/repos/skywinder/changelog_test/issues/14/events", + "html_url" => "https://github.com/skywinder/changelog_test/issues/14", + "id" => 95_419_412, + "number" => 14, + "title" => "Issue closed from commit from PR", + "user" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => + "https://api.github.com/users/skywinder/following{/other_user}", + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => + "https://api.github.com/users/skywinder/starred{/owner}{/repo}", + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "received_events_url" => + "https://api.github.com/users/skywinder/received_events", + "type" => "User", + "site_admin" => false }, + "labels" => [], + "state" => "closed", + "locked" => false, + "assignee" => nil, + "assignees" => [], + "milestone" => nil, + "comments" => 0, + "created_at" => "2015-07-16T12:06:08Z", + "updated_at" => "2015-07-16T12:21:42Z", + "closed_at" => "2015-07-16T12:21:42Z", + "body" => "" } + + # Convert times to Time + expected_issue.each_pair do |k, v| + expected_issue[k] = Time.parse(v) if v =~ /^2015-/ + end + + expect(issues.first).to eq(expected_issue) + end + + it "returns pull request with proper key/values" do + _issues, pull_requests = fetcher.fetch_closed_issues_and_pr + + expected_pr = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21", + "repository_url" => "https://api.github.com/repos/skywinder/changelog_test", + "labels_url" => + "https://api.github.com/repos/skywinder/changelog_test/issues/21/labels{/name}", + "comments_url" => + "https://api.github.com/repos/skywinder/changelog_test/issues/21/comments", + "events_url" => + "https://api.github.com/repos/skywinder/changelog_test/issues/21/events", + "html_url" => "https://github.com/skywinder/changelog_test/pull/21", + "id" => 124_925_759, + "number" => 21, + "title" => "Merged br (should appear in change log with #20)", + "user" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => + "https://api.github.com/users/skywinder/following{/other_user}", + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => + "https://api.github.com/users/skywinder/starred{/owner}{/repo}", + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "received_events_url" => + "https://api.github.com/users/skywinder/received_events", + "type" => "User", + "site_admin" => false }, + "labels" => [], + "state" => "closed", + "locked" => false, + "assignee" => nil, + "assignees" => [], + "milestone" => nil, + "comments" => 0, + "created_at" => "2016-01-05T09:24:08Z", + "updated_at" => "2016-01-05T09:26:53Z", + "closed_at" => "2016-01-05T09:24:27Z", + "pull_request" => + { "url" => "https://api.github.com/repos/skywinder/changelog_test/pulls/21", + "html_url" => "https://github.com/skywinder/changelog_test/pull/21", + "diff_url" => "https://github.com/skywinder/changelog_test/pull/21.diff", + "patch_url" => "https://github.com/skywinder/changelog_test/pull/21.patch" }, + "body" => + "to test https://github.com/skywinder/github-changelog-generator/pull/305\r\nshould appear in change log with #20" } + + # Convert times to Time + expected_pr.each_pair do |k, v| + expected_pr[k] = Time.parse(v) if v =~ /^2016-01/ + end + + expect(pull_requests.first).to eq(expected_pr) + end + + it "returns issues with labels" do + issues, _pull_requests = fetcher.fetch_closed_issues_and_pr + expected = [[], [], ["Bug"], [], ["enhancement"], ["some label"], []] + expect(issues.map { |i| i["labels"].map { |l| l["name"] } }).to eq(expected) + end + + it "returns pull_requests with labels" do + _issues, pull_requests = fetcher.fetch_closed_issues_and_pr + expected = [[], [], [], [], [], ["enhancement"], [], [], ["invalid"], [], [], [], [], ["invalid"]] + expect(pull_requests.map { |i| i["labels"].map { |l| l["name"] } }).to eq(expected) + end + end + end + + describe "#fetch_closed_pull_requests" do + context "when API call is valid", :vcr do + it "returns pull requests" do + pull_requests = fetcher.fetch_closed_pull_requests + expect(pull_requests.size).to eq(14) + end + + it "returns correct pull request keys" do + pull_requests = fetcher.fetch_closed_pull_requests + + pr = pull_requests.first + expect(pr.keys).to eq(%w[url id html_url diff_url patch_url issue_url number state locked title user body created_at updated_at closed_at merged_at merge_commit_sha assignee assignees milestone commits_url review_comments_url review_comment_url comments_url statuses_url head base _links]) + end + end + end + + describe "#fetch_events_async" do + context "when API call is valid", :vcr do + it "populates issues" do + issues = [{ "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", + "repository_url" => "https://api.github.com/repos/skywinder/changelog_test", + "labels_url" => + "https://api.github.com/repos/skywinder/changelog_test/issues/14/labels{/name}", + "comments_url" => + "https://api.github.com/repos/skywinder/changelog_test/issues/14/comments", + "events_url" => + "https://api.github.com/repos/skywinder/changelog_test/issues/14/events", + "html_url" => "https://github.com/skywinder/changelog_test/issues/14", + "id" => 95_419_412, + "number" => 14, + "title" => "Issue closed from commit from PR", + "user" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => + "https://api.github.com/users/skywinder/following{/other_user}", + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => + "https://api.github.com/users/skywinder/starred{/owner}{/repo}", + "subscriptions_url" => + "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "received_events_url" => + "https://api.github.com/users/skywinder/received_events", + "type" => "User", + "site_admin" => false }, + "labels" => [], + "state" => "closed", + "locked" => false, + "assignee" => nil, + "assignees" => [], + "milestone" => nil, + "comments" => 0, + "created_at" => "2015-07-16T12:06:08Z", + "updated_at" => "2015-07-16T12:21:42Z", + "closed_at" => "2015-07-16T12:21:42Z", + "body" => "" }] + + # Check that they are blank to begin with + expect(issues.first["events"]).to be_nil + + fetcher.fetch_events_async(issues) + issue_events = issues.first["events"] + + expected_events = [{ "id" => 357_462_189, + "url" => + "https://api.github.com/repos/skywinder/changelog_test/issues/events/357462189", + "actor" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => + "https://api.github.com/users/skywinder/following{/other_user}", + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => + "https://api.github.com/users/skywinder/starred{/owner}{/repo}", + "subscriptions_url" => + "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "received_events_url" => + "https://api.github.com/users/skywinder/received_events", + "type" => "User", + "site_admin" => false }, + "event" => "referenced", + "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", + "commit_url" => + "https://api.github.com/repos/skywinder/changelog_test/commits/decfe840d1a1b86e0c28700de5362d3365a29555", + "created_at" => "2015-07-16T12:21:16Z" }, + { "id" => 357_462_542, + "url" => + "https://api.github.com/repos/skywinder/changelog_test/issues/events/357462542", + "actor" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => + "https://api.github.com/users/skywinder/following{/other_user}", + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => + "https://api.github.com/users/skywinder/starred{/owner}{/repo}", + "subscriptions_url" => + "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "received_events_url" => + "https://api.github.com/users/skywinder/received_events", + "type" => "User", + "site_admin" => false }, + "event" => "closed", + "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", + "commit_url" => + "https://api.github.com/repos/skywinder/changelog_test/commits/decfe840d1a1b86e0c28700de5362d3365a29555", + "created_at" => "2015-07-16T12:21:42Z" }] + + # Convert times to Time + expected_events.map! do |event| + event.each_pair do |k, v| + event[k] = Time.parse(v) if v =~ /^201[56]-/ + end + end + + expect(issue_events).to eq(expected_events) + end + end + end + + describe "#fetch_date_of_tag" do + context "when API call is valid", :vcr do + it "returns date" do + tag = { "name" => "v0.0.3", + "zipball_url" => + "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.3", + "tarball_url" => + "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.3", + "commit" => + { "sha" => "a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90", + "url" => + "https://api.github.com/repos/skywinder/changelog_test/commits/a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90" } } + + dt = fetcher.fetch_date_of_tag(tag) + expect(dt).to eq(Time.parse("2015-03-04 19:01:48 UTC")) + end + end + end + + describe "#querystring_as_hash" do + it "works on the blank URL" do + expect { fetcher.send(:querystring_as_hash, "") }.not_to raise_error + end + + it "where there are no querystring params" do + expect { fetcher.send(:querystring_as_hash, "http://example.com") }.not_to raise_error + end + + it "returns a String-keyed Hash of querystring params" do + expect(fetcher.send(:querystring_as_hash, "http://example.com/o.html?str=18&wis=12")).to include("wis" => "12", "str" => "18") + end + end + + describe "#fetch_commit" do + context "when API call is valid", :vcr do + it "returns commit" do + event = { "id" => 357_462_189, + "url" => + "https://api.github.com/repos/skywinder/changelog_test/issues/events/357462189", + "actor" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => + "https://api.github.com/users/skywinder/following{/other_user}", + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => + "https://api.github.com/users/skywinder/starred{/owner}{/repo}", + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "received_events_url" => + "https://api.github.com/users/skywinder/received_events", + "type" => "User", + "site_admin" => false }, + "event" => "referenced", + "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", + "commit_url" => + "https://api.github.com/repos/skywinder/changelog_test/commits/decfe840d1a1b86e0c28700de5362d3365a29555", + "created_at" => "2015-07-16T12:21:16Z" } + commit = fetcher.fetch_commit(event) + + expectations = [ + %w[sha decfe840d1a1b86e0c28700de5362d3365a29555], + ["url", + "https://api.github.com/repos/skywinder/changelog_test/commits/decfe840d1a1b86e0c28700de5362d3365a29555"], + # OLD API: "https://api.github.com/repos/skywinder/changelog_test/git/commits/decfe840d1a1b86e0c28700de5362d3365a29555"], + ["html_url", + "https://github.com/skywinder/changelog_test/commit/decfe840d1a1b86e0c28700de5362d3365a29555"], + ["author", + { "login" => "skywinder", "id" => 3_356_474, "avatar_url" => "https://avatars2.githubusercontent.com/u/3356474?v=4", "gravatar_id" => "", "url" => "https://api.github.com/users/skywinder", "html_url" => "https://github.com/skywinder", "followers_url" => "https://api.github.com/users/skywinder/followers", "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", "organizations_url" => "https://api.github.com/users/skywinder/orgs", "repos_url" => "https://api.github.com/users/skywinder/repos", "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", "type" => "User", "site_admin" => false }], + ["committer", + { "login" => "skywinder", "id" => 3_356_474, "avatar_url" => "https://avatars2.githubusercontent.com/u/3356474?v=4", "gravatar_id" => "", "url" => "https://api.github.com/users/skywinder", "html_url" => "https://github.com/skywinder", "followers_url" => "https://api.github.com/users/skywinder/followers", "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", "organizations_url" => "https://api.github.com/users/skywinder/orgs", "repos_url" => "https://api.github.com/users/skywinder/repos", "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", "type" => "User", "site_admin" => false }], + ["parents", + [{ "sha" => "7ec095e5e3caceacedabf44d0b9b10da17c92e51", + "url" => + "https://api.github.com/repos/skywinder/changelog_test/commits/7ec095e5e3caceacedabf44d0b9b10da17c92e51", + # OLD API: "https://api.github.com/repos/skywinder/changelog_test/git/commits/7ec095e5e3caceacedabf44d0b9b10da17c92e51", + "html_url" => + "https://github.com/skywinder/changelog_test/commit/7ec095e5e3caceacedabf44d0b9b10da17c92e51" }]] + ] + + expectations.each do |property, val| + expect(commit[property]).to eq(val) + end + end + end + end + + describe "#commits" do + context "when API is valid", :vcr do + subject do + fetcher.commits + end + + it "returns commits" do + expect(subject.last["sha"]).to eq("4c2d6d1ed58bdb24b870dcb5d9f2ceed0283d69d") + end + end + end +end From 62fbbe6711c06c58645f3a7555a15b0ad752e025 Mon Sep 17 00:00:00 2001 From: kreczko Date: Thu, 1 Nov 2018 16:46:27 +0000 Subject: [PATCH 120/128] added gitlab_changelog_generator --- .gitignore | 3 +- bin/gitlab_changelog_generator | 5 ++++ lib/gitlab_changelog_generator.rb | 48 +++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100755 bin/gitlab_changelog_generator create mode 100755 lib/gitlab_changelog_generator.rb diff --git a/.gitignore b/.gitignore index 6096426..fdf2a2f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ -bin/ +bin/* !bin/git-generate-changelog !bin/github_changelog_generator +!bin/gitlab_changelog_generator pkg/ coverage/ .bundle diff --git a/bin/gitlab_changelog_generator b/bin/gitlab_changelog_generator new file mode 100755 index 0000000..86ff22b --- /dev/null +++ b/bin/gitlab_changelog_generator @@ -0,0 +1,5 @@ +#! /usr/bin/env ruby +# frozen_string_literal: true + +require_relative "../lib/gitlab_changelog_generator" +GitLabChangelogGenerator::ChangelogGenerator.new.run diff --git a/lib/gitlab_changelog_generator.rb b/lib/gitlab_changelog_generator.rb new file mode 100755 index 0000000..8197b5f --- /dev/null +++ b/lib/gitlab_changelog_generator.rb @@ -0,0 +1,48 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "octokit" +require "faraday-http-cache" +require "logger" +require "active_support" +require "active_support/core_ext/object/blank" +require "json" +require "multi_json" +require "benchmark" + +require "github_changelog_generator/helper" +require "github_changelog_generator/options" +require "github_changelog_generator/parser" +require "github_changelog_generator/parser_file" +require "github_changelog_generator/generator/generator" +require "github_changelog_generator/version" +require "github_changelog_generator/reader" + +# The main module, where placed all classes (now, at least) +module GitLabChangelogGenerator + # Main class and entry point for this script. + class ChangelogGenerator + # Class, responsible for whole changelog generation cycle + # @return initialised instance of ChangelogGenerator + def initialize + @options = GitHubChangelogGenerator::Parser.parse_options + @options[:gitlab] = true + @generator = GitHubChangelogGenerator::Generator.new @options + end + + # The entry point of this script to generate changelog + # @raise (ChangelogGeneratorError) Is thrown when one of specified tags was not found in list of tags. + def run + log = @generator.compound_changelog + + if @options.write_to_file? + output_filename = @options[:output].to_s + File.open(output_filename, "wb") { |file| file.write(log) } + puts "Done!" + puts "Generated log placed in #{Dir.pwd}/#{output_filename}" + else + puts log + end + end + end +end From 587ff1d39b53e6bef8a4e622fab71a4ba0ab658a Mon Sep 17 00:00:00 2001 From: kreczko Date: Thu, 1 Nov 2018 16:53:31 +0000 Subject: [PATCH 121/128] Last few Github -> Gitlab conversions --- lib/github_changelog_generator/gitlab_fetcher.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/github_changelog_generator/gitlab_fetcher.rb b/lib/github_changelog_generator/gitlab_fetcher.rb index 06a095d..e0b39a1 100644 --- a/lib/github_changelog_generator/gitlab_fetcher.rb +++ b/lib/github_changelog_generator/gitlab_fetcher.rb @@ -5,7 +5,7 @@ require "gitlab" module GitLabChangelogGenerator - # A Fetcher responsible for all requests to GitHub and all basic manipulation with related data + # A Fetcher responsible for all requests to GitLab and all basic manipulation with related data # (such as filtering, validating, e.t.c) # # Example: @@ -15,10 +15,10 @@ class GitlabFetcher MAX_THREAD_NUMBER = 25 MAX_FORBIDDEN_RETRIES = 100 CHANGELOG_AUTH_TOKEN = "CHANGELOG_AUTH_TOKEN" - RATE_LIMIT_EXCEEDED_MSG = "Warning: Can't finish operation: GitHub API rate limit exceeded, changelog may be " \ + RATE_LIMIT_EXCEEDED_MSG = "Warning: Can't finish operation: GitLab API rate limit exceeded, changelog may be " \ "missing some issues. You can limit the number of issues fetched using the `--max-issues NUM` argument." NO_TOKEN_PROVIDED = "Warning: No token provided (-t option) and variable $CHANGELOG_AUTH_TOKEN was not found. " \ - "This script can make only 50 requests to GitHub API per hour without token!" + "This script can make only 50 requests to GitLab API per hour without token!" # @param options [Hash] Options passed in # @option options [String] :user Gitlab username @@ -417,7 +417,7 @@ def print_empty_line print_in_same_line(" ") end - # Returns GitHub token. First try to use variable, provided by --token option, + # Returns AUTH token. First try to use variable, provided by --token option, # otherwise try to fetch it from CHANGELOG_AUTH_TOKEN env variable. # # @return [String] From 769fbdf013df11ac47a3f3113f5fcbf37bb6307a Mon Sep 17 00:00:00 2001 From: kreczko Date: Thu, 1 Nov 2018 17:07:58 +0000 Subject: [PATCH 122/128] resolved second batch of feedback from @olleolleolle --- .../gitlab_fetcher.rb | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/github_changelog_generator/gitlab_fetcher.rb b/lib/github_changelog_generator/gitlab_fetcher.rb index e0b39a1..721c944 100644 --- a/lib/github_changelog_generator/gitlab_fetcher.rb +++ b/lib/github_changelog_generator/gitlab_fetcher.rb @@ -21,8 +21,8 @@ class GitlabFetcher "This script can make only 50 requests to GitLab API per hour without token!" # @param options [Hash] Options passed in - # @option options [String] :user Gitlab username - # @option options [String] :project Gitlab project + # @option options [String] :user GitLab username + # @option options [String] :project GitLab project # @option options [String] :since Only issues updated at or after this time are returned. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. eg. Time.parse("2016-01-01 10:00:00").iso8601 # @option options [Boolean] :http_cache Use ActiveSupport::Cache::FileStore to cache http requests # @option options [Boolean] :cache_file If using http_cache, this is the cache file path @@ -78,17 +78,16 @@ def fetch_tags tags = [] @client.tags(@project_id, DEFAULT_REQUEST_OPTIONS).auto_paginate do |new_tag| - tags.push(new_tag) + tags << new_tag end print_empty_line - if tags.count == 0 + if tags.empty? GitHubChangelogGenerator::Helper.log.warn "Warning: Can't find any tags in repo. \ Make sure, that you push tags to remote repo via 'git push --tags'" else GitHubChangelogGenerator::Helper.log.info "Found #{tags.count} tags" end - # tags are a Sawyer::Resource. Convert to hash tags.map { |resource| stringify_keys_deep(resource.to_hash) } end @@ -98,8 +97,7 @@ def closed_pr_options }.tap { |options| options[:since] = @since if @since } end - # This method fetch all closed issues and separate them to pull requests and pure issues - # (pull request is kind of issue in term of GitHub) + # This method fetch all closed issues pull requests (GitLab uses the term "merge requests") # # @return [Tuple] with (issues [Array ], pull-requests [Array ]) def fetch_closed_issues_and_pr @@ -138,7 +136,7 @@ def fetch_closed_pull_requests new_pr["user"] = { login: new_pr["author"]["username"], html_url: new_pr["author"]["web_url"] } # to make it work with older gitlab version or repos that lived across versions new_pr["merge_commit_sha"] = new_pr["merge_commit_sha"].nil? ? new_pr["sha"] : new_pr["merge_commit_sha"] - pull_requests.push(new_pr) + pull_requests << new_pr end print_empty_line @@ -156,15 +154,15 @@ def fetch_events_async(issues) threads = [] options = {} return if issues.empty? + options[:target_type] = issues.first["merged_at"].nil? ? "issue" : "merge_request" issue_events = [] @client.project_events(@project_id, options).auto_paginate do |event| event = stringify_keys_deep(event.to_hash) # gitlab to github event["event"] = event["action_name"] - issue_events.push(event) + issue_events << event end - # p issue_events issues.each_slice(MAX_THREAD_NUMBER) do |issues_slice| issues_slice.each do |issue| @@ -175,7 +173,7 @@ def fetch_events_async(issues) if new_event["action_name"].eql? "closed" issue["closed_at"] = issue["closed_at"].nil? ? new_event["created_at"] : issue["closed_at"] end - issue["events"].push(new_event) + issue["events"] << new_event end end print_in_same_line("Fetching events for #{options[:target_type]}s: #{i + 1}/#{issues.count}") @@ -194,7 +192,7 @@ def fetch_events_async(issues) # Fetch comments for PRs and add them to "comments" # - # @param [Array] prs The array of PRs. + # @param prs [Array] PRs for which to fetch comments # @return [Void] No return; PRs are updated in-place. def fetch_comments_async(prs) threads = [] @@ -219,18 +217,18 @@ def fetch_comments_async(prs) # Fetch tag time from repo # - # @param [Hash] tag GitHub data item about a Tag + # @param [Hash] tag GitLab data item about a Tag # # @return [Time] time of specified tag def fetch_date_of_tag(tag) Time.parse(tag["commit"]["committed_date"]) end - # Fetch and cache comparison between two github refs + # Fetch and cache comparison between two GitLab refs # # @param [String] older The older sha/tag/branch. # @param [String] newer The newer sha/tag/branch. - # @return [Hash] Github api response for comparison. + # @return [Hash] GitLab api response for comparison. def fetch_compare(older, newer) unless @compares["#{older}...#{newer}"] compare_data = check_response { @client.compare(@project_id, older, newer || "HEAD") } @@ -240,7 +238,7 @@ def fetch_compare(older, newer) end # TODO: do not know what the equivalent for gitlab is if compare_data["compare_same_ref"] == true - raise StandardError, "Sha #{older} and sha #{newer} are not related; please file a github-changelog-generator issues and describe how to replicate this issue." + raise StandardError, "Sha #{older} and sha #{newer} are not related; please file a github-changelog-generator issue and describe how to replicate this issue." end @compares["#{older}...#{newer}"] = stringify_keys_deep(compare_data.to_hash) end @@ -276,7 +274,7 @@ def commits @client.commits(@project_id).auto_paginate do |new_commit| new_commit = stringify_keys_deep(new_commit.to_hash) new_commit["sha"] = new_commit["id"] - @commits.push(new_commit) + @commits << new_commit end end @commits @@ -298,7 +296,7 @@ def default_branch # "shas_in_tag" # # @param [Array] tags The array of tags. - # @return [Nil] No return; tags are updated in-place. + # @return [void] No return; tags are updated in-place. def fetch_tag_shas_async(tags) i = 0 threads = [] From 03f24491a521e6bb0386c5ebcd4204a2ee478d37 Mon Sep 17 00:00:00 2001 From: Chris Denneen Date: Wed, 29 Jan 2020 09:54:34 -0500 Subject: [PATCH 123/128] Add gitlab to rake task --- lib/github_changelog_generator/task.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/github_changelog_generator/task.rb b/lib/github_changelog_generator/task.rb index 9faa738..cec8796 100644 --- a/lib/github_changelog_generator/task.rb +++ b/lib/github_changelog_generator/task.rb @@ -17,7 +17,7 @@ class RakeTask < ::Rake::TaskLib compare_link include_labels exclude_labels bug_labels enhancement_labels include_tags_regex between_tags exclude_tags exclude_tags_regex since_tag max_issues - github_site github_endpoint simple_list + github_site github_endpoint simple_list gitlab future_release release_branch verbose release_url base configure_sections add_sections http_cache] From 8b1881ef706873ac0c2c6a97a22e88676082f7c1 Mon Sep 17 00:00:00 2001 From: Chris Denneen Date: Thu, 18 Mar 2021 20:55:26 -0400 Subject: [PATCH 124/128] Updates to sync with upstream and fix rubocop errors --- .../gitlab_fetcher.rb | 13 +- spec/unit/gitlab_fetcher_spec.rb | 364 +++++++++--------- 2 files changed, 187 insertions(+), 190 deletions(-) diff --git a/lib/github_changelog_generator/gitlab_fetcher.rb b/lib/github_changelog_generator/gitlab_fetcher.rb index 721c944..fe394cb 100644 --- a/lib/github_changelog_generator/gitlab_fetcher.rb +++ b/lib/github_changelog_generator/gitlab_fetcher.rb @@ -237,9 +237,8 @@ def fetch_compare(older, newer) commit["sha"] = commit["id"] end # TODO: do not know what the equivalent for gitlab is - if compare_data["compare_same_ref"] == true - raise StandardError, "Sha #{older} and sha #{newer} are not related; please file a github-changelog-generator issue and describe how to replicate this issue." - end + raise StandardError, "Sha #{older} and sha #{newer} are not related; please file a github-changelog-generator issue and describe how to replicate this issue." if compare_data["compare_same_ref"] == true + @compares["#{older}...#{newer}"] = stringify_keys_deep(compare_data.to_hash) end @compares["#{older}...#{newer}"] @@ -356,10 +355,8 @@ def extract_request_args(args) # 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 - def check_response - Retriable.retriable(retry_options) do - yield - end + def check_response(&block) + Retriable.retriable(retry_options, &block) rescue MovedPermanentlyError => e fail_with_message(e, "The repository has moved, update your configuration") rescue Gitlab::Error::Forbidden => e @@ -407,7 +404,7 @@ def sys_abort(msg) # # @param [String] log_string def print_in_same_line(log_string) - print log_string + "\r" + print "#{log_string}\r" end # Print long line with spaces on same line to clear prev message diff --git a/spec/unit/gitlab_fetcher_spec.rb b/spec/unit/gitlab_fetcher_spec.rb index 1935206..0d83fb1 100644 --- a/spec/unit/gitlab_fetcher_spec.rb +++ b/spec/unit/gitlab_fetcher_spec.rb @@ -102,39 +102,39 @@ # TODO: swap for Gitlab API context "when API call is valid", :vcr do it "should return tags" do - expected_tags = [{ "name" => "v0.0.3", + expected_tags = [{ "name" => "v0.0.3", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.3", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.3", - "commit" => + "commit" => { "sha" => "a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90" } }, - { "name" => "v0.0.2", + { "name" => "v0.0.2", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.2", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.2", - "commit" => + "commit" => { "sha" => "9b35bb13dcd15b68e7bcbf10cde5eb937a54f710", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/9b35bb13dcd15b68e7bcbf10cde5eb937a54f710" } }, - { "name" => "v0.0.1", + { "name" => "v0.0.1", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.1", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.1", - "commit" => + "commit" => { "sha" => "4c2d6d1ed58bdb24b870dcb5d9f2ceed0283d69d", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/4c2d6d1ed58bdb24b870dcb5d9f2ceed0283d69d" } }, - { "name" => "0.0.4", + { "name" => "0.0.4", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/0.0.4", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/0.0.4", - "commit" => + "commit" => { "sha" => "ece0c3ab7142b21064b885061c55ede00ef6ce94", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/ece0c3ab7142b21064b885061c55ede00ef6ce94" } }] @@ -160,50 +160,50 @@ it "returns issue with proper key/values" do issues, _pull_requests = fetcher.fetch_closed_issues_and_pr - expected_issue = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", + expected_issue = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", "repository_url" => "https://api.github.com/repos/skywinder/changelog_test", - "labels_url" => + "labels_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/labels{/name}", - "comments_url" => + "comments_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/comments", - "events_url" => + "events_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/events", - "html_url" => "https://github.com/skywinder/changelog_test/issues/14", - "id" => 95_419_412, - "number" => 14, - "title" => "Issue closed from commit from PR", - "user" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "html_url" => "https://github.com/skywinder/changelog_test/issues/14", + "id" => 95_419_412, + "number" => 14, + "title" => "Issue closed from commit from PR", + "user" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "labels" => [], - "state" => "closed", - "locked" => false, - "assignee" => nil, + "type" => "User", + "site_admin" => false }, + "labels" => [], + "state" => "closed", + "locked" => false, + "assignee" => nil, "assignees" => [], - "milestone" => nil, - "comments" => 0, - "created_at" => "2015-07-16T12:06:08Z", - "updated_at" => "2015-07-16T12:21:42Z", - "closed_at" => "2015-07-16T12:21:42Z", - "body" => "" } + "milestone" => nil, + "comments" => 0, + "created_at" => "2015-07-16T12:06:08Z", + "updated_at" => "2015-07-16T12:21:42Z", + "closed_at" => "2015-07-16T12:21:42Z", + "body" => "" } # Convert times to Time expected_issue.each_pair do |k, v| @@ -216,55 +216,55 @@ it "returns pull request with proper key/values" do _issues, pull_requests = fetcher.fetch_closed_issues_and_pr - expected_pr = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21", + expected_pr = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21", "repository_url" => "https://api.github.com/repos/skywinder/changelog_test", - "labels_url" => + "labels_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21/labels{/name}", - "comments_url" => + "comments_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21/comments", - "events_url" => + "events_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21/events", - "html_url" => "https://github.com/skywinder/changelog_test/pull/21", - "id" => 124_925_759, - "number" => 21, - "title" => "Merged br (should appear in change log with #20)", - "user" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "html_url" => "https://github.com/skywinder/changelog_test/pull/21", + "id" => 124_925_759, + "number" => 21, + "title" => "Merged br (should appear in change log with #20)", + "user" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "labels" => [], - "state" => "closed", - "locked" => false, - "assignee" => nil, + "type" => "User", + "site_admin" => false }, + "labels" => [], + "state" => "closed", + "locked" => false, + "assignee" => nil, "assignees" => [], - "milestone" => nil, - "comments" => 0, - "created_at" => "2016-01-05T09:24:08Z", - "updated_at" => "2016-01-05T09:26:53Z", - "closed_at" => "2016-01-05T09:24:27Z", - "pull_request" => - { "url" => "https://api.github.com/repos/skywinder/changelog_test/pulls/21", - "html_url" => "https://github.com/skywinder/changelog_test/pull/21", - "diff_url" => "https://github.com/skywinder/changelog_test/pull/21.diff", + "milestone" => nil, + "comments" => 0, + "created_at" => "2016-01-05T09:24:08Z", + "updated_at" => "2016-01-05T09:26:53Z", + "closed_at" => "2016-01-05T09:24:27Z", + "pull_request" => + { "url" => "https://api.github.com/repos/skywinder/changelog_test/pulls/21", + "html_url" => "https://github.com/skywinder/changelog_test/pull/21", + "diff_url" => "https://github.com/skywinder/changelog_test/pull/21.diff", "patch_url" => "https://github.com/skywinder/changelog_test/pull/21.patch" }, - "body" => + "body" => "to test https://github.com/skywinder/github-changelog-generator/pull/305\r\nshould appear in change log with #20" } # Convert times to Time @@ -308,51 +308,51 @@ describe "#fetch_events_async" do context "when API call is valid", :vcr do it "populates issues" do - issues = [{ "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", + issues = [{ "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", "repository_url" => "https://api.github.com/repos/skywinder/changelog_test", - "labels_url" => + "labels_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/labels{/name}", - "comments_url" => + "comments_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/comments", - "events_url" => + "events_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/events", - "html_url" => "https://github.com/skywinder/changelog_test/issues/14", - "id" => 95_419_412, - "number" => 14, - "title" => "Issue closed from commit from PR", - "user" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "html_url" => "https://github.com/skywinder/changelog_test/issues/14", + "id" => 95_419_412, + "number" => 14, + "title" => "Issue closed from commit from PR", + "user" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "labels" => [], - "state" => "closed", - "locked" => false, - "assignee" => nil, + "type" => "User", + "site_admin" => false }, + "labels" => [], + "state" => "closed", + "locked" => false, + "assignee" => nil, "assignees" => [], - "milestone" => nil, - "comments" => 0, - "created_at" => "2015-07-16T12:06:08Z", - "updated_at" => "2015-07-16T12:21:42Z", - "closed_at" => "2015-07-16T12:21:42Z", - "body" => "" }] + "milestone" => nil, + "comments" => 0, + "created_at" => "2015-07-16T12:06:08Z", + "updated_at" => "2015-07-16T12:21:42Z", + "closed_at" => "2015-07-16T12:21:42Z", + "body" => "" }] # Check that they are blank to begin with expect(issues.first["events"]).to be_nil @@ -360,63 +360,63 @@ fetcher.fetch_events_async(issues) issue_events = issues.first["events"] - expected_events = [{ "id" => 357_462_189, - "url" => + expected_events = [{ "id" => 357_462_189, + "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/events/357462189", - "actor" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "actor" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "event" => "referenced", - "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", + "type" => "User", + "site_admin" => false }, + "event" => "referenced", + "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", "commit_url" => "https://api.github.com/repos/skywinder/changelog_test/commits/decfe840d1a1b86e0c28700de5362d3365a29555", "created_at" => "2015-07-16T12:21:16Z" }, - { "id" => 357_462_542, - "url" => + { "id" => 357_462_542, + "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/events/357462542", - "actor" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "actor" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "event" => "closed", - "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", + "type" => "User", + "site_admin" => false }, + "event" => "closed", + "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", "commit_url" => "https://api.github.com/repos/skywinder/changelog_test/commits/decfe840d1a1b86e0c28700de5362d3365a29555", "created_at" => "2015-07-16T12:21:42Z" }] @@ -436,12 +436,12 @@ describe "#fetch_date_of_tag" do context "when API call is valid", :vcr do it "returns date" do - tag = { "name" => "v0.0.3", + tag = { "name" => "v0.0.3", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.3", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.3", - "commit" => + "commit" => { "sha" => "a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90" } } @@ -469,32 +469,32 @@ describe "#fetch_commit" do context "when API call is valid", :vcr do it "returns commit" do - event = { "id" => 357_462_189, - "url" => + event = { "id" => 357_462_189, + "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/events/357462189", - "actor" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "actor" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "event" => "referenced", - "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", + "type" => "User", + "site_admin" => false }, + "event" => "referenced", + "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", "commit_url" => "https://api.github.com/repos/skywinder/changelog_test/commits/decfe840d1a1b86e0c28700de5362d3365a29555", "created_at" => "2015-07-16T12:21:16Z" } From 07068e4208fe2d7028a459525e1b1cdb76e9e10a Mon Sep 17 00:00:00 2001 From: Chris Denneen Date: Thu, 18 Mar 2021 20:58:53 -0400 Subject: [PATCH 125/128] Updates for upstream sync and rubocop fixes --- .../gitlab_fetcher.rb | 13 +- spec/unit/gitlab_fetcher_spec.rb | 364 +++++++++--------- 2 files changed, 187 insertions(+), 190 deletions(-) diff --git a/lib/github_changelog_generator/gitlab_fetcher.rb b/lib/github_changelog_generator/gitlab_fetcher.rb index 721c944..fe394cb 100644 --- a/lib/github_changelog_generator/gitlab_fetcher.rb +++ b/lib/github_changelog_generator/gitlab_fetcher.rb @@ -237,9 +237,8 @@ def fetch_compare(older, newer) commit["sha"] = commit["id"] end # TODO: do not know what the equivalent for gitlab is - if compare_data["compare_same_ref"] == true - raise StandardError, "Sha #{older} and sha #{newer} are not related; please file a github-changelog-generator issue and describe how to replicate this issue." - end + raise StandardError, "Sha #{older} and sha #{newer} are not related; please file a github-changelog-generator issue and describe how to replicate this issue." if compare_data["compare_same_ref"] == true + @compares["#{older}...#{newer}"] = stringify_keys_deep(compare_data.to_hash) end @compares["#{older}...#{newer}"] @@ -356,10 +355,8 @@ def extract_request_args(args) # 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 - def check_response - Retriable.retriable(retry_options) do - yield - end + def check_response(&block) + Retriable.retriable(retry_options, &block) rescue MovedPermanentlyError => e fail_with_message(e, "The repository has moved, update your configuration") rescue Gitlab::Error::Forbidden => e @@ -407,7 +404,7 @@ def sys_abort(msg) # # @param [String] log_string def print_in_same_line(log_string) - print log_string + "\r" + print "#{log_string}\r" end # Print long line with spaces on same line to clear prev message diff --git a/spec/unit/gitlab_fetcher_spec.rb b/spec/unit/gitlab_fetcher_spec.rb index 1935206..0d83fb1 100644 --- a/spec/unit/gitlab_fetcher_spec.rb +++ b/spec/unit/gitlab_fetcher_spec.rb @@ -102,39 +102,39 @@ # TODO: swap for Gitlab API context "when API call is valid", :vcr do it "should return tags" do - expected_tags = [{ "name" => "v0.0.3", + expected_tags = [{ "name" => "v0.0.3", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.3", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.3", - "commit" => + "commit" => { "sha" => "a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90" } }, - { "name" => "v0.0.2", + { "name" => "v0.0.2", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.2", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.2", - "commit" => + "commit" => { "sha" => "9b35bb13dcd15b68e7bcbf10cde5eb937a54f710", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/9b35bb13dcd15b68e7bcbf10cde5eb937a54f710" } }, - { "name" => "v0.0.1", + { "name" => "v0.0.1", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.1", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.1", - "commit" => + "commit" => { "sha" => "4c2d6d1ed58bdb24b870dcb5d9f2ceed0283d69d", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/4c2d6d1ed58bdb24b870dcb5d9f2ceed0283d69d" } }, - { "name" => "0.0.4", + { "name" => "0.0.4", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/0.0.4", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/0.0.4", - "commit" => + "commit" => { "sha" => "ece0c3ab7142b21064b885061c55ede00ef6ce94", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/ece0c3ab7142b21064b885061c55ede00ef6ce94" } }] @@ -160,50 +160,50 @@ it "returns issue with proper key/values" do issues, _pull_requests = fetcher.fetch_closed_issues_and_pr - expected_issue = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", + expected_issue = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", "repository_url" => "https://api.github.com/repos/skywinder/changelog_test", - "labels_url" => + "labels_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/labels{/name}", - "comments_url" => + "comments_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/comments", - "events_url" => + "events_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/events", - "html_url" => "https://github.com/skywinder/changelog_test/issues/14", - "id" => 95_419_412, - "number" => 14, - "title" => "Issue closed from commit from PR", - "user" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "html_url" => "https://github.com/skywinder/changelog_test/issues/14", + "id" => 95_419_412, + "number" => 14, + "title" => "Issue closed from commit from PR", + "user" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "labels" => [], - "state" => "closed", - "locked" => false, - "assignee" => nil, + "type" => "User", + "site_admin" => false }, + "labels" => [], + "state" => "closed", + "locked" => false, + "assignee" => nil, "assignees" => [], - "milestone" => nil, - "comments" => 0, - "created_at" => "2015-07-16T12:06:08Z", - "updated_at" => "2015-07-16T12:21:42Z", - "closed_at" => "2015-07-16T12:21:42Z", - "body" => "" } + "milestone" => nil, + "comments" => 0, + "created_at" => "2015-07-16T12:06:08Z", + "updated_at" => "2015-07-16T12:21:42Z", + "closed_at" => "2015-07-16T12:21:42Z", + "body" => "" } # Convert times to Time expected_issue.each_pair do |k, v| @@ -216,55 +216,55 @@ it "returns pull request with proper key/values" do _issues, pull_requests = fetcher.fetch_closed_issues_and_pr - expected_pr = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21", + expected_pr = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21", "repository_url" => "https://api.github.com/repos/skywinder/changelog_test", - "labels_url" => + "labels_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21/labels{/name}", - "comments_url" => + "comments_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21/comments", - "events_url" => + "events_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21/events", - "html_url" => "https://github.com/skywinder/changelog_test/pull/21", - "id" => 124_925_759, - "number" => 21, - "title" => "Merged br (should appear in change log with #20)", - "user" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "html_url" => "https://github.com/skywinder/changelog_test/pull/21", + "id" => 124_925_759, + "number" => 21, + "title" => "Merged br (should appear in change log with #20)", + "user" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "labels" => [], - "state" => "closed", - "locked" => false, - "assignee" => nil, + "type" => "User", + "site_admin" => false }, + "labels" => [], + "state" => "closed", + "locked" => false, + "assignee" => nil, "assignees" => [], - "milestone" => nil, - "comments" => 0, - "created_at" => "2016-01-05T09:24:08Z", - "updated_at" => "2016-01-05T09:26:53Z", - "closed_at" => "2016-01-05T09:24:27Z", - "pull_request" => - { "url" => "https://api.github.com/repos/skywinder/changelog_test/pulls/21", - "html_url" => "https://github.com/skywinder/changelog_test/pull/21", - "diff_url" => "https://github.com/skywinder/changelog_test/pull/21.diff", + "milestone" => nil, + "comments" => 0, + "created_at" => "2016-01-05T09:24:08Z", + "updated_at" => "2016-01-05T09:26:53Z", + "closed_at" => "2016-01-05T09:24:27Z", + "pull_request" => + { "url" => "https://api.github.com/repos/skywinder/changelog_test/pulls/21", + "html_url" => "https://github.com/skywinder/changelog_test/pull/21", + "diff_url" => "https://github.com/skywinder/changelog_test/pull/21.diff", "patch_url" => "https://github.com/skywinder/changelog_test/pull/21.patch" }, - "body" => + "body" => "to test https://github.com/skywinder/github-changelog-generator/pull/305\r\nshould appear in change log with #20" } # Convert times to Time @@ -308,51 +308,51 @@ describe "#fetch_events_async" do context "when API call is valid", :vcr do it "populates issues" do - issues = [{ "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", + issues = [{ "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", "repository_url" => "https://api.github.com/repos/skywinder/changelog_test", - "labels_url" => + "labels_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/labels{/name}", - "comments_url" => + "comments_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/comments", - "events_url" => + "events_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/events", - "html_url" => "https://github.com/skywinder/changelog_test/issues/14", - "id" => 95_419_412, - "number" => 14, - "title" => "Issue closed from commit from PR", - "user" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "html_url" => "https://github.com/skywinder/changelog_test/issues/14", + "id" => 95_419_412, + "number" => 14, + "title" => "Issue closed from commit from PR", + "user" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "labels" => [], - "state" => "closed", - "locked" => false, - "assignee" => nil, + "type" => "User", + "site_admin" => false }, + "labels" => [], + "state" => "closed", + "locked" => false, + "assignee" => nil, "assignees" => [], - "milestone" => nil, - "comments" => 0, - "created_at" => "2015-07-16T12:06:08Z", - "updated_at" => "2015-07-16T12:21:42Z", - "closed_at" => "2015-07-16T12:21:42Z", - "body" => "" }] + "milestone" => nil, + "comments" => 0, + "created_at" => "2015-07-16T12:06:08Z", + "updated_at" => "2015-07-16T12:21:42Z", + "closed_at" => "2015-07-16T12:21:42Z", + "body" => "" }] # Check that they are blank to begin with expect(issues.first["events"]).to be_nil @@ -360,63 +360,63 @@ fetcher.fetch_events_async(issues) issue_events = issues.first["events"] - expected_events = [{ "id" => 357_462_189, - "url" => + expected_events = [{ "id" => 357_462_189, + "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/events/357462189", - "actor" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "actor" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "event" => "referenced", - "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", + "type" => "User", + "site_admin" => false }, + "event" => "referenced", + "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", "commit_url" => "https://api.github.com/repos/skywinder/changelog_test/commits/decfe840d1a1b86e0c28700de5362d3365a29555", "created_at" => "2015-07-16T12:21:16Z" }, - { "id" => 357_462_542, - "url" => + { "id" => 357_462_542, + "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/events/357462542", - "actor" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "actor" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "event" => "closed", - "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", + "type" => "User", + "site_admin" => false }, + "event" => "closed", + "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", "commit_url" => "https://api.github.com/repos/skywinder/changelog_test/commits/decfe840d1a1b86e0c28700de5362d3365a29555", "created_at" => "2015-07-16T12:21:42Z" }] @@ -436,12 +436,12 @@ describe "#fetch_date_of_tag" do context "when API call is valid", :vcr do it "returns date" do - tag = { "name" => "v0.0.3", + tag = { "name" => "v0.0.3", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.3", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.3", - "commit" => + "commit" => { "sha" => "a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90" } } @@ -469,32 +469,32 @@ describe "#fetch_commit" do context "when API call is valid", :vcr do it "returns commit" do - event = { "id" => 357_462_189, - "url" => + event = { "id" => 357_462_189, + "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/events/357462189", - "actor" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "actor" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "event" => "referenced", - "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", + "type" => "User", + "site_admin" => false }, + "event" => "referenced", + "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", "commit_url" => "https://api.github.com/repos/skywinder/changelog_test/commits/decfe840d1a1b86e0c28700de5362d3365a29555", "created_at" => "2015-07-16T12:21:16Z" } From 101230ec173fcae2b659420988d6072dc43ecc5d Mon Sep 17 00:00:00 2001 From: Chris Denneen Date: Thu, 18 Mar 2021 21:09:43 -0400 Subject: [PATCH 126/128] Update TOKEN to match the existing token so it will work without new variable: CHANGELOG_GITHUB_TOKEN --- lib/github_changelog_generator/gitlab_fetcher.rb | 8 ++++---- spec/unit/gitlab_fetcher_spec.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/github_changelog_generator/gitlab_fetcher.rb b/lib/github_changelog_generator/gitlab_fetcher.rb index fe394cb..1b6793f 100644 --- a/lib/github_changelog_generator/gitlab_fetcher.rb +++ b/lib/github_changelog_generator/gitlab_fetcher.rb @@ -14,10 +14,10 @@ class GitlabFetcher PER_PAGE_NUMBER = 100 MAX_THREAD_NUMBER = 25 MAX_FORBIDDEN_RETRIES = 100 - CHANGELOG_AUTH_TOKEN = "CHANGELOG_AUTH_TOKEN" + CHANGELOG_GITHUB_TOKEN = "CHANGELOG_GITHUB_TOKEN" RATE_LIMIT_EXCEEDED_MSG = "Warning: Can't finish operation: GitLab API rate limit exceeded, changelog may be " \ "missing some issues. You can limit the number of issues fetched using the `--max-issues NUM` argument." - NO_TOKEN_PROVIDED = "Warning: No token provided (-t option) and variable $CHANGELOG_AUTH_TOKEN was not found. " \ + NO_TOKEN_PROVIDED = "Warning: No token provided (-t option) and variable $CHANGELOG_GITHUB_TOKEN was not found. " \ "This script can make only 50 requests to GitLab API per hour without token!" # @param options [Hash] Options passed in @@ -413,11 +413,11 @@ def print_empty_line end # Returns AUTH token. First try to use variable, provided by --token option, - # otherwise try to fetch it from CHANGELOG_AUTH_TOKEN env variable. + # otherwise try to fetch it from CHANGELOG_GITHUB_TOKEN env variable. # # @return [String] def fetch_auth_token - env_var = @options[:token].presence || ENV["CHANGELOG_AUTH_TOKEN"] + env_var = @options[:token].presence || ENV["CHANGELOG_GITHUB_TOKEN"] GitHubChangelogGenerator::Helper.log.warn NO_TOKEN_PROVIDED unless env_var diff --git a/spec/unit/gitlab_fetcher_spec.rb b/spec/unit/gitlab_fetcher_spec.rb index 0d83fb1..a7aa116 100644 --- a/spec/unit/gitlab_fetcher_spec.rb +++ b/spec/unit/gitlab_fetcher_spec.rb @@ -37,7 +37,7 @@ end describe "#fetch_auth_token" do - token = GitLabChangelogGenerator::GitlabFetcher::CHANGELOG_AUTH_TOKEN + token = GitLabChangelogGenerator::GitlabFetcher::CHANGELOG_GITHUB_TOKEN context "when token in ENV exist" do before { stub_const("ENV", ENV.to_hash.merge(token => VALID_TOKEN)) } subject { fetcher.send(:fetch_auth_token) } From 993e641fb24df479757641746d353f67f6a6a35a Mon Sep 17 00:00:00 2001 From: Chris Denneen Date: Mon, 29 Mar 2021 14:00:30 -0400 Subject: [PATCH 127/128] Resync to upstream --- .../gitlab_fetcher.rb | 21 +- spec/unit/gitlab_fetcher_spec.rb | 366 +++++++++--------- 2 files changed, 195 insertions(+), 192 deletions(-) diff --git a/lib/github_changelog_generator/gitlab_fetcher.rb b/lib/github_changelog_generator/gitlab_fetcher.rb index 1b6793f..721c944 100644 --- a/lib/github_changelog_generator/gitlab_fetcher.rb +++ b/lib/github_changelog_generator/gitlab_fetcher.rb @@ -14,10 +14,10 @@ class GitlabFetcher PER_PAGE_NUMBER = 100 MAX_THREAD_NUMBER = 25 MAX_FORBIDDEN_RETRIES = 100 - CHANGELOG_GITHUB_TOKEN = "CHANGELOG_GITHUB_TOKEN" + CHANGELOG_AUTH_TOKEN = "CHANGELOG_AUTH_TOKEN" RATE_LIMIT_EXCEEDED_MSG = "Warning: Can't finish operation: GitLab API rate limit exceeded, changelog may be " \ "missing some issues. You can limit the number of issues fetched using the `--max-issues NUM` argument." - NO_TOKEN_PROVIDED = "Warning: No token provided (-t option) and variable $CHANGELOG_GITHUB_TOKEN was not found. " \ + NO_TOKEN_PROVIDED = "Warning: No token provided (-t option) and variable $CHANGELOG_AUTH_TOKEN was not found. " \ "This script can make only 50 requests to GitLab API per hour without token!" # @param options [Hash] Options passed in @@ -237,8 +237,9 @@ def fetch_compare(older, newer) commit["sha"] = commit["id"] end # TODO: do not know what the equivalent for gitlab is - raise StandardError, "Sha #{older} and sha #{newer} are not related; please file a github-changelog-generator issue and describe how to replicate this issue." if compare_data["compare_same_ref"] == true - + if compare_data["compare_same_ref"] == true + raise StandardError, "Sha #{older} and sha #{newer} are not related; please file a github-changelog-generator issue and describe how to replicate this issue." + end @compares["#{older}...#{newer}"] = stringify_keys_deep(compare_data.to_hash) end @compares["#{older}...#{newer}"] @@ -355,8 +356,10 @@ def extract_request_args(args) # 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 - def check_response(&block) - Retriable.retriable(retry_options, &block) + def check_response + Retriable.retriable(retry_options) do + yield + end rescue MovedPermanentlyError => e fail_with_message(e, "The repository has moved, update your configuration") rescue Gitlab::Error::Forbidden => e @@ -404,7 +407,7 @@ def sys_abort(msg) # # @param [String] log_string def print_in_same_line(log_string) - print "#{log_string}\r" + print log_string + "\r" end # Print long line with spaces on same line to clear prev message @@ -413,11 +416,11 @@ def print_empty_line end # Returns AUTH token. First try to use variable, provided by --token option, - # otherwise try to fetch it from CHANGELOG_GITHUB_TOKEN env variable. + # otherwise try to fetch it from CHANGELOG_AUTH_TOKEN env variable. # # @return [String] def fetch_auth_token - env_var = @options[:token].presence || ENV["CHANGELOG_GITHUB_TOKEN"] + env_var = @options[:token].presence || ENV["CHANGELOG_AUTH_TOKEN"] GitHubChangelogGenerator::Helper.log.warn NO_TOKEN_PROVIDED unless env_var diff --git a/spec/unit/gitlab_fetcher_spec.rb b/spec/unit/gitlab_fetcher_spec.rb index a7aa116..1935206 100644 --- a/spec/unit/gitlab_fetcher_spec.rb +++ b/spec/unit/gitlab_fetcher_spec.rb @@ -37,7 +37,7 @@ end describe "#fetch_auth_token" do - token = GitLabChangelogGenerator::GitlabFetcher::CHANGELOG_GITHUB_TOKEN + token = GitLabChangelogGenerator::GitlabFetcher::CHANGELOG_AUTH_TOKEN context "when token in ENV exist" do before { stub_const("ENV", ENV.to_hash.merge(token => VALID_TOKEN)) } subject { fetcher.send(:fetch_auth_token) } @@ -102,39 +102,39 @@ # TODO: swap for Gitlab API context "when API call is valid", :vcr do it "should return tags" do - expected_tags = [{ "name" => "v0.0.3", + expected_tags = [{ "name" => "v0.0.3", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.3", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.3", - "commit" => + "commit" => { "sha" => "a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90" } }, - { "name" => "v0.0.2", + { "name" => "v0.0.2", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.2", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.2", - "commit" => + "commit" => { "sha" => "9b35bb13dcd15b68e7bcbf10cde5eb937a54f710", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/9b35bb13dcd15b68e7bcbf10cde5eb937a54f710" } }, - { "name" => "v0.0.1", + { "name" => "v0.0.1", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.1", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.1", - "commit" => + "commit" => { "sha" => "4c2d6d1ed58bdb24b870dcb5d9f2ceed0283d69d", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/4c2d6d1ed58bdb24b870dcb5d9f2ceed0283d69d" } }, - { "name" => "0.0.4", + { "name" => "0.0.4", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/0.0.4", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/0.0.4", - "commit" => + "commit" => { "sha" => "ece0c3ab7142b21064b885061c55ede00ef6ce94", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/ece0c3ab7142b21064b885061c55ede00ef6ce94" } }] @@ -160,50 +160,50 @@ it "returns issue with proper key/values" do issues, _pull_requests = fetcher.fetch_closed_issues_and_pr - expected_issue = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", + expected_issue = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", "repository_url" => "https://api.github.com/repos/skywinder/changelog_test", - "labels_url" => + "labels_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/labels{/name}", - "comments_url" => + "comments_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/comments", - "events_url" => + "events_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/events", - "html_url" => "https://github.com/skywinder/changelog_test/issues/14", - "id" => 95_419_412, - "number" => 14, - "title" => "Issue closed from commit from PR", - "user" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "html_url" => "https://github.com/skywinder/changelog_test/issues/14", + "id" => 95_419_412, + "number" => 14, + "title" => "Issue closed from commit from PR", + "user" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "labels" => [], - "state" => "closed", - "locked" => false, - "assignee" => nil, + "type" => "User", + "site_admin" => false }, + "labels" => [], + "state" => "closed", + "locked" => false, + "assignee" => nil, "assignees" => [], - "milestone" => nil, - "comments" => 0, - "created_at" => "2015-07-16T12:06:08Z", - "updated_at" => "2015-07-16T12:21:42Z", - "closed_at" => "2015-07-16T12:21:42Z", - "body" => "" } + "milestone" => nil, + "comments" => 0, + "created_at" => "2015-07-16T12:06:08Z", + "updated_at" => "2015-07-16T12:21:42Z", + "closed_at" => "2015-07-16T12:21:42Z", + "body" => "" } # Convert times to Time expected_issue.each_pair do |k, v| @@ -216,55 +216,55 @@ it "returns pull request with proper key/values" do _issues, pull_requests = fetcher.fetch_closed_issues_and_pr - expected_pr = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21", + expected_pr = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21", "repository_url" => "https://api.github.com/repos/skywinder/changelog_test", - "labels_url" => + "labels_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21/labels{/name}", - "comments_url" => + "comments_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21/comments", - "events_url" => + "events_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21/events", - "html_url" => "https://github.com/skywinder/changelog_test/pull/21", - "id" => 124_925_759, - "number" => 21, - "title" => "Merged br (should appear in change log with #20)", - "user" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "html_url" => "https://github.com/skywinder/changelog_test/pull/21", + "id" => 124_925_759, + "number" => 21, + "title" => "Merged br (should appear in change log with #20)", + "user" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "labels" => [], - "state" => "closed", - "locked" => false, - "assignee" => nil, + "type" => "User", + "site_admin" => false }, + "labels" => [], + "state" => "closed", + "locked" => false, + "assignee" => nil, "assignees" => [], - "milestone" => nil, - "comments" => 0, - "created_at" => "2016-01-05T09:24:08Z", - "updated_at" => "2016-01-05T09:26:53Z", - "closed_at" => "2016-01-05T09:24:27Z", - "pull_request" => - { "url" => "https://api.github.com/repos/skywinder/changelog_test/pulls/21", - "html_url" => "https://github.com/skywinder/changelog_test/pull/21", - "diff_url" => "https://github.com/skywinder/changelog_test/pull/21.diff", + "milestone" => nil, + "comments" => 0, + "created_at" => "2016-01-05T09:24:08Z", + "updated_at" => "2016-01-05T09:26:53Z", + "closed_at" => "2016-01-05T09:24:27Z", + "pull_request" => + { "url" => "https://api.github.com/repos/skywinder/changelog_test/pulls/21", + "html_url" => "https://github.com/skywinder/changelog_test/pull/21", + "diff_url" => "https://github.com/skywinder/changelog_test/pull/21.diff", "patch_url" => "https://github.com/skywinder/changelog_test/pull/21.patch" }, - "body" => + "body" => "to test https://github.com/skywinder/github-changelog-generator/pull/305\r\nshould appear in change log with #20" } # Convert times to Time @@ -308,51 +308,51 @@ describe "#fetch_events_async" do context "when API call is valid", :vcr do it "populates issues" do - issues = [{ "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", + issues = [{ "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", "repository_url" => "https://api.github.com/repos/skywinder/changelog_test", - "labels_url" => + "labels_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/labels{/name}", - "comments_url" => + "comments_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/comments", - "events_url" => + "events_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/events", - "html_url" => "https://github.com/skywinder/changelog_test/issues/14", - "id" => 95_419_412, - "number" => 14, - "title" => "Issue closed from commit from PR", - "user" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "html_url" => "https://github.com/skywinder/changelog_test/issues/14", + "id" => 95_419_412, + "number" => 14, + "title" => "Issue closed from commit from PR", + "user" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "labels" => [], - "state" => "closed", - "locked" => false, - "assignee" => nil, + "type" => "User", + "site_admin" => false }, + "labels" => [], + "state" => "closed", + "locked" => false, + "assignee" => nil, "assignees" => [], - "milestone" => nil, - "comments" => 0, - "created_at" => "2015-07-16T12:06:08Z", - "updated_at" => "2015-07-16T12:21:42Z", - "closed_at" => "2015-07-16T12:21:42Z", - "body" => "" }] + "milestone" => nil, + "comments" => 0, + "created_at" => "2015-07-16T12:06:08Z", + "updated_at" => "2015-07-16T12:21:42Z", + "closed_at" => "2015-07-16T12:21:42Z", + "body" => "" }] # Check that they are blank to begin with expect(issues.first["events"]).to be_nil @@ -360,63 +360,63 @@ fetcher.fetch_events_async(issues) issue_events = issues.first["events"] - expected_events = [{ "id" => 357_462_189, - "url" => + expected_events = [{ "id" => 357_462_189, + "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/events/357462189", - "actor" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "actor" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "event" => "referenced", - "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", + "type" => "User", + "site_admin" => false }, + "event" => "referenced", + "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", "commit_url" => "https://api.github.com/repos/skywinder/changelog_test/commits/decfe840d1a1b86e0c28700de5362d3365a29555", "created_at" => "2015-07-16T12:21:16Z" }, - { "id" => 357_462_542, - "url" => + { "id" => 357_462_542, + "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/events/357462542", - "actor" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "actor" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "event" => "closed", - "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", + "type" => "User", + "site_admin" => false }, + "event" => "closed", + "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", "commit_url" => "https://api.github.com/repos/skywinder/changelog_test/commits/decfe840d1a1b86e0c28700de5362d3365a29555", "created_at" => "2015-07-16T12:21:42Z" }] @@ -436,12 +436,12 @@ describe "#fetch_date_of_tag" do context "when API call is valid", :vcr do it "returns date" do - tag = { "name" => "v0.0.3", + tag = { "name" => "v0.0.3", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.3", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.3", - "commit" => + "commit" => { "sha" => "a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90" } } @@ -469,32 +469,32 @@ describe "#fetch_commit" do context "when API call is valid", :vcr do it "returns commit" do - event = { "id" => 357_462_189, - "url" => + event = { "id" => 357_462_189, + "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/events/357462189", - "actor" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "actor" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "event" => "referenced", - "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", + "type" => "User", + "site_admin" => false }, + "event" => "referenced", + "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", "commit_url" => "https://api.github.com/repos/skywinder/changelog_test/commits/decfe840d1a1b86e0c28700de5362d3365a29555", "created_at" => "2015-07-16T12:21:16Z" } From 6cfb746f637e5c20d9c5601ee5a85eca74a4de1c Mon Sep 17 00:00:00 2001 From: Chris Denneen Date: Mon, 29 Mar 2021 14:01:06 -0400 Subject: [PATCH 128/128] Updates for rubocop and TOKEN consistency --- .../gitlab_fetcher.rb | 21 +- spec/unit/gitlab_fetcher_spec.rb | 366 +++++++++--------- 2 files changed, 192 insertions(+), 195 deletions(-) diff --git a/lib/github_changelog_generator/gitlab_fetcher.rb b/lib/github_changelog_generator/gitlab_fetcher.rb index 721c944..1b6793f 100644 --- a/lib/github_changelog_generator/gitlab_fetcher.rb +++ b/lib/github_changelog_generator/gitlab_fetcher.rb @@ -14,10 +14,10 @@ class GitlabFetcher PER_PAGE_NUMBER = 100 MAX_THREAD_NUMBER = 25 MAX_FORBIDDEN_RETRIES = 100 - CHANGELOG_AUTH_TOKEN = "CHANGELOG_AUTH_TOKEN" + CHANGELOG_GITHUB_TOKEN = "CHANGELOG_GITHUB_TOKEN" RATE_LIMIT_EXCEEDED_MSG = "Warning: Can't finish operation: GitLab API rate limit exceeded, changelog may be " \ "missing some issues. You can limit the number of issues fetched using the `--max-issues NUM` argument." - NO_TOKEN_PROVIDED = "Warning: No token provided (-t option) and variable $CHANGELOG_AUTH_TOKEN was not found. " \ + NO_TOKEN_PROVIDED = "Warning: No token provided (-t option) and variable $CHANGELOG_GITHUB_TOKEN was not found. " \ "This script can make only 50 requests to GitLab API per hour without token!" # @param options [Hash] Options passed in @@ -237,9 +237,8 @@ def fetch_compare(older, newer) commit["sha"] = commit["id"] end # TODO: do not know what the equivalent for gitlab is - if compare_data["compare_same_ref"] == true - raise StandardError, "Sha #{older} and sha #{newer} are not related; please file a github-changelog-generator issue and describe how to replicate this issue." - end + raise StandardError, "Sha #{older} and sha #{newer} are not related; please file a github-changelog-generator issue and describe how to replicate this issue." if compare_data["compare_same_ref"] == true + @compares["#{older}...#{newer}"] = stringify_keys_deep(compare_data.to_hash) end @compares["#{older}...#{newer}"] @@ -356,10 +355,8 @@ def extract_request_args(args) # 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 - def check_response - Retriable.retriable(retry_options) do - yield - end + def check_response(&block) + Retriable.retriable(retry_options, &block) rescue MovedPermanentlyError => e fail_with_message(e, "The repository has moved, update your configuration") rescue Gitlab::Error::Forbidden => e @@ -407,7 +404,7 @@ def sys_abort(msg) # # @param [String] log_string def print_in_same_line(log_string) - print log_string + "\r" + print "#{log_string}\r" end # Print long line with spaces on same line to clear prev message @@ -416,11 +413,11 @@ def print_empty_line end # Returns AUTH token. First try to use variable, provided by --token option, - # otherwise try to fetch it from CHANGELOG_AUTH_TOKEN env variable. + # otherwise try to fetch it from CHANGELOG_GITHUB_TOKEN env variable. # # @return [String] def fetch_auth_token - env_var = @options[:token].presence || ENV["CHANGELOG_AUTH_TOKEN"] + env_var = @options[:token].presence || ENV["CHANGELOG_GITHUB_TOKEN"] GitHubChangelogGenerator::Helper.log.warn NO_TOKEN_PROVIDED unless env_var diff --git a/spec/unit/gitlab_fetcher_spec.rb b/spec/unit/gitlab_fetcher_spec.rb index 1935206..a7aa116 100644 --- a/spec/unit/gitlab_fetcher_spec.rb +++ b/spec/unit/gitlab_fetcher_spec.rb @@ -37,7 +37,7 @@ end describe "#fetch_auth_token" do - token = GitLabChangelogGenerator::GitlabFetcher::CHANGELOG_AUTH_TOKEN + token = GitLabChangelogGenerator::GitlabFetcher::CHANGELOG_GITHUB_TOKEN context "when token in ENV exist" do before { stub_const("ENV", ENV.to_hash.merge(token => VALID_TOKEN)) } subject { fetcher.send(:fetch_auth_token) } @@ -102,39 +102,39 @@ # TODO: swap for Gitlab API context "when API call is valid", :vcr do it "should return tags" do - expected_tags = [{ "name" => "v0.0.3", + expected_tags = [{ "name" => "v0.0.3", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.3", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.3", - "commit" => + "commit" => { "sha" => "a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90" } }, - { "name" => "v0.0.2", + { "name" => "v0.0.2", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.2", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.2", - "commit" => + "commit" => { "sha" => "9b35bb13dcd15b68e7bcbf10cde5eb937a54f710", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/9b35bb13dcd15b68e7bcbf10cde5eb937a54f710" } }, - { "name" => "v0.0.1", + { "name" => "v0.0.1", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.1", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.1", - "commit" => + "commit" => { "sha" => "4c2d6d1ed58bdb24b870dcb5d9f2ceed0283d69d", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/4c2d6d1ed58bdb24b870dcb5d9f2ceed0283d69d" } }, - { "name" => "0.0.4", + { "name" => "0.0.4", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/0.0.4", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/0.0.4", - "commit" => + "commit" => { "sha" => "ece0c3ab7142b21064b885061c55ede00ef6ce94", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/ece0c3ab7142b21064b885061c55ede00ef6ce94" } }] @@ -160,50 +160,50 @@ it "returns issue with proper key/values" do issues, _pull_requests = fetcher.fetch_closed_issues_and_pr - expected_issue = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", + expected_issue = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", "repository_url" => "https://api.github.com/repos/skywinder/changelog_test", - "labels_url" => + "labels_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/labels{/name}", - "comments_url" => + "comments_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/comments", - "events_url" => + "events_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/events", - "html_url" => "https://github.com/skywinder/changelog_test/issues/14", - "id" => 95_419_412, - "number" => 14, - "title" => "Issue closed from commit from PR", - "user" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "html_url" => "https://github.com/skywinder/changelog_test/issues/14", + "id" => 95_419_412, + "number" => 14, + "title" => "Issue closed from commit from PR", + "user" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "labels" => [], - "state" => "closed", - "locked" => false, - "assignee" => nil, + "type" => "User", + "site_admin" => false }, + "labels" => [], + "state" => "closed", + "locked" => false, + "assignee" => nil, "assignees" => [], - "milestone" => nil, - "comments" => 0, - "created_at" => "2015-07-16T12:06:08Z", - "updated_at" => "2015-07-16T12:21:42Z", - "closed_at" => "2015-07-16T12:21:42Z", - "body" => "" } + "milestone" => nil, + "comments" => 0, + "created_at" => "2015-07-16T12:06:08Z", + "updated_at" => "2015-07-16T12:21:42Z", + "closed_at" => "2015-07-16T12:21:42Z", + "body" => "" } # Convert times to Time expected_issue.each_pair do |k, v| @@ -216,55 +216,55 @@ it "returns pull request with proper key/values" do _issues, pull_requests = fetcher.fetch_closed_issues_and_pr - expected_pr = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21", + expected_pr = { "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21", "repository_url" => "https://api.github.com/repos/skywinder/changelog_test", - "labels_url" => + "labels_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21/labels{/name}", - "comments_url" => + "comments_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21/comments", - "events_url" => + "events_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/21/events", - "html_url" => "https://github.com/skywinder/changelog_test/pull/21", - "id" => 124_925_759, - "number" => 21, - "title" => "Merged br (should appear in change log with #20)", - "user" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "html_url" => "https://github.com/skywinder/changelog_test/pull/21", + "id" => 124_925_759, + "number" => 21, + "title" => "Merged br (should appear in change log with #20)", + "user" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "labels" => [], - "state" => "closed", - "locked" => false, - "assignee" => nil, + "type" => "User", + "site_admin" => false }, + "labels" => [], + "state" => "closed", + "locked" => false, + "assignee" => nil, "assignees" => [], - "milestone" => nil, - "comments" => 0, - "created_at" => "2016-01-05T09:24:08Z", - "updated_at" => "2016-01-05T09:26:53Z", - "closed_at" => "2016-01-05T09:24:27Z", - "pull_request" => - { "url" => "https://api.github.com/repos/skywinder/changelog_test/pulls/21", - "html_url" => "https://github.com/skywinder/changelog_test/pull/21", - "diff_url" => "https://github.com/skywinder/changelog_test/pull/21.diff", + "milestone" => nil, + "comments" => 0, + "created_at" => "2016-01-05T09:24:08Z", + "updated_at" => "2016-01-05T09:26:53Z", + "closed_at" => "2016-01-05T09:24:27Z", + "pull_request" => + { "url" => "https://api.github.com/repos/skywinder/changelog_test/pulls/21", + "html_url" => "https://github.com/skywinder/changelog_test/pull/21", + "diff_url" => "https://github.com/skywinder/changelog_test/pull/21.diff", "patch_url" => "https://github.com/skywinder/changelog_test/pull/21.patch" }, - "body" => + "body" => "to test https://github.com/skywinder/github-changelog-generator/pull/305\r\nshould appear in change log with #20" } # Convert times to Time @@ -308,51 +308,51 @@ describe "#fetch_events_async" do context "when API call is valid", :vcr do it "populates issues" do - issues = [{ "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", + issues = [{ "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14", "repository_url" => "https://api.github.com/repos/skywinder/changelog_test", - "labels_url" => + "labels_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/labels{/name}", - "comments_url" => + "comments_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/comments", - "events_url" => + "events_url" => "https://api.github.com/repos/skywinder/changelog_test/issues/14/events", - "html_url" => "https://github.com/skywinder/changelog_test/issues/14", - "id" => 95_419_412, - "number" => 14, - "title" => "Issue closed from commit from PR", - "user" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "html_url" => "https://github.com/skywinder/changelog_test/issues/14", + "id" => 95_419_412, + "number" => 14, + "title" => "Issue closed from commit from PR", + "user" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "labels" => [], - "state" => "closed", - "locked" => false, - "assignee" => nil, + "type" => "User", + "site_admin" => false }, + "labels" => [], + "state" => "closed", + "locked" => false, + "assignee" => nil, "assignees" => [], - "milestone" => nil, - "comments" => 0, - "created_at" => "2015-07-16T12:06:08Z", - "updated_at" => "2015-07-16T12:21:42Z", - "closed_at" => "2015-07-16T12:21:42Z", - "body" => "" }] + "milestone" => nil, + "comments" => 0, + "created_at" => "2015-07-16T12:06:08Z", + "updated_at" => "2015-07-16T12:21:42Z", + "closed_at" => "2015-07-16T12:21:42Z", + "body" => "" }] # Check that they are blank to begin with expect(issues.first["events"]).to be_nil @@ -360,63 +360,63 @@ fetcher.fetch_events_async(issues) issue_events = issues.first["events"] - expected_events = [{ "id" => 357_462_189, - "url" => + expected_events = [{ "id" => 357_462_189, + "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/events/357462189", - "actor" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "actor" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "event" => "referenced", - "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", + "type" => "User", + "site_admin" => false }, + "event" => "referenced", + "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", "commit_url" => "https://api.github.com/repos/skywinder/changelog_test/commits/decfe840d1a1b86e0c28700de5362d3365a29555", "created_at" => "2015-07-16T12:21:16Z" }, - { "id" => 357_462_542, - "url" => + { "id" => 357_462_542, + "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/events/357462542", - "actor" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "actor" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "event" => "closed", - "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", + "type" => "User", + "site_admin" => false }, + "event" => "closed", + "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", "commit_url" => "https://api.github.com/repos/skywinder/changelog_test/commits/decfe840d1a1b86e0c28700de5362d3365a29555", "created_at" => "2015-07-16T12:21:42Z" }] @@ -436,12 +436,12 @@ describe "#fetch_date_of_tag" do context "when API call is valid", :vcr do it "returns date" do - tag = { "name" => "v0.0.3", + tag = { "name" => "v0.0.3", "zipball_url" => "https://api.github.com/repos/skywinder/changelog_test/zipball/v0.0.3", "tarball_url" => "https://api.github.com/repos/skywinder/changelog_test/tarball/v0.0.3", - "commit" => + "commit" => { "sha" => "a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90", "url" => "https://api.github.com/repos/skywinder/changelog_test/commits/a0cba2b1a1ea9011ab07ee1ac140ba5a5eb8bd90" } } @@ -469,32 +469,32 @@ describe "#fetch_commit" do context "when API call is valid", :vcr do it "returns commit" do - event = { "id" => 357_462_189, - "url" => + event = { "id" => 357_462_189, + "url" => "https://api.github.com/repos/skywinder/changelog_test/issues/events/357462189", - "actor" => - { "login" => "skywinder", - "id" => 3_356_474, - "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", - "gravatar_id" => "", - "url" => "https://api.github.com/users/skywinder", - "html_url" => "https://github.com/skywinder", - "followers_url" => "https://api.github.com/users/skywinder/followers", - "following_url" => + "actor" => + { "login" => "skywinder", + "id" => 3_356_474, + "avatar_url" => "https://avatars.githubusercontent.com/u/3356474?v=3", + "gravatar_id" => "", + "url" => "https://api.github.com/users/skywinder", + "html_url" => "https://github.com/skywinder", + "followers_url" => "https://api.github.com/users/skywinder/followers", + "following_url" => "https://api.github.com/users/skywinder/following{/other_user}", - "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", - "starred_url" => + "gists_url" => "https://api.github.com/users/skywinder/gists{/gist_id}", + "starred_url" => "https://api.github.com/users/skywinder/starred{/owner}{/repo}", - "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", - "organizations_url" => "https://api.github.com/users/skywinder/orgs", - "repos_url" => "https://api.github.com/users/skywinder/repos", - "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", + "subscriptions_url" => "https://api.github.com/users/skywinder/subscriptions", + "organizations_url" => "https://api.github.com/users/skywinder/orgs", + "repos_url" => "https://api.github.com/users/skywinder/repos", + "events_url" => "https://api.github.com/users/skywinder/events{/privacy}", "received_events_url" => "https://api.github.com/users/skywinder/received_events", - "type" => "User", - "site_admin" => false }, - "event" => "referenced", - "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", + "type" => "User", + "site_admin" => false }, + "event" => "referenced", + "commit_id" => "decfe840d1a1b86e0c28700de5362d3365a29555", "commit_url" => "https://api.github.com/repos/skywinder/changelog_test/commits/decfe840d1a1b86e0c28700de5362d3365a29555", "created_at" => "2015-07-16T12:21:16Z" }