githack 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d580c81976aa556c3c84fd93c7394a473dd08d11
4
- data.tar.gz: 768611bf8d2d7bcd8b71c34fb4d2624c4e9b20f2
3
+ metadata.gz: 45b9752319cd83954a52829df8728540731f5fe7
4
+ data.tar.gz: 99461ea4306976cdcedfea9927d13b778c96fda4
5
5
  SHA512:
6
- metadata.gz: e9f21fb4bc6e718d7e52d08c9c53044bea0d67c2369492226fd74bdb38f0a30bc2b76a8c243911abbe168a9369637fab7e3f1b0c8d67fb1aefc4dde9e6b70308
7
- data.tar.gz: e8b34e95ca079a6dbc8aa8a90f56adb63e32e6f170e0a6a5e820f4e6c371f3734599fb67059308226515e46a7b8ee3f84d238795e09bc87e21309ebc53c8e21a
6
+ metadata.gz: e5908cddcecc60d86ba4ccf49a9685af8e930ccdf88d9a48507c2bfb442e7ec0274460c01ae1e2e85f800042d6e43723fcda6dd8090b53c080575dfd789b26af
7
+ data.tar.gz: 6da3344fb2cbd29c67d0648d947bfa82b0a9a09b04a47497f4db7825072632500864fd1b9a25258b623d9dbb28a1329e925b8f2f8c4f5140d44249ea43b87848
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- githack (0.1.0)
4
+ githack (0.2.0)
5
5
  git (~> 1.5)
6
6
  tty-spinner (~> 0.8)
7
7
 
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Githack
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/githack.svg)](https://rubygems.org/gems/githack)
4
+
3
5
  Crawl [Git][git]'s commits of a given repository to find forgotten credentials
4
6
 
5
7
  Currently support:
@@ -42,7 +44,7 @@ Simply use tis to clone the remote repository in your temporary folder
42
44
  ```ruby
43
45
  require 'githack'
44
46
 
45
- repository = Repository.new 'https://github.com/RaspberryCook/website'
47
+ repository = Githack::RailsRepository.new 'https://github.com/RaspberryCook/website'
46
48
  ```
47
49
 
48
50
  And then you can search on repository like this:
data/bin/githack.rb CHANGED
@@ -33,7 +33,7 @@ end.parse!
33
33
 
34
34
  spinner = TTY::Spinner.new '[:spinner] Cloning repository ...'
35
35
  spinner.auto_spin
36
- repository = Repository.new url
36
+ repository = Githack::RailsRepository.new url
37
37
  spinner.stop('Done!')
38
38
 
39
39
  unless options[:skip_config_database]
data/lib/githack.rb CHANGED
@@ -1,5 +1,5 @@
1
- require "githack/version"
2
- require "githack/repository"
1
+ require 'githack/version'
2
+ require 'githack/rails_repository'
3
3
 
4
4
  module Githack
5
5
  # Your code goes here...
@@ -0,0 +1,35 @@
1
+ require 'githack/repository'
2
+
3
+ module Githack
4
+ class RailsRepository < Repository
5
+ # Get all changements for config/secrets.yml file (who contains some API keys)
6
+ def search_rails_config_secrets
7
+ results = []
8
+
9
+ absolute_file_path = File.join @path, 'config', 'secrets.yml'
10
+
11
+ checkout_on_yaml_file_change(absolute_file_path) do |secrets|
12
+ results << secrets
13
+ end
14
+
15
+ results.uniq
16
+ end
17
+
18
+ # Get all changements for config/database.yml file (who contains database configuration for Ruby on Rails Framework)
19
+ def search_rails_config_database
20
+ results = []
21
+
22
+ absolute_file_path = File.join @path, 'config', 'database.yml'
23
+
24
+ checkout_on_yaml_file_change(absolute_file_path) do |configs|
25
+ configs.each do |config|
26
+ config_data = config[1]
27
+ next if config_data['adapter'] == 'sqlite3'
28
+ results << config_data
29
+ end
30
+ end
31
+
32
+ results.uniq
33
+ end
34
+ end
35
+ end
@@ -2,86 +2,56 @@ require 'tmpdir'
2
2
  require 'yaml'
3
3
  require 'git'
4
4
 
5
- class Repository
6
- SENSIBLES_FILES = [
7
- File.join('config', 'database.yml')
8
- ].freeze
9
-
10
- attr_reader :git, :remote, :name, :path
11
-
12
- def initialize(remote)
13
- @remote = remote
14
- @name = remote.gsub /[^0-9A-Z]/i, '_'
15
- @path = File.join(Dir.tmpdir, name)
16
-
17
- @git = if File.directory? @path
18
- Git.open @path
19
- else
20
- Git.clone @remote, @name, path: Dir.tmpdir
21
- end
22
- end
23
-
24
- # Get all changements for config/secrets.yml file (who contains some API keys)
25
- def search_rails_config_secrets
26
- results = []
27
-
28
- absolute_file_path = File.join @path, 'config', 'secrets.yml'
29
-
30
- checkout_on_yaml_file_change(absolute_file_path) do |secrets|
31
- results << secrets
5
+ module Githack
6
+ class Repository
7
+ attr_reader :git, :remote, :name, :path
8
+
9
+ def initialize(remote)
10
+ @remote = remote
11
+ @name = remote.gsub /[^0-9A-Z]/i, '_'
12
+ @path = File.join(Dir.tmpdir, name)
13
+
14
+ @git = if File.directory? @path
15
+ Git.open @path
16
+ else
17
+ Git.clone @remote, @name, path: Dir.tmpdir
18
+ end
32
19
  end
33
20
 
34
- results.uniq
35
- end
36
-
37
- # Get all changements for config/database.yml file (who contains database configuration for Ruby on Rails Framework)
38
- def search_rails_config_database
39
- results = []
40
-
41
- absolute_file_path = File.join @path, 'config', 'database.yml'
42
-
43
- checkout_on_yaml_file_change(absolute_file_path) do |configs|
44
- configs.each do |config|
45
- config_data = config[1]
46
- next if config_data['adapter'] == 'sqlite3'
47
- results << config_data
21
+ protected
22
+
23
+ # Checkout on all file changes
24
+ #
25
+ # @param file <String> absolute filepath
26
+ # @yield <Hash> YAML file parsed
27
+ def checkout_on_yaml_file_change(file)
28
+ checkout_on_file_change(file) do
29
+ begin
30
+ data = YAML.safe_load(File.read(file))
31
+ yield data
32
+ rescue Psych::SyntaxError => e
33
+ # can't parse YAML file
34
+ end
48
35
  end
49
36
  end
50
37
 
51
- results.uniq
52
- end
53
-
54
- # Checkout on all file changes
55
- #
56
- # @param file <String> absolute filepath
57
- # @yield <Hash> YAML file parsed
58
- def checkout_on_yaml_file_change(file)
59
- checkout_on_file_change(file) do
38
+ # Checkout on all file changes
39
+ #
40
+ # @param file <String> absolute filepath
41
+ # @yield <Git::Log>
42
+ def checkout_on_file_change(file)
43
+ @git.checkout 'master'
60
44
  begin
61
- data = YAML.safe_load(File.read(file))
62
- yield data
63
- rescue Psych::SyntaxError => e
64
- # can't parse YAML file
65
- end
66
- end
67
- end
68
-
69
- # Checkout on all file changes
70
- #
71
- # @param file <String> absolute filepath
72
- # @yield <Git::Log>
73
- def checkout_on_file_change(file)
74
- @git.checkout 'master'
75
- begin
76
- @git.log.object(file).each do |commit|
77
- @git.checkout commit
78
- next unless File.exist? file
79
-
80
- yield commit
45
+ @git.log.object(file).each do |commit|
46
+ @git.checkout commit
47
+ next unless File.exist? file
48
+
49
+ yield commit
50
+ end
51
+ rescue StandardError
52
+ Psych::BadAlias
81
53
  end
82
- rescue StandardError
83
- Psych::BadAlias
54
+ @git.checkout 'master'
84
55
  end
85
- @git.checkout 'master'
86
56
  end
87
57
  end
@@ -1,3 +1,3 @@
1
1
  module Githack
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: githack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rousseau Alexandre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-18 00:00:00.000000000 Z
11
+ date: 2018-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -101,6 +101,7 @@ files:
101
101
  - bin/setup
102
102
  - githack.gemspec
103
103
  - lib/githack.rb
104
+ - lib/githack/rails_repository.rb
104
105
  - lib/githack/repository.rb
105
106
  - lib/githack/version.rb
106
107
  homepage: https://github.com/madeindjs/githack