Linting
This commit is contained in:
parent
0189c2d736
commit
db1ffdd59b
|
@ -1,3 +1,4 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
class Array
|
class Array
|
||||||
def stringify_keys_deep!
|
def stringify_keys_deep!
|
||||||
new_ar = []
|
new_ar = []
|
||||||
|
|
|
@ -75,7 +75,7 @@ module GitHubChangelogGenerator
|
||||||
begin
|
begin
|
||||||
commit = @fetcher.fetch_commit(event)
|
commit = @fetcher.fetch_commit(event)
|
||||||
issue["actual_date"] = commit["commit"]["author"]["date"]
|
issue["actual_date"] = commit["commit"]["author"]["date"]
|
||||||
|
|
||||||
# issue['actual_date'] = commit['author']['date']
|
# issue['actual_date'] = commit['author']['date']
|
||||||
rescue
|
rescue
|
||||||
puts "Warning: Can't fetch commit #{event['commit_id']}. It is probably referenced from another repo."
|
puts "Warning: Can't fetch commit #{event['commit_id']}. It is probably referenced from another repo."
|
||||||
|
|
|
@ -178,9 +178,9 @@ module GitHubChangelogGenerator
|
||||||
return "#{line} ({Null user})" unless user
|
return "#{line} ({Null user})" unless user
|
||||||
|
|
||||||
if @options[:usernames_as_github_logins]
|
if @options[:usernames_as_github_logins]
|
||||||
"#{line} (@#{user["login"]})"
|
"#{line} (@#{user['login']})"
|
||||||
else
|
else
|
||||||
"#{line} ([#{user["login"]}](#{user["html_url"]}))"
|
"#{line} ([#{user['login']}](#{user['html_url']}))"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -101,7 +101,7 @@ module GitHubChangelogGenerator
|
||||||
def get_filtered_tags(all_tags)
|
def get_filtered_tags(all_tags)
|
||||||
filtered_tags = filter_since_tag(all_tags)
|
filtered_tags = filter_since_tag(all_tags)
|
||||||
filtered_tags = filter_due_tag(filtered_tags)
|
filtered_tags = filter_due_tag(filtered_tags)
|
||||||
filtered_tags = filter_between_tags(filtered_tags)
|
filter_between_tags(filtered_tags)
|
||||||
end
|
end
|
||||||
|
|
||||||
# @param [Array] all_tags all tags
|
# @param [Array] all_tags all tags
|
||||||
|
@ -148,7 +148,7 @@ module GitHubChangelogGenerator
|
||||||
# @return [Array] filtered tags according :between_tags option
|
# @return [Array] filtered tags according :between_tags option
|
||||||
def filter_between_tags(all_tags)
|
def filter_between_tags(all_tags)
|
||||||
filtered_tags = all_tags
|
filtered_tags = all_tags
|
||||||
tag_names = filtered_tags.map { |ft| ft['name'] }
|
tag_names = filtered_tags.map { |ft| ft["name"] }
|
||||||
|
|
||||||
if @options[:between_tags]
|
if @options[:between_tags]
|
||||||
@options[:between_tags].each do |tag|
|
@options[:between_tags].each do |tag|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
class Hash
|
class Hash
|
||||||
def stringify_keys_deep!
|
def stringify_keys_deep!
|
||||||
new_hash = {}
|
new_hash = {}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
module GitHubChangelogGenerator
|
module GitHubChangelogGenerator
|
||||||
# A Fetcher responsible for all requests to GitHub and all basic manipulation with related data
|
# A Fetcher responsible for all requests to GitHub and all basic manipulation with related data
|
||||||
# (such as filtering, validating, e.t.c)
|
# (such as filtering, validating, e.t.c)
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
# fetcher = GitHubChangelogGenerator::OctoFetcher.new options
|
# fetcher = GitHubChangelogGenerator::OctoFetcher.new(options)
|
||||||
|
|
||||||
class OctoFetcher
|
class OctoFetcher
|
||||||
PER_PAGE_NUMBER = 100
|
PER_PAGE_NUMBER = 100
|
||||||
MAX_THREAD_NUMBER = 1
|
MAX_THREAD_NUMBER = 1
|
||||||
|
@ -14,16 +14,21 @@ module GitHubChangelogGenerator
|
||||||
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_GITHUB_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 GitHub API per hour without token!"
|
||||||
|
|
||||||
def initialize(options = {})
|
# @param options [Hash] Options passed in
|
||||||
|
# @option options [String] :user GitHub username
|
||||||
|
# @option options [String] :project GitHub 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
|
||||||
|
# @option options [Boolean] :cache_log If using http_cache, this is the cache log file path
|
||||||
|
def initialize(options = {}) # rubocop:disable Metrics/CyclomaticComplexity
|
||||||
@options = options || {}
|
@options = options || {}
|
||||||
@user = @options[:user]
|
@user = @options[:user]
|
||||||
@project = @options[:project]
|
@project = @options[:project]
|
||||||
# Only issues updated at or after this time are returned. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.
|
@since = @options[:since]
|
||||||
@since = @options[:since] # eg. Time.parse("2016-01-01 10:00:00").iso8601
|
|
||||||
# Use ActiveSupport::Cache::FileStore to cache http requests
|
|
||||||
@http_cache = @options[:http_cache]
|
@http_cache = @options[:http_cache]
|
||||||
@cache_file = @options.fetch(:cache_file, '/tmp/github-changelog-http-cache') if @http_cache
|
@cache_file = @options.fetch(:cache_file, "/tmp/github-changelog-http-cache") if @http_cache
|
||||||
@cache_log = @options.fetch(:cache_log, '/tmp/github-changelog-logger.log') if @http_cache
|
@cache_log = @options.fetch(:cache_log, "/tmp/github-changelog-logger.log") if @http_cache
|
||||||
init_cache if @http_cache
|
init_cache if @http_cache
|
||||||
|
|
||||||
@github_token = fetch_github_token
|
@github_token = fetch_github_token
|
||||||
|
@ -33,17 +38,16 @@ module GitHubChangelogGenerator
|
||||||
@github_options[:access_token] = @github_token unless @github_token.nil?
|
@github_options[:access_token] = @github_token unless @github_token.nil?
|
||||||
@github_options[:api_endpoint] = @options[:github_endpoint] unless @options[:github_endpoint].nil?
|
@github_options[:api_endpoint] = @options[:github_endpoint] unless @options[:github_endpoint].nil?
|
||||||
|
|
||||||
|
|
||||||
client_type = @options[:github_endpoint].nil? ? Octokit::Client : Octokit::EnterpriseAdminClient
|
client_type = @options[:github_endpoint].nil? ? Octokit::Client : Octokit::EnterpriseAdminClient
|
||||||
@client = client_type.new(@github_options)
|
@client = client_type.new(@github_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def init_cache
|
def init_cache
|
||||||
middleware_opts = {
|
middleware_opts = {
|
||||||
:serializer => Marshal,
|
serializer: Marshal,
|
||||||
:store => ActiveSupport::Cache::FileStore.new(@cache_file),
|
store: ActiveSupport::Cache::FileStore.new(@cache_file),
|
||||||
:logger => Logger.new(@cache_log),
|
logger: Logger.new(@cache_log),
|
||||||
:shared_cache => false
|
shared_cache: false
|
||||||
}
|
}
|
||||||
stack = Faraday::RackBuilder.new do |builder|
|
stack = Faraday::RackBuilder.new do |builder|
|
||||||
builder.use Faraday::HttpCache, middleware_opts
|
builder.use Faraday::HttpCache, middleware_opts
|
||||||
|
@ -98,7 +102,7 @@ module GitHubChangelogGenerator
|
||||||
|
|
||||||
if tags.count == 0
|
if tags.count == 0
|
||||||
Helper.log.warn "Warning: Can't find any tags in repo.\
|
Helper.log.warn "Warning: Can't find any tags in repo.\
|
||||||
Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
Make sure, that you push tags to remote repo via 'git push --tags'"
|
||||||
else
|
else
|
||||||
Helper.log.info "Found #{tags.count} tags"
|
Helper.log.info "Found #{tags.count} tags"
|
||||||
end
|
end
|
||||||
|
@ -264,11 +268,11 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
||||||
begin
|
begin
|
||||||
value = yield
|
value = yield
|
||||||
rescue Octokit::Unauthorized => e
|
rescue Octokit::Unauthorized => e
|
||||||
Helper.log.error e.message.red
|
Helper.log.error e.message
|
||||||
abort "Error: wrong GitHub token"
|
abort "Error: wrong GitHub token"
|
||||||
rescue Octokit::Forbidden => e
|
rescue Octokit::Forbidden => e
|
||||||
Helper.log.warn e.message.red
|
Helper.log.warn e.message
|
||||||
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
|
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG
|
||||||
Helper.log.warn @client.rate_limit
|
Helper.log.warn @client.rate_limit
|
||||||
end
|
end
|
||||||
value
|
value
|
||||||
|
@ -293,7 +297,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
||||||
def fetch_github_token
|
def fetch_github_token
|
||||||
env_var = @options[:token] ? @options[:token] : (ENV.fetch CHANGELOG_GITHUB_TOKEN, nil)
|
env_var = @options[:token] ? @options[:token] : (ENV.fetch CHANGELOG_GITHUB_TOKEN, nil)
|
||||||
|
|
||||||
Helper.log.warn NO_TOKEN_PROVIDED.yellow unless env_var
|
Helper.log.warn NO_TOKEN_PROVIDED unless env_var
|
||||||
|
|
||||||
env_var
|
env_var
|
||||||
end
|
end
|
||||||
|
|
|
@ -215,8 +215,8 @@ module GitHubChangelogGenerator
|
||||||
enhancement_prefix: "**Implemented enhancements:**",
|
enhancement_prefix: "**Implemented enhancements:**",
|
||||||
git_remote: "origin",
|
git_remote: "origin",
|
||||||
http_cache: true,
|
http_cache: true,
|
||||||
cache_file: '/tmp/github-changelog-http-cache',
|
cache_file: "/tmp/github-changelog-http-cache",
|
||||||
cache_log: '/tmp/github-changelog-logger.log',
|
cache_log: "/tmp/github-changelog-logger.log"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -46,9 +46,9 @@ VCR.configure do |c|
|
||||||
preserve_exact_body_bytes: true,
|
preserve_exact_body_bytes: true,
|
||||||
decode_compressed_response: true
|
decode_compressed_response: true
|
||||||
}
|
}
|
||||||
c.filter_sensitive_data('<GITHUB_TOKEN>') {
|
c.filter_sensitive_data("<GITHUB_TOKEN>") do
|
||||||
"token #{ENV.fetch('CHANGELOG_GITHUB_TOKEN')}"
|
"token #{ENV.fetch('CHANGELOG_GITHUB_TOKEN')}"
|
||||||
}
|
end
|
||||||
|
|
||||||
c.configure_rspec_metadata!
|
c.configure_rspec_metadata!
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
describe GitHubChangelogGenerator::Generator do
|
describe GitHubChangelogGenerator::Generator do
|
||||||
def tag_with_name(tag)
|
def tag_with_name(tag)
|
||||||
{
|
{
|
||||||
'name' => tag
|
"name" => tag
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
VALID_TOKEN = "0123456789abcdef"
|
VALID_TOKEN = "0123456789abcdef"
|
||||||
INVALID_TOKEN = "0000000000000000"
|
INVALID_TOKEN = "0000000000000000"
|
||||||
|
|
||||||
|
@ -60,7 +61,6 @@ describe GitHubChangelogGenerator::OctoFetcher do
|
||||||
|
|
||||||
describe "#github_fetch_tags" do
|
describe "#github_fetch_tags" do
|
||||||
context "when wrong token provided", :vcr do
|
context "when wrong token provided", :vcr do
|
||||||
|
|
||||||
let(:options) do
|
let(:options) do
|
||||||
{
|
{
|
||||||
user: "skywinder",
|
user: "skywinder",
|
||||||
|
@ -75,7 +75,6 @@ describe GitHubChangelogGenerator::OctoFetcher do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when API call is valid", :vcr do
|
context "when API call is valid", :vcr do
|
||||||
|
|
||||||
it "should return tags" do
|
it "should return tags" do
|
||||||
expected_tags = [{ "name" => "v0.0.3",
|
expected_tags = [{ "name" => "v0.0.3",
|
||||||
"zipball_url" =>
|
"zipball_url" =>
|
||||||
|
@ -125,8 +124,7 @@ describe GitHubChangelogGenerator::OctoFetcher do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#fetch_closed_issues_and_pr" do
|
describe "#fetch_closed_issues_and_pr" do
|
||||||
context "when API call is valid", :vcr do
|
context "when API call is valid", :vcr do
|
||||||
|
|
||||||
it "returns issues" do
|
it "returns issues" do
|
||||||
issues, pull_requests = fetcher.fetch_closed_issues_and_pr
|
issues, pull_requests = fetcher.fetch_closed_issues_and_pr
|
||||||
expect(issues.size).to eq(7)
|
expect(issues.size).to eq(7)
|
||||||
|
@ -173,7 +171,7 @@ describe GitHubChangelogGenerator::OctoFetcher do
|
||||||
"state" => "closed",
|
"state" => "closed",
|
||||||
"locked" => false,
|
"locked" => false,
|
||||||
"assignee" => nil,
|
"assignee" => nil,
|
||||||
"assignees" => [],
|
"assignees" => [],
|
||||||
"milestone" => nil,
|
"milestone" => nil,
|
||||||
"comments" => 0,
|
"comments" => 0,
|
||||||
"created_at" => "2015-07-16T12:06:08Z",
|
"created_at" => "2015-07-16T12:06:08Z",
|
||||||
|
@ -229,7 +227,7 @@ describe GitHubChangelogGenerator::OctoFetcher do
|
||||||
"state" => "closed",
|
"state" => "closed",
|
||||||
"locked" => false,
|
"locked" => false,
|
||||||
"assignee" => nil,
|
"assignee" => nil,
|
||||||
"assignees" => [],
|
"assignees" => [],
|
||||||
"milestone" => nil,
|
"milestone" => nil,
|
||||||
"comments" => 0,
|
"comments" => 0,
|
||||||
"created_at" => "2016-01-05T09:24:08Z",
|
"created_at" => "2016-01-05T09:24:08Z",
|
||||||
|
@ -322,7 +320,7 @@ describe GitHubChangelogGenerator::OctoFetcher do
|
||||||
"state" => "closed",
|
"state" => "closed",
|
||||||
"locked" => false,
|
"locked" => false,
|
||||||
"assignee" => nil,
|
"assignee" => nil,
|
||||||
"assignees" => [],
|
"assignees" => [],
|
||||||
"milestone" => nil,
|
"milestone" => nil,
|
||||||
"comments" => 0,
|
"comments" => 0,
|
||||||
"created_at" => "2015-07-16T12:06:08Z",
|
"created_at" => "2015-07-16T12:06:08Z",
|
||||||
|
@ -411,7 +409,6 @@ describe GitHubChangelogGenerator::OctoFetcher do
|
||||||
|
|
||||||
describe "#fetch_date_of_tag" do
|
describe "#fetch_date_of_tag" do
|
||||||
context "when API call is valid", :vcr do
|
context "when API call is valid", :vcr do
|
||||||
|
|
||||||
it "returns date" do
|
it "returns date" do
|
||||||
tag = { "name" => "v0.0.3",
|
tag = { "name" => "v0.0.3",
|
||||||
"zipball_url" =>
|
"zipball_url" =>
|
||||||
|
@ -431,7 +428,6 @@ describe GitHubChangelogGenerator::OctoFetcher do
|
||||||
|
|
||||||
describe "#fetch_commit" do
|
describe "#fetch_commit" do
|
||||||
context "when API call is valid", :vcr do
|
context "when API call is valid", :vcr do
|
||||||
|
|
||||||
it "returns commit" do
|
it "returns commit" do
|
||||||
event = { "id" => 357_462_189,
|
event = { "id" => 357_462_189,
|
||||||
"url" =>
|
"url" =>
|
||||||
|
@ -481,8 +477,7 @@ describe GitHubChangelogGenerator::OctoFetcher do
|
||||||
"https://api.github.com/repos/skywinder/changelog_test/commits/7ec095e5e3caceacedabf44d0b9b10da17c92e51",
|
"https://api.github.com/repos/skywinder/changelog_test/commits/7ec095e5e3caceacedabf44d0b9b10da17c92e51",
|
||||||
# OLD API: "https://api.github.com/repos/skywinder/changelog_test/git/commits/7ec095e5e3caceacedabf44d0b9b10da17c92e51",
|
# OLD API: "https://api.github.com/repos/skywinder/changelog_test/git/commits/7ec095e5e3caceacedabf44d0b9b10da17c92e51",
|
||||||
"html_url" =>
|
"html_url" =>
|
||||||
"https://github.com/skywinder/changelog_test/commit/7ec095e5e3caceacedabf44d0b9b10da17c92e51" }]
|
"https://github.com/skywinder/changelog_test/commit/7ec095e5e3caceacedabf44d0b9b10da17c92e51" }]]
|
||||||
]
|
|
||||||
]
|
]
|
||||||
|
|
||||||
expectations.each do |property, val|
|
expectations.each do |property, val|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user