Skip to content

Commit

Permalink
Merge pull request #566 from airbrake/airbrake-deploy-username
Browse files Browse the repository at this point in the history
filters/git_last_checkout: add support for AIRBRAKE_DEPLOY_USERNAME
  • Loading branch information
kyrylo authored Apr 9, 2020
2 parents f18a4f6 + 631eda7 commit 11c4670
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
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

0 comments on commit 11c4670

Please sign in to comment.