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

filters/git_last_checkout: add support for AIRBRAKE_DEPLOY_USERNAME #566

Merged
merged 1 commit into from
Apr 9, 2020
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Airbrake Ruby Changelog

### master

* Added support for `AIRBRAKE_DEPLOY_USERNAME`, which overrides deployer
username in the automatic deploy tracking feature
([#566](https://github.com/airbrake/airbrake-ruby/pull/566))

### [v4.13.3][v4.13.3] (March 2, 2020)

* Added the ability to filter via `blacklist_keys` the following keys:
Expand Down
3 changes: 2 additions & 1 deletion lib/airbrake-ruby/filters/git_last_checkout_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def initialize(root_directory)
@git_path = File.join(root_directory, '.git')
@weight = 116
@last_checkout = nil
@deploy_username = ENV['AIRBRAKE_DEPLOY_USERNAME']
end

# @macro call_filter
Expand Down Expand Up @@ -59,7 +60,7 @@ def last_checkout

author = parts[2..-4]
@last_checkout = {
username: author[0..1].join(' '),
username: @deploy_username || author[0..1].join(' '),
email: parts[-3][1..-2],
revision: parts[1],
time: timestamp(parts[-2].to_i),
Expand Down
23 changes: 20 additions & 3 deletions spec/filters/git_last_checkout_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,41 @@
end

context "when .git directory exists" do
before { subject.call(notice) }
context "when AIRBRAKE_DEPLOY_USERNAME env variable is set" do
before { ENV['AIRBRAKE_DEPLOY_USERNAME'] = 'deployer' }

it "attaches last checkouted username" do
expect(notice[:context][:lastCheckout][:username]).not_to be_empty
it "attaches username from the environment" do
subject.call(notice)
expect(notice[:context][:lastCheckout][:username]).to eq('deployer')
end
end

context "when AIRBRAKE_DEPLOY_USERNAME env variable is NOT set" do
before { ENV['AIRBRAKE_DEPLOY_USERNAME'] = nil }

it "attaches last checkouted username" do
subject.call(notice)
username = notice[:context][:lastCheckout][:username]
expect(username).not_to be_empty
expect(username).not_to be_nil
end
end

it "attaches last checkouted email" do
subject.call(notice)
expect(notice[:context][:lastCheckout][:email]).to(
match(/\A\w+[\w.-]*@\w+\.?\w+?\z/),
)
end

it "attaches last checkouted revision" do
subject.call(notice)
expect(notice[:context][:lastCheckout][:revision]).not_to be_empty
expect(notice[:context][:lastCheckout][:revision].size).to eq(40)
end

it "attaches last checkouted time" do
subject.call(notice)
expect(notice[:context][:lastCheckout][:time]).not_to be_empty
expect(notice[:context][:lastCheckout][:time].size).to eq(25)
end
Expand Down