diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..52ded59 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: + # Maintain dependencies for GitHub Actions + - package-ecosystem: github-actions + directory: / + schedule: + interval: daily diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 074d665..b2edbce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,27 +17,27 @@ jobs: steps: - name: Install Crystal - uses: oprypin/install-crystal@v1 + uses: crystal-lang/install-crystal@v1 with: crystal: ${{ matrix.crystal }} - name: Download source - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install dependencies run: shards install - env: - SHARDS_OPTS: --ignore-crystal-version - name: Run specs - run: | - crystal spec - crystal spec --no-debug + run: crystal spec + + - name: Run specs (no-debug) + run: crystal spec --no-debug - name: Run specs (release) - run: | - crystal spec --release - crystal spec --release --no-debug + run: crystal spec --release + + - name: Run specs (release, no-debug) + run: crystal spec --release --no-debug - name: Build crash handler run: shards build crash_handler diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 111a388..ded57f7 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -4,52 +4,33 @@ on: push: branches: [master] +permissions: + contents: write + jobs: - build: + build-and-deploy: runs-on: ubuntu-latest steps: - name: Inject slug/short variables - uses: rlespinasse/github-slug-action@v3.x + uses: rlespinasse/github-slug-action@v4 - name: Install Crystal - uses: oprypin/install-crystal@v1 + uses: crystal-lang/install-crystal@v1 - name: Download source - uses: actions/checkout@v2 - with: - persist-credentials: false + uses: actions/checkout@v3 - name: Install dependencies run: shards install - env: - SHARDS_OPTS: --ignore-crystal-version - name: Build docs - run: | - sed -i -e 's:<.*>::g' README.md - crystal docs src/raven.cr --project-version="${{ env.GITHUB_REF_SLUG }}" --source-refname="${{ env.GITHUB_SHA_SHORT }}" - - - name: Upload artifacts - uses: actions/upload-artifact@v2 - with: - name: docs - path: docs - - deploy: - needs: build - runs-on: ubuntu-latest - steps: - - name: Download artifacts - uses: actions/download-artifact@v2 - with: - name: docs - path: docs + run: crystal docs src/raven.cr --project-version="${{ env.GITHUB_REF_SLUG }}" --source-refname="${{ env.GITHUB_SHA_SHORT }}" - name: Deploy docs 🚀 - uses: JamesIves/github-pages-deploy-action@3.7.1 + uses: JamesIves/github-pages-deploy-action@v4 with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - BRANCH: gh-pages - FOLDER: docs - CLEAN: true - CLEAN_EXCLUDE: '["img"]' + branch: gh-pages + folder: docs + clean: true + clean-exclude: | + img diff --git a/shard.yml b/shard.yml index a38506a..9acafac 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: raven -version: 1.9.2 +version: 1.9.3 authors: - Sijawusz Pur Rahnama @@ -15,15 +15,15 @@ dependencies: development_dependencies: timecop: github: crystal-community/timecop.cr - version: ~> 0.4.0 + version: ~> 0.5.0 ameba: github: crystal-ameba/ameba - version: ~> 1.0.0 + version: ~> 1.4.0 targets: crash_handler: main: src/crash_handler.cr -crystal: ">= 0.35.0" +crystal: ~> 1.6 license: MIT diff --git a/spec/raven/breadcrumb_buffer_spec.cr b/spec/raven/breadcrumb_buffer_spec.cr index 0eb6527..aa10936 100644 --- a/spec/raven/breadcrumb_buffer_spec.cr +++ b/spec/raven/breadcrumb_buffer_spec.cr @@ -1,6 +1,6 @@ require "../spec_helper" -private def with_breadcrumb_buffer +private def with_breadcrumb_buffer(&) breadcrumbs = Raven::BreadcrumbBuffer.new(10) yield breadcrumbs end diff --git a/spec/raven/client_spec.cr b/spec/raven/client_spec.cr index 8b13572..fd3a79f 100644 --- a/spec/raven/client_spec.cr +++ b/spec/raven/client_spec.cr @@ -10,7 +10,7 @@ private class ClientTest < Raven::Client end end -private def with_client +private def with_client(&) yield ClientTest.new(build_configuration) end diff --git a/spec/raven/client_state_spec.cr b/spec/raven/client_state_spec.cr index a8820ac..e7e3a4c 100644 --- a/spec/raven/client_state_spec.cr +++ b/spec/raven/client_state_spec.cr @@ -1,7 +1,7 @@ require "../spec_helper" require "timecop" -private def with_client_state +private def with_client_state(&) yield Raven::Client::State.new end diff --git a/spec/raven/configuration_spec.cr b/spec/raven/configuration_spec.cr index 68006a2..cfd45dc 100644 --- a/spec/raven/configuration_spec.cr +++ b/spec/raven/configuration_spec.cr @@ -12,13 +12,13 @@ private class RandomSampleFail < Random::PCG32 end end -private def with_configuration +private def with_configuration(&) with_clean_env do yield Raven::Configuration.new end end -private def with_configuration_with_dsn +private def with_configuration_with_dsn(&) with_configuration do |configuration| configuration.dsn = "http://12345:67890@sentry.localdomain:3000/sentry/42" yield configuration diff --git a/spec/raven/event_spec.cr b/spec/raven/event_spec.cr index e663eb5..3f77bb0 100644 --- a/spec/raven/event_spec.cr +++ b/spec/raven/event_spec.cr @@ -4,7 +4,7 @@ module Raven::Test class Exception < ::Exception; end end -private def with_event(clear = true, **opts) +private def with_event(clear = true, **opts, &) if clear Raven::Context.clear! Raven::BreadcrumbBuffer.clear! @@ -13,7 +13,7 @@ private def with_event(clear = true, **opts) yield event end -private def with_event_hash(**opts) +private def with_event_hash(**opts, &) with_event(**opts) do |event| yield event.to_hash end diff --git a/spec/raven/instance_spec.cr b/spec/raven/instance_spec.cr index ea348bd..7a493de 100644 --- a/spec/raven/instance_spec.cr +++ b/spec/raven/instance_spec.cr @@ -16,7 +16,7 @@ private class InstanceTest < Raven::Instance end end -private def with_instance(context = nil) +private def with_instance(context = nil, &) yield InstanceTest.new(context, build_configuration) end diff --git a/spec/raven/log_backend_spec.cr b/spec/raven/log_backend_spec.cr index f8ba9bf..1b14830 100644 --- a/spec/raven/log_backend_spec.cr +++ b/spec/raven/log_backend_spec.cr @@ -15,7 +15,7 @@ private def build_logger(source = nil, **opts) .for(source.to_s) end -private def with_clean_configuration +private def with_clean_configuration(&) prev_configuration = Raven.instance.configuration.dup begin Raven.instance.configuration = build_configuration diff --git a/spec/raven/processors/spec_helper.cr b/spec/raven/processors/spec_helper.cr index 75534f5..0f76136 100644 --- a/spec/raven/processors/spec_helper.cr +++ b/spec/raven/processors/spec_helper.cr @@ -1,6 +1,6 @@ require "../../spec_helper" -def with_processor(klass : Raven::Processor.class) +def with_processor(klass : Raven::Processor.class, &) configuration = Raven::Configuration.new client = Raven::Client.new(configuration) processor = klass.new(client) diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 567c790..20d4c41 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -3,7 +3,7 @@ require "log/spec" require "../src/raven" # Make sure we reset the env in case something leaks in -def with_clean_env +def with_clean_env(&) sentry_vars = ->{ ENV.to_h.select { |key, _| key.starts_with?("SENTRY_") } } previous_vars = sentry_vars.call begin diff --git a/src/crash_handler.cr b/src/crash_handler.cr index 5060e3a..39f9f43 100644 --- a/src/crash_handler.cr +++ b/src/crash_handler.cr @@ -73,7 +73,7 @@ module Raven end end - private def capture_with_options(*args, **options) + private def capture_with_options(*args, **options, &) options = DEFAULT_OPTS.merge(options) capture(*args, **options) do |event| yield event @@ -84,7 +84,7 @@ module Raven capture_with_options(*args, **options) { } end - private def capture_with_options(**options) + private def capture_with_options(**options, &) yield rescue ex : Raven::Error raise ex # Don't capture Raven errors diff --git a/src/raven/breadcrumb_buffer.cr b/src/raven/breadcrumb_buffer.cr index b676550..82b1d82 100644 --- a/src/raven/breadcrumb_buffer.cr +++ b/src/raven/breadcrumb_buffer.cr @@ -28,7 +28,7 @@ module Raven @buffer << crumb end - def record(**opts) : Nil + def record(**opts, &) : Nil crumb = Breadcrumb.new(**opts) yield crumb record crumb @@ -50,7 +50,7 @@ module Raven members.last? end - def each + def each(&) members.each do |breadcrumb| yield breadcrumb end diff --git a/src/raven/context.cr b/src/raven/context.cr index aeb19db..ec63543 100644 --- a/src/raven/context.cr +++ b/src/raven/context.cr @@ -25,8 +25,13 @@ module Raven end class_getter runtime_context : AnyHash::JSON do - v = Crystal::DESCRIPTION.match /^(.+?) (\d+[^\n]+)\n+LLVM: (\d+[^\n]+)\nDefault target: (.+?)$/m - _, name, version = v.not_nil! + version_pattern = /^(.+?) (\d+[^\n]+)\n+LLVM: (\d+[^\n]+)\nDefault target: (.+?)$/m + + unless match = Crystal::DESCRIPTION.match(version_pattern) + raise Raven::Error.new("Couldn't parse runtime version") + end + + _, name, version, _llvm_version, _target = match { name: name, version: version, diff --git a/src/raven/instance.cr b/src/raven/instance.cr index 592fc4c..68b8f81 100644 --- a/src/raven/instance.cr +++ b/src/raven/instance.cr @@ -69,7 +69,7 @@ module Raven end # :ditto: - def configure + def configure(&) yield configuration configure end @@ -127,7 +127,7 @@ module Raven # event.extra.merge! foo: "bar" # end # ``` - def capture(obj : Exception | String, **options, &block) + def capture(obj : Exception | String, **options, &) unless configuration.capture_allowed?(obj) Log.debug { "'#{obj}' excluded from capture: #{configuration.error_messages}" @@ -190,7 +190,7 @@ module Raven # NOTE: Useful in scenarios where you need to reconstruct the error # (usually along with a backtrace from external source), while # having no access to the actual Exception object. - def capture(klass : String, message : String, backtrace : String? = nil, **options, &block) + def capture(klass : String, message : String, backtrace : String? = nil, **options, &) formatted_message = "#{klass}: #{message}" capture(formatted_message, **options) do |event| ex = Interface::SingleException.new.tap do |iface| @@ -219,7 +219,7 @@ module Raven # MyApp.run # end # ``` - def capture(**options, &block) + def capture(**options, &) yield rescue ex : Raven::Error raise ex # Don't capture Raven errors diff --git a/src/raven/transports/http.cr b/src/raven/transports/http.cr index cb0cbe6..529c2a3 100644 --- a/src/raven/transports/http.cr +++ b/src/raven/transports/http.cr @@ -14,6 +14,7 @@ module Raven private def build_client ssl = configuration.ssl ssl = configuration.scheme == "https" if ssl.nil? + # ameba:disable Lint/NotNil ::HTTP::Client.new(configuration.host.not_nil!, configuration.port, ssl).tap do |client| client.before_request do |request| request.headers["User-Agent"] = Client::USER_AGENT