Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use sorbet #30

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .github/workflows/mega-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
# MegaLinter GitHub Action configuration file
# More info at https://megalinter.github.io
name: MegaLinter

on:
# Trigger mega-linter at every push. Action will also be visible from Pull Requests to main
push: # Comment this line to trigger action only on pull-requests (not recommended if you don't pay for GH Actions)
pull_request:
branches: [master, main]

env: # Comment env block if you do not want to apply fixes
# Apply linter fixes configuration
APPLY_FIXES: all # When active, APPLY_FIXES must also be defined as environment variable (in github/workflows/mega-linter.yml or other CI tool)
APPLY_FIXES_EVENT: pull_request # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all)
APPLY_FIXES_MODE: commit # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request)

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
build:
name: MegaLinter
runs-on: ubuntu-latest
steps:
# Git Checkout
- name: Checkout Code
uses: actions/checkout@v2
with:
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
fetch-depth: 0

# MegaLinter
- name: MegaLinter
id: ml
# You can override MegaLinter flavor used to have faster performances
# More info at https://megalinter.github.io/flavors/
uses: megalinter/megalinter@v5
env:
# All available variables are described in documentation
# https://megalinter.github.io/configuration/
VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} # Validates all source when push on main, else just the git diff with main. Override with true if you always want to lint all sources
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
# DISABLE: COPYPASTE,SPELL # Uncomment to disable copy-paste and spell checks

# Upload MegaLinter artifacts
- name: Archive production artifacts
if: ${{ success() }} || ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: MegaLinter reports
path: |
report
mega-linter.log

# Create pull request if applicable (for now works only on PR from same repository, not from forks)
- name: Create Pull Request with applied fixes
id: cpr
if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
commit-message: "[MegaLinter] Apply linters automatic fixes"
title: "[MegaLinter] Apply linters automatic fixes"
labels: bot
- name: Create PR output
if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"

# Push new commit if applicable (for now works only on PR from same repository, not from forks)
- name: Prepare commit
if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
run: sudo chown -Rc $UID .git/
- name: Commit and push applied linter fixes
if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }}
commit_message: "[MegaLinter] Apply linters fixes"
4 changes: 4 additions & 0 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ENABLE: RUBY
ENABLE_LINTERS:
- SPELL_MISSPELL
- MARKDOWN_MARKDOWNLINT
7 changes: 6 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
require: rubocop-rspec
require:
- standard
- rubocop-rspec

inherit_gem:
standard: config/base.yml
8 changes: 6 additions & 2 deletions firebase_dynamic_link.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'dry-configurable', '>= 0.9', '< 1.0'
spec.add_runtime_dependency 'faraday', '>= 0.16', '< 3.0'
spec.add_runtime_dependency 'faraday-net_http', '>= 1.0', '< 3.0'
spec.add_runtime_dependency 'sorbet-runtime'

spec.add_development_dependency 'appraisal', '~> 2.4.1'
spec.add_development_dependency 'bootsnap', '~> 1.9.3'
Expand All @@ -37,8 +38,11 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'pry', '~> 0.14.1'
spec.add_development_dependency 'rake', '>= 12.3.3'
spec.add_development_dependency 'rspec', '~> 3.10.0'
spec.add_development_dependency 'rubocop', '~> 1.22'
spec.add_development_dependency 'rubocop-rspec', '~> 2.5.0'
spec.add_development_dependency 'rubocop', '~> 1.29.0'
spec.add_development_dependency 'rubocop-rspec', '~> 2.11.1'
spec.add_development_dependency 'simplecov', '~> 0.17.1'
spec.add_development_dependency 'standard', '~> 1.12.1'
spec.add_development_dependency 'sorbet'
spec.add_development_dependency 'sord'
spec.add_development_dependency 'vcr', '~> 4.0', '>= 4.0.0'
end
27 changes: 14 additions & 13 deletions lib/firebase_dynamic_link.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# typed: true
# frozen_string_literal: true

require 'dry-configurable'
require 'dry/configurable/version'
require 'faraday'
require 'faraday/net_http' if Faraday::VERSION.to_f >= 2.0
require 'firebase_dynamic_link/client'
require 'firebase_dynamic_link/link_renderer'
require 'firebase_dynamic_link/version'
require "dry-configurable"
require "dry/configurable/version"
require "faraday"
require "faraday/net_http" if Faraday::VERSION.to_f >= 2.0
require "firebase_dynamic_link/client"
require "firebase_dynamic_link/link_renderer"
require "firebase_dynamic_link/version"

module FirebaseDynamicLink
extend Dry::Configurable
Expand Down Expand Up @@ -105,23 +106,23 @@ class QuotaExceeded < StandardError; end
# @since 1.0.0
# @!scope class
if USE_DRY_CONFIGURABLE_0_13
setting(:suffix_option, default: 'UNGUESSABLE', constructor: lambda { |value|
setting(:suffix_option, default: "UNGUESSABLE", constructor: lambda { |value|
if %w[SHORT
UNGUESSABLE].include?(value)
UNGUESSABLE].include?(value)
value
else
raise(FirebaseDynamicLink::InvalidConfig,
'default suffix option config is not valid')
"default suffix option config is not valid")
end
})
else
setting(:suffix_option, 'UNGUESSABLE') do |value|
setting(:suffix_option, "UNGUESSABLE") do |value|
if %w[SHORT
UNGUESSABLE].include?(value)
UNGUESSABLE].include?(value)
value
else
raise(FirebaseDynamicLink::InvalidConfig,
'default suffix option config is not valid')
"default suffix option config is not valid")
end
end

Expand Down
25 changes: 13 additions & 12 deletions lib/firebase_dynamic_link/client.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# typed: true
# frozen_string_literal: true

require 'uri'
require 'firebase_dynamic_link/connection'
require 'firebase_dynamic_link/link_renderer'
require 'case_transform2'
require "uri"
require "firebase_dynamic_link/connection"
require "firebase_dynamic_link/link_renderer"
require "case_transform2"

module FirebaseDynamicLink
# Main class that responsible to shorten link or parameters
Expand Down Expand Up @@ -31,9 +32,9 @@ def shorten_link(link, options = {})
suffix_option = options[:suffix_option] if options.key?(:suffix_option)

params = CaseTransform2.camel_lower(long_dynamic_link: build_link(link, options),
suffix: {
option: suffix_option || config.suffix_option
})
suffix: {
option: suffix_option || config.suffix_option
})
response = connection.post(nil, params.to_json)
link_renderer.render(response)
rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
Expand Down Expand Up @@ -131,12 +132,12 @@ def shorten_parameters(params, options = {})

dynamic_link_domain = options.delete(:dynamic_link_domain)
dynamic_link_domain ||= config.dynamic_link_domain || raise(FirebaseDynamicLink::InvalidConfig,
'Dynamic link domain is empty')
"Dynamic link domain is empty")

params = CaseTransform2.camel_lower(dynamic_link_info: params.merge(domainUriPrefix: dynamic_link_domain),
suffix: {
option: suffix_option || config.suffix_option
})
suffix: {
option: suffix_option || config.suffix_option
})
response = connection.post(nil, params.to_json)
link_renderer.render(response)
rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
Expand All @@ -153,7 +154,7 @@ def shorten_parameters(params, options = {})
def build_link(link, options)
dynamic_link_domain = options.delete(:dynamic_link_domain)
dynamic_link_domain ||= config.dynamic_link_domain || raise(FirebaseDynamicLink::InvalidConfig,
'Dynamic link domain is empty')
"Dynamic link domain is empty")
"#{dynamic_link_domain}?link=#{link}"
end

Expand Down
3 changes: 2 additions & 1 deletion lib/firebase_dynamic_link/connection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# frozen_string_literal: true

module FirebaseDynamicLink
Expand All @@ -11,7 +12,7 @@ class Connection

def initialize(end_point)
@client = Faraday::Connection.new(url: end_point,
headers: { 'Content-Type' => 'application/json' })
headers: {"Content-Type" => "application/json"})

client.options.timeout = FirebaseDynamicLink.config.timeout
client.options.open_timeout = FirebaseDynamicLink.config.open_timeout
Expand Down
17 changes: 9 additions & 8 deletions lib/firebase_dynamic_link/link_renderer.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# typed: true
# frozen_string_literal: true

module FirebaseDynamicLink
# Responsible to formatting output of Client#shorten_link
class LinkRenderer
# @param response [Faraday::Connection] http reponse
# @param response [Faraday::Connection] http response
# @return [Hash<Symbol, String or Hash>
# @example
# {
Expand All @@ -27,28 +28,28 @@ def render(response)

def render_success(response)
body = JSON.parse(response.body)
return raise_error(response) if body.key?('error')
return raise_error(response) if body.key?("error")

{
link: body['shortLink'],
preview_link: body['previewLink'],
warning: body['warning']
link: body["shortLink"],
preview_link: body["previewLink"],
warning: body["warning"]
}
end

def raise_error(response)
reason = response.reason_phrase.to_s if response.respond_to?(:reason_phrase)
message = begin
body = JSON.parse(response.body)
body['error']['message']
body["error"]["message"]
rescue JSON::ParserError, NoMethodError
response.body
end
raise FirebaseDynamicLink::ConnectionError, [reason, message].compact.join(': ')
raise FirebaseDynamicLink::ConnectionError, [reason, message].compact.join(": ")
end

def raise_limit_has_reached
raise FirebaseDynamicLink::QuotaExceeded, 'Request limit has been reached'
raise FirebaseDynamicLink::QuotaExceeded, "Request limit has been reached"
end
end
end
3 changes: 2 additions & 1 deletion lib/firebase_dynamic_link/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# typed: strict
# frozen_string_literal: true

module FirebaseDynamicLink
VERSION = '2.0.1'
VERSION = "2.0.1"
end
27 changes: 27 additions & 0 deletions report/IDE-config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
MegaLinter can help you to define the same linter configuration locally

INSTRUCTIONS

- Copy the content of IDE-config folder at the root of your repository
- if you are using Visual Studio Code, just reopen your project after the copy, and you will be prompted to install recommended extensions
- If not, you can install extensions manually using the following links.

IDE EXTENSIONS APPLICABLE TO YOUR PROJECT

rubocop (RUBY)
- atom:
- linter-rubocop: https://github.com/AtomLinter/linter-rubocop
- brackets:
- brackets-rubocop: https://github.com/smockle-archive/brackets-rubocop
- emacs:
- rubocop-emacs: https://github.com/rubocop-hq/rubocop-emacs
- flycheck: https://github.com/flycheck/flycheck
- idea:
- RubyMine: https://www.jetbrains.com/help/idea/2017.1/rubocop.html
- sublime:
- sublime_rubocop: https://github.com/pderichs/sublime_rubocop
- vim:
- vim-rubocop: https://github.com/ngmy/vim-rubocop
- ale: https://github.com/w0rp/ale
- vscode:
- VsCode Ruby Extension: https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby
8 changes: 8 additions & 0 deletions report/IDE-config/.ruby-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
#######################
# Rubocop Config file #
#######################

inherit_gem:
rubocop-github:
- config/default.yml
5 changes: 5 additions & 0 deletions report/IDE-config/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"rebornix.Ruby"
]
}
14 changes: 14 additions & 0 deletions report/linters_logs/SUCCESS-RUBY_RUBOCOP.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Results of rubocop linter (version 1.29.1)
See documentation on https://megalinter.github.io/descriptors/ruby_rubocop/
-----------------------------------------------

✅ [SUCCESS] lib/firebase_dynamic_link.rb - FIXED
✅ [SUCCESS] lib/firebase_dynamic_link/client.rb - FIXED
✅ [SUCCESS] lib/firebase_dynamic_link/connection.rb - FIXED
✅ [SUCCESS] lib/firebase_dynamic_link/link_renderer.rb - FIXED
✅ [SUCCESS] lib/firebase_dynamic_link/version.rb - FIXED
✅ [SUCCESS] spec/client_spec.rb - FIXED
✅ [SUCCESS] spec/connection_spec.rb - FIXED
✅ [SUCCESS] spec/firebase_dynamic_link_spec.rb - FIXED
✅ [SUCCESS] spec/link_renderer_spec.rb - FIXED
✅ [SUCCESS] spec/spec_helper.rb - FIXED
5 changes: 5 additions & 0 deletions report/linters_logs/SUCCESS-SPELL_MISSPELL.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Results of misspell linter (version 0.3.4)
See documentation on https://megalinter.github.io/descriptors/spell_misspell/
-----------------------------------------------

✅ [SUCCESS] for workspace /github/workspace
Loading