gitstamp 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/AUTHORS +1 -0
- data/CHANGES.md +6 -0
- data/CREDITS.md +1 -0
- data/README.md +26 -0
- data/UNLICENSE +24 -0
- data/VERSION +1 -0
- data/bin/gitstamp +76 -0
- data/lib/gitstamp/commit.rb +40 -0
- data/lib/gitstamp/transaction.rb +44 -0
- data/lib/gitstamp/version.rb +21 -0
- data/lib/gitstamp.rb +6 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1774534fb07609cd455470e861ec4b0afd377e8b8b46c4123b5a673084388d03
|
4
|
+
data.tar.gz: a814125b30c20e4d42934c9141265a711d699189c2c7e3446033db473b9c440d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c00982820e2af67d2dea03d4e53d81aeb53e066e0878dec11ff31c814035b795bd0345fcaba4b64c952d7c51262d474a378476327cef0ad26f8a353c21db00b
|
7
|
+
data.tar.gz: 816b1398692ac5a41d63bb5e50be645ebacbd4c196324259a0c431ed4a338799076a99eecd681bb603506c96f3c4a442d7b1a26ede5ae73590634cf0f54b6fbc
|
data/AUTHORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Arto Bendiken <arto@bendiken.net>
|
data/CHANGES.md
ADDED
data/CREDITS.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Credits
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Gitstamp Command-Line Interface (CLI)
|
2
|
+
|
3
|
+
[![Project license](https://img.shields.io/badge/license-Public%20Domain-blue.svg)](https://unlicense.org)
|
4
|
+
[![Ruby compatibility](https://img.shields.io/badge/ruby-2.4%2B-blue)](https://rubygems.org/gems/gitstamp)
|
5
|
+
[![RubyGems gem](https://img.shields.io/gem/v/gitstamp.svg)](https://rubygems.org/gems/gitstamp)
|
6
|
+
|
7
|
+
## Prerequisites
|
8
|
+
|
9
|
+
- [Ruby](https://www.ruby-lang.org/en/) 2.4+
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
The tool can be installed quickly and easily on any computer that has [Ruby]
|
14
|
+
available:
|
15
|
+
|
16
|
+
```bash
|
17
|
+
$ gem install gitstamp
|
18
|
+
```
|
19
|
+
|
20
|
+
In case the command wasn't found after installation, you likely need to
|
21
|
+
configure your `PATH` environment variable to include your [RubyGems] program
|
22
|
+
path.
|
23
|
+
|
24
|
+
[Ruby]: https://www.ruby-lang.org/en/
|
25
|
+
[RubyGems]: https://guides.rubygems.org/faqs/
|
26
|
+
[Unlicense]: https://unlicense.org
|
data/UNLICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
+
distribute this software, either in source code form or as a compiled
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
+
means.
|
7
|
+
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
+
of this software dedicate any and all copyright interest in the
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
11
|
+
of the public at large and to the detriment of our heirs and
|
12
|
+
successors. We intend this dedication to be an overt act of
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
14
|
+
software under copyright law.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
For more information, please refer to <https://unlicense.org/>
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/gitstamp
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env ruby -W1
|
2
|
+
# This is free and unencumbered software released into the public domain.
|
3
|
+
|
4
|
+
require_relative '../lib/gitstamp'
|
5
|
+
|
6
|
+
require 'arweave' # https://rubygems.org/gems/arweave
|
7
|
+
require 'rugged' # https://rubygems.org/gems/rugged
|
8
|
+
require 'thor' # https://rubygems.org/gems/thor
|
9
|
+
|
10
|
+
require 'json'
|
11
|
+
|
12
|
+
class CLI < Thor
|
13
|
+
def self.exit_on_failure?() true end
|
14
|
+
|
15
|
+
class_option :debug, aliases: '-d', type: :boolean, desc: "Enable debugging"
|
16
|
+
class_option :verbose, aliases: '-v', type: :boolean, desc: "Be verbose (print warnings)"
|
17
|
+
class_option :quiet, aliases: '-q', type: :boolean, desc: "Be quiet (silence non-fatal errors)"
|
18
|
+
class_option :wallet, aliases: '-W', banner: 'FILE', desc: "Specify Arweave wallet FILE (in JWK format)"
|
19
|
+
|
20
|
+
desc "publish COMMIT...", "Publish commits to Gitstamp"
|
21
|
+
option :author, banner: 'URI', desc: "Override author URI (mailto: or https://)"
|
22
|
+
option :committer, banner: 'URI', desc: "Override committer URI (mailto: or https://)"
|
23
|
+
option :link, banner: 'URL', desc: "Include commit link URL (https://)"
|
24
|
+
def publish(*commits)
|
25
|
+
wallet = self.wallet
|
26
|
+
author, committer, link = self.options[:author], self.options[:committer], self.options[:link]
|
27
|
+
git = Rugged::Repository.new('.')
|
28
|
+
commits = commits.empty? ? [git.head.target] : commits.map { |sha1| git.lookup(sha1) }
|
29
|
+
commits.each do |commit|
|
30
|
+
commit = Gitstamp::Commit.from_git(commit, author: author, committer: committer, link: link)
|
31
|
+
warn commit.to_tags.inspect if debug?
|
32
|
+
transaction_id = Gitstamp::Transaction.new(commit).publish!(wallet)
|
33
|
+
puts "#{set_color(transaction_id, :green)}" unless quiet?
|
34
|
+
end
|
35
|
+
rescue => error
|
36
|
+
raise error if debug?
|
37
|
+
warn "#{$0}: #{set_color(error, :red)}"
|
38
|
+
exit error.respond_to?(:exit_code) ? error.exit_code : -1
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def wallet
|
44
|
+
@wallet ||= begin
|
45
|
+
wallet_path = self.options[:wallet]
|
46
|
+
raise "wallet path required" if wallet_path.nil?
|
47
|
+
raise "#{wallet_path}: wallet file not found" if !File.exist?(wallet_path)
|
48
|
+
begin
|
49
|
+
Arweave::Wallet.new(JSON.parse(File.read(wallet_path)))
|
50
|
+
rescue JSON::ParserError => error
|
51
|
+
raise "#{wallet_path}: #{error}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def debug?() self.options[:debug] end
|
57
|
+
def verbose?() self.options[:verbose] || self.debug? end
|
58
|
+
def quiet?() self.options[:quiet] end
|
59
|
+
end # CLI
|
60
|
+
|
61
|
+
# Fix for https://github.com/erikhuda/thor/issues/398
|
62
|
+
class Thor::Shell::Basic
|
63
|
+
def print_wrapped(message, options = {})
|
64
|
+
indent = (options[:indent] || 0).to_i
|
65
|
+
if indent.zero?
|
66
|
+
self.stdout.puts message
|
67
|
+
else
|
68
|
+
message.each_line do |message_line|
|
69
|
+
self.stdout.print ' ' * indent
|
70
|
+
self.stdout.puts message_line.chomp
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end # Thor::Shell::Basic
|
75
|
+
|
76
|
+
CLI.start(ARGV)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
##
|
4
|
+
# A Gitstamp commit contains the Git commit message and relevant metadata.
|
5
|
+
class Gitstamp::Commit < ::Struct.new(:id, :link, :author, :committer, :committer_date, :message, keyword_init: true)
|
6
|
+
##
|
7
|
+
# Constructs a Gitstamp commit from a Git commit.
|
8
|
+
#
|
9
|
+
# @param [Rugged::Commit] git the Git commit object
|
10
|
+
# @param [URI, #to_s] author an optional author URI override
|
11
|
+
# @param [URI, #to_s] committer an optional committer URI override
|
12
|
+
# @param [URI, #to_s] link an optional commit link URL
|
13
|
+
# @return [Commit]
|
14
|
+
def self.from_git(git, author: nil, committer: nil, link: nil)
|
15
|
+
self.new(
|
16
|
+
id: git.oid.to_s,
|
17
|
+
link: link&.to_s,
|
18
|
+
author: (author || "mailto:#{git.author[:email]}").to_s,
|
19
|
+
committer: (committer || "mailto:#{git.committer[:email]}").to_s,
|
20
|
+
committer_date: git.committer[:time], # preserves the timezone
|
21
|
+
message: git.message.to_s,
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Returns the Arweave metadata tags for this commit.
|
27
|
+
#
|
28
|
+
# @return [Hash<String, String>]
|
29
|
+
def to_tags
|
30
|
+
{
|
31
|
+
'Content-Type' => 'text/plain',
|
32
|
+
'App-Name' => 'Gitstamp',
|
33
|
+
'Git-Commit' => self.id.to_s,
|
34
|
+
'Git-Commit-Link' => self.link&.to_s,
|
35
|
+
'Git-Author' => self.author&.to_s,
|
36
|
+
'Git-Committer' => self.committer&.to_s,
|
37
|
+
'Git-Committer-Date' => self.committer_date&.strftime("%Y-%m-%dT%H:%M:%S%:z"),
|
38
|
+
}.delete_if { |k, v| v.nil? }
|
39
|
+
end
|
40
|
+
end # Gitstamp::Commit
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
##
|
4
|
+
# A Gitstamp transaction is an Arweave transaction with specific tags.
|
5
|
+
class Gitstamp::Transaction
|
6
|
+
##
|
7
|
+
# The transaction's associated commit.
|
8
|
+
#
|
9
|
+
# @return [Commit] commit
|
10
|
+
attr_reader :commit
|
11
|
+
|
12
|
+
##
|
13
|
+
# Constructs a transaction from a commit.
|
14
|
+
#
|
15
|
+
# @param [Commit] commit
|
16
|
+
# @return [void]
|
17
|
+
def initialize(commit)
|
18
|
+
@commit = commit
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# Signs this transaction as originating from the given wallet.
|
23
|
+
#
|
24
|
+
# @param [Arweave::Wallet] wallet
|
25
|
+
# @return [Arweave::Transaction] the signed Arweave transaction
|
26
|
+
def sign(wallet)
|
27
|
+
tx = Arweave::Transaction.new(data: @commit.message.to_s)
|
28
|
+
@commit.to_tags.each do |name, value|
|
29
|
+
tx.add_tag(name: name, value: value)
|
30
|
+
end
|
31
|
+
tx.sign(wallet)
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Submits this transaction to the Arweave network.
|
36
|
+
#
|
37
|
+
# @param [Arweave::Wallet] wallet
|
38
|
+
# @return [String] the posted Arweave transaction ID
|
39
|
+
def publish!(wallet)
|
40
|
+
tx = self.sign(wallet)
|
41
|
+
tx.commit
|
42
|
+
tx.attributes[:id]
|
43
|
+
end
|
44
|
+
end # Gitstamp::Transaction
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
module Gitstamp
|
4
|
+
module VERSION
|
5
|
+
FILE = File.expand_path('../../VERSION', __dir__).freeze
|
6
|
+
STRING = File.read(FILE).chomp.freeze
|
7
|
+
MAJOR, MINOR, PATCH, EXTRA = STRING.split('.').map(&:to_i).freeze
|
8
|
+
|
9
|
+
##
|
10
|
+
# @return [String]
|
11
|
+
def self.to_s() STRING end
|
12
|
+
|
13
|
+
##
|
14
|
+
# @return [String]
|
15
|
+
def self.to_str() STRING end
|
16
|
+
|
17
|
+
##
|
18
|
+
# @return [Array(Integer, Integer, Integer)]
|
19
|
+
def self.to_a() [MAJOR, MINOR, PATCH].freeze end
|
20
|
+
end # VERSION
|
21
|
+
end # Gitstamp
|
data/lib/gitstamp.rb
ADDED
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitstamp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arto Bendiken
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: arweave
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rugged
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: thor
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.0'
|
97
|
+
description: Gitstamp Command-Line Interface (CLI)
|
98
|
+
email: arto@bendiken.net
|
99
|
+
executables:
|
100
|
+
- gitstamp
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- AUTHORS
|
105
|
+
- CHANGES.md
|
106
|
+
- CREDITS.md
|
107
|
+
- README.md
|
108
|
+
- UNLICENSE
|
109
|
+
- VERSION
|
110
|
+
- bin/gitstamp
|
111
|
+
- lib/gitstamp.rb
|
112
|
+
- lib/gitstamp/commit.rb
|
113
|
+
- lib/gitstamp/transaction.rb
|
114
|
+
- lib/gitstamp/version.rb
|
115
|
+
homepage: https://github.com/artob/gitstamp-cli
|
116
|
+
licenses:
|
117
|
+
- Unlicense
|
118
|
+
metadata:
|
119
|
+
bug_tracker_uri: https://github.com/artob/gitstamp-cli/issues
|
120
|
+
changelog_uri: https://github.com/artob/gitstamp-cli/blob/master/CHANGES.md
|
121
|
+
documentation_uri: https://www.rubydoc.info/github/artob/gitstamp-cli/master
|
122
|
+
homepage_uri: https://gitstamp.dev
|
123
|
+
source_code_uri: https://github.com/artob/gitstamp-cli
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 2.4.0
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 2.6.8
|
138
|
+
requirements: []
|
139
|
+
rubygems_version: 3.1.2
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: Gitstamp Command-Line Interface (CLI)
|
143
|
+
test_files: []
|