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

Add KeybaseDirSign pre-commit hook + tests. #235

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 7 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ PreCommit:
install_command: 'gem install json'
include: '**/*.json'

KeybaseDirSign:
enabled: false
description: Signing directory contents with Keybase
required_executable: 'keybase'
flags: ['dir', 'sign', '--quiet']
install_command: 'npm install -g keybase-installer && keybase-installer'

LocalPathsInGemfile:
enabled: false
description: 'Checking for local paths in Gemfile'
Expand Down
25 changes: 25 additions & 0 deletions lib/overcommit/hook/pre_commit/keybase_dir_sign.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Overcommit::Hook::PreCommit
# Runs `keybase dir sign` and `git add SIGNED.md` to sign the dir contents
# with an OpenPGP cryptographic signature. Signs *all* files, not just
# those that are part of the current commit.
#
# @see https://keybase.io/
class KeybaseDirSign < Base
def run
keybase_result = execute(command)
keybase_output = keybase_result.stdout.chomp

if keybase_result.success? && keybase_output.empty?
git_result = execute(['git', 'add', 'SIGNED.md'])
git_output = git_result.stdout.chomp

if git_result.success? && git_output.empty?
return :pass
end
[:fail, git_result.stderr]
end

[:fail, keybase_result.stderr]
end
end
end
38 changes: 38 additions & 0 deletions spec/overcommit/hook/pre_commit/keybase_dir_sign_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'spec_helper'

describe Overcommit::Hook::PreCommit::KeybaseDirSign do
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
let(:context) { double('context') }
subject { described_class.new(config, context) }

context 'when keybase exits successfully' do
before do
result = double('result')
result.stub(:success?).and_return(true)
result.stub(:stdout).and_return('')
subject.stub(:execute).and_return(result)
end

it { should pass }
end

context 'when keybase exits unsucessfully' do
let(:result) { double('result') }

before do
result.stub(:success?).and_return(false)
result.stub(:stdout).and_return('')
subject.stub(:execute).and_return(result)
end

context 'and it reports an error' do
before do
result.stub(:stderr).and_return([
'an error'
].join('\n'))
end

it { should fail_hook }
end
end
end