Skip to content

Commit

Permalink
Merge pull request #128 from simplybusiness/improve-logging-messages
Browse files Browse the repository at this point in the history
Improve logging messages
  • Loading branch information
addersuk authored Jul 10, 2023
2 parents f7f1202 + 443ae37 commit ae9476e
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
inherit_from: .rubocop_todo.yml

inherit_gem:
simplycop:
- .simplycop.yml
Expand Down
12 changes: 12 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-07-09 13:04:52 UTC using RuboCop version 1.52.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 11
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.0
3.2.1
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ group :development, :test do
gem 'rspec'
gem 'rspec-mocks', '~> 3.12.5'
gem 'simplecov', '< 0.18'
gem 'simplycop', '< 1.13.1'
gem 'simplycop', '1.13.0'
end

gem "faraday-retry", "~> 2.2"
5 changes: 4 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ GEM
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.2)
faraday-retry (2.2.0)
faraday (~> 2.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.6.3)
Expand Down Expand Up @@ -103,14 +105,15 @@ PLATFORMS
ruby

DEPENDENCIES
faraday-retry (~> 2.2)
jwt
octokit
pry
rspec
rspec-mocks (~> 3.12.5)
semantic
simplecov (< 0.18)
simplycop (< 1.13.1)
simplycop (= 1.13.0)

BUNDLED WITH
2.4.12
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ jobs:
uses: actions/checkout@v2
with:
repository: 'simplybusiness/dobby'
ref: 'v3.0.0'
ref: 'v3'
- name: Set up ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Bump version
uses: simplybusiness/dobby@v3.0.0
uses: simplybusiness/dobby@v3
env:
DOBBY_APP_ID: ${{ secrets.DOBBY_APP_ID }}
DOBBY_PRIVATE_KEY: ${{ secrets.DOBBY_PRIVATE_KEY }}
Expand Down
10 changes: 8 additions & 2 deletions lib/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ def initiate_version_update(level)
check_and_bump_version(level, head_branch_content, head_branch_blob_sha, updated_content)
else
add_reaction('confused')
puts "::error title=Unknown semver level::The semver level #{level} is not valid"
end
end

def fetch_content(ref:, path:)
content = client.contents(repo, path: path, query: { ref: ref })
begin
content = client.contents(repo, path: path, query: { ref: ref })
rescue Octokit::NotFound => e
puts "::error file=#{path},title=Error fetching file #{path}::#{e.message} "
raise e
end
Base64.decode64(content['content'])
end

Expand All @@ -60,7 +66,7 @@ def add_reaction(reaction)

def check_and_bump_version(level, head_branch_content, head_branch_blob_sha, updated_content)
if head_branch_content == updated_content
puts 'Nothing to update, the desired version bump is already present'
puts '::notice title=Nothing to update::Nothing to update, the desired version bump is already present'
else
client.update_contents(
repo, version_file_path,
Expand Down
3 changes: 2 additions & 1 deletion lib/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def initialize(config)
@config = config
comment = config.payload['comment']['body'].strip.downcase
error_msg = "Comment must be start with #{COMMAND_PREFIX}"
puts "::error title=Arguement Error::#{error_msg}"
raise ArgumentError, error_msg unless comment.start_with?(COMMAND_PREFIX)

cmd = comment.delete_prefix(COMMAND_PREFIX)
Expand All @@ -24,7 +25,7 @@ def call
when 'version'
action.initiate_version_update(options)
else
puts 'Command is invalid'
puts "::error title=Unknown command::The command #{command} is not valid"
action.add_reaction('confused')
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'octokit'
require 'json'
require 'jwt'
require 'openssl'

TEN_MINUTES = 600 # seconds

Expand Down Expand Up @@ -32,6 +33,7 @@ def bearer_token
exp: Time.now.to_i + TEN_MINUTES,
iss: ENV.fetch('DOBBY_APP_ID')
}

private_key = OpenSSL::PKey::RSA.new(ENV.fetch('DOBBY_PRIVATE_KEY'))

JWT.encode(payload, private_key, 'RS256')
Expand Down

0 comments on commit ae9476e

Please sign in to comment.