octostat 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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +10 -0
- data/lib/octostat/command.rb +29 -0
- data/lib/octostat/database.rb +65 -0
- data/lib/octostat/git.rb +52 -0
- data/lib/octostat/version.rb +3 -0
- data/lib/octostat.rb +8 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a2e64faab77a884d9f7849108699a7d063709311553d22f79ebb9f9c61093722
|
4
|
+
data.tar.gz: 4e897ff4d764deeefb86b51566fb0de8d01312cd39eca04eb22e0be14813c943
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 533b07af9b0820358c52a116d03a4c40037a3f6e38b7bdaecc1ab087359411092b0adfc24a6f2e4a88a5b0f4bccf9d987454a21e98db04bc153f36394ef328d9
|
7
|
+
data.tar.gz: e1ae8db0d9455fe57db6e722dacf0dfa3b7a2ad7573133a8718e219a9364c3e8d3abb766ed36a00c700dd7c04cadf4279bd8a40c0815bf846cdd4e00d5a5e17c
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Joé Dupuis
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Octostat
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/octostat`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'octostat'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install octostat
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/octostat.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
|
4
|
+
module Octostat
|
5
|
+
class Command
|
6
|
+
def initialize *args
|
7
|
+
@db_path = "octostat.sqlite"
|
8
|
+
args = parser.parse!(args)
|
9
|
+
@path = args.first || Dir.pwd
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
db = Database.new(db_path)
|
14
|
+
Git.new(path).each do |commit|
|
15
|
+
db.insert_commit(**commit)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :db_path, :path
|
22
|
+
|
23
|
+
def parser
|
24
|
+
OptionParser.new do |opts|
|
25
|
+
opts.on("-dDB", "--db=DB", "Path to the SQLite db") { |db| @db_path = db }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require "sqlite3"
|
3
|
+
|
4
|
+
module Octostat
|
5
|
+
class Database
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
PRAGMAS = {
|
9
|
+
"foreign_keys" => true,
|
10
|
+
"journal_mode" => :wal,
|
11
|
+
"synchronous" => :normal,
|
12
|
+
"mmap_size" => 134217728, # 128 megabytes
|
13
|
+
"journal_size_limit" => 67108864, # 64 megabytes
|
14
|
+
"cache_size" => 2000
|
15
|
+
}
|
16
|
+
|
17
|
+
COMMIT_INSERT = "INSERT OR IGNORE INTO commits (hash, email, name, date, merge_commit, subject) VALUES (?, ?, ?, ?, ?, ?)"
|
18
|
+
|
19
|
+
def initialize file
|
20
|
+
@db = SQLite3::Database.new file
|
21
|
+
apply_pragma
|
22
|
+
create_tables
|
23
|
+
@commit_statement = db.prepare(COMMIT_INSERT)
|
24
|
+
end
|
25
|
+
|
26
|
+
def insert_commit hash:, name:, email:, subject:, date:, merge_commit:
|
27
|
+
commit_statement.execute([
|
28
|
+
hash,
|
29
|
+
email,
|
30
|
+
name,
|
31
|
+
date,
|
32
|
+
(merge_commit ? 1 : 0),
|
33
|
+
subject
|
34
|
+
])
|
35
|
+
end
|
36
|
+
|
37
|
+
def_delegators :@db, :execute, :foreign_keys, :journal_mode, :synchronous, :mmap_size, :journal_size_limit, :cache_size, :table_info
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def create_tables
|
42
|
+
db.execute <<-SQL
|
43
|
+
CREATE TABLE IF NOT EXISTS commits (
|
44
|
+
hash TEXT PRIMARY KEY,
|
45
|
+
email TEXT NOT NULL,
|
46
|
+
name TEXT NOT NULL,
|
47
|
+
date TEXT NOT NULL,
|
48
|
+
merge_commit BOOLEAN,
|
49
|
+
subject TEXT NOT NULL
|
50
|
+
);
|
51
|
+
|
52
|
+
CREATE INDEX IF NOT EXISTS idx_commits_name ON commits(name);
|
53
|
+
CREATE INDEX IF NOT EXISTS idx_commits_email ON commits(email);
|
54
|
+
SQL
|
55
|
+
end
|
56
|
+
|
57
|
+
def apply_pragma
|
58
|
+
PRAGMAS.each do |pragma, value|
|
59
|
+
db.public_send("#{pragma}=", value)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
attr_reader :db, :commit_statement
|
64
|
+
end
|
65
|
+
end
|
data/lib/octostat/git.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "open3"
|
2
|
+
|
3
|
+
|
4
|
+
module Octostat
|
5
|
+
class Git
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
LOG_FORMAT = <<~FORMAT.strip
|
9
|
+
%h
|
10
|
+
%ae
|
11
|
+
%an
|
12
|
+
%aI
|
13
|
+
%P
|
14
|
+
%s
|
15
|
+
FORMAT
|
16
|
+
|
17
|
+
ENTRY_LENGTH = LOG_FORMAT.lines.size
|
18
|
+
|
19
|
+
COMMAND = ["git", "log", "--pretty=format:#{LOG_FORMAT}"]
|
20
|
+
|
21
|
+
def initialize path
|
22
|
+
@path = path
|
23
|
+
end
|
24
|
+
|
25
|
+
def env
|
26
|
+
{"GIT_DIR" => path}
|
27
|
+
end
|
28
|
+
|
29
|
+
def each
|
30
|
+
return enum_for(:each) unless block_given?
|
31
|
+
Open3.popen2e(*COMMAND, chdir: path) do |input, output, wait_thr|
|
32
|
+
output.each_slice(ENTRY_LENGTH) do |commit|
|
33
|
+
commit.each(&:strip!)
|
34
|
+
hash, email, name, date, parents, subject = commit
|
35
|
+
merge_commit = parents.split(" ").size > 1
|
36
|
+
yield({
|
37
|
+
hash:,
|
38
|
+
email:,
|
39
|
+
name:,
|
40
|
+
date:,
|
41
|
+
merge_commit:,
|
42
|
+
subject:
|
43
|
+
})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
attr_reader :path
|
51
|
+
end
|
52
|
+
end
|
data/lib/octostat.rb
ADDED
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: octostat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joé Dupuis
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 1980-01-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sqlite3
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: debug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- joe@dupuis.io
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- LICENSE.txt
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- lib/octostat.rb
|
80
|
+
- lib/octostat/command.rb
|
81
|
+
- lib/octostat/database.rb
|
82
|
+
- lib/octostat/git.rb
|
83
|
+
- lib/octostat/version.rb
|
84
|
+
homepage: https://github.com/testdouble/octostat
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata:
|
88
|
+
homepage_uri: https://github.com/testdouble/octostat
|
89
|
+
source_code_uri: https://github.com/testdouble/octostat
|
90
|
+
changelog_uri: https://github.com/testdouble/octostat/main/CHANGELOG.md
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubygems_version: 3.5.16
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Octostat extract git information to Sqlite
|
110
|
+
test_files: []
|