gitodo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 88b669b25bad62f4a7e55b37c9cff2bb83bd5ca9
4
+ data.tar.gz: 0b3ccbdaa46177ea7b2d1ca68b82d1d332c382fc
5
+ SHA512:
6
+ metadata.gz: 21f84045f4e5fc684a738e322884f4099b56581d1caa01ce9eb625fcf6c2ab90c542cd705f7c128edccf18e05ded29e24c58a04037fe38a7fd85039974e3de8e
7
+ data.tar.gz: dcd97109e76601f6e5aed882204b40e06f62f5d6b902592d446606ede2ecb922108f49a00fdb7e22172505ddf3eda4f73395120ac91499fb6d26cd2f71cb434d
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env bash
2
+
3
+ echo "Starting unit tests"
4
+ bundle exec rake test
5
+ if [ $? -ne 0 ]; then
6
+ echo ""
7
+ echo ""
8
+ echo "Unit tests failed; push aborted!"
9
+ exit 1
10
+ fi
11
+
12
+ echo
13
+ echo "Starting rubocop"
14
+ bundle exec rubocop --format worst --format simple --format offenses
15
+ if [ $? -ne 0 ]; then
16
+ echo ""
17
+ echo ""
18
+ echo "Rubocop failed; push aborted!"
19
+ exit 1
20
+ fi
21
+
22
+ echo
23
+ echo "All pre-push checks passed! Pushing to remote"
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ **/*.byebug_history
12
+ gitodo-*.gem
13
+ .gitodo.yml
data/.rubocop.yml ADDED
@@ -0,0 +1,37 @@
1
+ AllCops:
2
+ Exclude:
3
+ - '*.gemspec'
4
+ - 'tmp/**/*'
5
+ - 'bin/**/*'
6
+ - 'test/**/*'
7
+ - '**/version.rb'
8
+
9
+ Style/RedundantSelf:
10
+ Enabled: false
11
+
12
+ Style/RedundantReturn:
13
+ Enabled: false
14
+
15
+ Style/GuardClause:
16
+ Enabled: false
17
+
18
+ Style/ClassAndModuleChildren:
19
+ Enabled: false
20
+
21
+ Style/EmptyLinesAroundClassBody:
22
+ Enabled: false
23
+
24
+ Style/CommentIndentation:
25
+ Enabled: false
26
+
27
+ Style/ClassVars:
28
+ Enabled: false
29
+
30
+ Metrics/LineLength:
31
+ Max: 120
32
+
33
+ Metrics/MethodLength:
34
+ Max: 25
35
+
36
+ Metrics/AbcSize:
37
+ Max: 25
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ - 2.4.0
6
+ before_install: gem install bundler -v 1.14.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at noah@apsis.io. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gitodo.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Noah Callaway
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,71 @@
1
+ # Gitodo
2
+
3
+ Gitodo is a small program that lets you write quick developer notes to yourself.
4
+
5
+ ## Installation
6
+
7
+ Install with:
8
+
9
+ $ gem install gitodo
10
+
11
+ ## Usage
12
+
13
+ $ gitodo "Don't forget to foo the baz before sending out a code review"
14
+ Todo added. There are 3 todos on branch `master`
15
+
16
+ $ gitodo "Also should baz the ding"
17
+ Todo added. There are 4 todos on branch `master`
18
+
19
+ $ gitodo --list
20
+ There are 4 todos on branch `master`
21
+ [1] Fix one of the things
22
+ [2] Fix the other of the things
23
+ [3] Don't forget to foo the baz before sending out a code review
24
+ [4] Also should baz the ding
25
+
26
+ $ gitodo --done 1 3
27
+ Finishing 2 todos
28
+ [1] Fix one of the things
29
+ [3] Don't forget to foo the baz before sending out a code review
30
+ Is that correct? [y/n]
31
+ |> y
32
+ Finished two todos! There are 2 todos remaining on branch `master`
33
+ [1] Fix the other of the things
34
+ [2] Also should baz the ding
35
+
36
+ $ gitodo --done
37
+ Which todos have you finished?
38
+ [1] Fix the other of the things
39
+ [2] Also should baz the ding
40
+ |> 2
41
+ Finishing 1 todo
42
+ [2] Also should baz the ding
43
+ Is that correct? [y/n]
44
+ |> y
45
+ Finished 1 todo!
46
+
47
+ $ gitodo --check
48
+ Check failed! There is 1 todo on branch `master`!
49
+ [1] Fix the order of the things
50
+
51
+ $ gitodo --done 1 !
52
+ Finished 1 todo! `master` is clean!
53
+
54
+ $ gitodo --check
55
+ Check passed! `master` is clean!
56
+
57
+
58
+ ## Development
59
+
60
+ 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.
61
+
62
+ 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).
63
+
64
+ ## Contributing
65
+
66
+ Bug reports and pull requests are welcome on GitHub at https://github.com/apsislabs/gitodo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
67
+
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gitodo"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+
3
+ cd "`dirname \"$0\"`/.."
4
+
5
+ echo "Installing githooks for `pwd`"
6
+ rm -rf .git/hooks
7
+ ln -s -f ../.githooks/ .git/hooks
data/bin/setup ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ bin/install-githooks
9
+
10
+ # create the sample git keep file
11
+ cd test/sample
12
+ git init
13
+ git add .
14
+ git commit -m "keep file"
data/exe/gitodo ADDED
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gitodo'
4
+
5
+ options = Gitodo::CommandLineOptions.parse(ARGV)
6
+
7
+ def are_count_todos(count)
8
+ (count == 1) ? "is #{count_todos(count)}" : "are #{count_todos(count)}"
9
+ end
10
+
11
+ def count_todos(count)
12
+ (count == 1) ? "#{count} todo" : "#{count} todos"
13
+ end
14
+
15
+ def do_add()
16
+ todo = ARGV.join(" ").strip
17
+ form = Gitodo::AddTodoForm.new({ todo: todo })
18
+ Gitodo::AddTodoCommand.call(add_form: form) do |m|
19
+ m.fail {|_, result| puts result.message; exit 1 }
20
+ m.pass do |val|
21
+ puts %Q(Todo added. There #{are_count_todos(val.todo_count)} on branch `#{val.branch}`)
22
+ end
23
+ end
24
+ end
25
+
26
+ def do_done()
27
+ @todo_indexes = ARGV
28
+ @needs_confirmation = true
29
+ @confirmed = false
30
+
31
+ # Handle No Arguments
32
+ if @todo_indexes.empty?
33
+ # print confirmation
34
+ Gitodo::ListTodoCommand.call do |m|
35
+ m.fail {|_, result| puts result.message; exit 1 }
36
+ m.pass do |val, result|
37
+ message = %Q(Which todos have you finished?)
38
+
39
+ val.todos.each do |todo|
40
+ message << "\n\t[#{todo.display_index}] #{todo.todo}"
41
+ end
42
+
43
+ puts message
44
+ print "> "
45
+
46
+ @todo_indexes = STDIN.gets.strip.split(" ")
47
+ end
48
+ end
49
+ end
50
+
51
+ # if '!' chomp it and skip confirmation
52
+ if ARGV.include? '!'
53
+ ARGV.delete '!'
54
+ @needs_confirmation = false
55
+ end
56
+
57
+ # handle the confirmation
58
+ if @needs_confirmation
59
+
60
+ form = Gitodo::ListTodoForm.new(todo_indexes: @todo_indexes)
61
+ Gitodo::ListTodoCommand.call(list_form: form) do |m|
62
+ m.fail {|_, result| puts result.message; exit 1 }
63
+ m.pass do |val, result|
64
+ message = "Finishing #{count_todos(val.todos.count)}."
65
+
66
+ val.todos.each do |todo|
67
+ message << "\n\t[#{todo.display_index}] #{todo.todo}"
68
+ end
69
+
70
+ message << "\nIs that correct? [y/n]"
71
+
72
+ puts message
73
+ print "> "
74
+
75
+ response = STDIN.gets.strip
76
+
77
+ unless response.downcase == "y"
78
+ puts "Not finishing any todos."
79
+ exit 1
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ form = Gitodo::DoneTodoForm.new({ todo_indexes: @todo_indexes })
86
+ Gitodo::DoneTodoCommand.call(done_form: form) do |m|
87
+ m.fail {|_, result| puts result.message; exit 1 }
88
+ m.pass do |val|
89
+ puts %Q(Todo added. There #{are_count_todos(val.todo_count)} on branch `#{val.branch}`)
90
+ end
91
+ end
92
+ end
93
+
94
+ def do_list()
95
+ Gitodo::ListTodoCommand.call do |m|
96
+ m.fail {|_, result| puts result.message; exit 1 }
97
+ m.pass do |val, result|
98
+ message = %Q(There #{are_count_todos(val.todos.count)} on branch `#{val.branch}`)
99
+
100
+ val.todos.each do |todo|
101
+ message << "\n\t[#{todo.display_index}] #{todo.todo}"
102
+ end
103
+
104
+ puts message
105
+ end
106
+ end
107
+ end
108
+
109
+ def do_check()
110
+ Gitodo::ListTodoCommand.call do |m|
111
+ m.fail {|_, result| puts result.message; exit 1 }
112
+ m.pass do |val, result|
113
+ if (val.todos.any?)
114
+ puts %Q(Check failed! There #{are_count_todos(val.todos.count)} on `#{val.branch}`)
115
+ exit 1
116
+ end
117
+
118
+ puts %Q(Check passed! `#{val.branch}` is clean!)
119
+ end
120
+ end
121
+ end
122
+
123
+ case options.command
124
+ when "add"
125
+ do_add
126
+ when "done"
127
+ do_done
128
+ when "list"
129
+ do_list
130
+ when "check"
131
+ do_check
132
+ else
133
+ puts "Command not recognized"
134
+ exit 1
135
+ end
data/gitodo.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gitodo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'gitodo'
8
+ spec.version = Gitodo::VERSION
9
+ spec.authors = ['Noah Callaway']
10
+ spec.email = ['noah@apsis.io']
11
+
12
+ spec.summary = %q{Track developer todo items in git (per branch)}
13
+ spec.homepage = 'http://www.apsis.io'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'slayer', '~> 0.3.1'
25
+ spec.add_development_dependency 'bundler', '~> 1.14'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'minitest', '~> 5.0'
28
+ spec.add_development_dependency 'minitest-reporters', '~> 1.1'
29
+ spec.add_development_dependency 'coveralls'
30
+ spec.add_development_dependency 'simplecov', '~> 0.13'
31
+ spec.add_development_dependency 'byebug', '~> 9.0'
32
+ spec.add_development_dependency 'yard', '~> 0.9'
33
+ spec.add_development_dependency 'rubocop', '~> 0.47.1'
34
+ end
data/lib/gitodo.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'slayer'
2
+ require 'byebug'
3
+
4
+ require 'gitodo/version'
5
+ require 'gitodo/command_line_options'
6
+ require 'gitodo/commands/add_todo_command'
7
+ require 'gitodo/commands/list_todo_command'
8
+ require 'gitodo/commands/done_todo_command'
9
+ require 'gitodo/forms/todo'
10
+ require 'gitodo/forms/add_todo_form'
11
+ require 'gitodo/forms/list_todo_form'
12
+ require 'gitodo/forms/done_todo_form'
13
+ require 'gitodo/services/git_service'
14
+ require 'gitodo/services/todo_service'
@@ -0,0 +1,144 @@
1
+ require 'optparse'
2
+
3
+ module Gitodo
4
+ class CommandLineOptions
5
+
6
+ def self.parse(args)
7
+ options = OpenStruct.new
8
+
9
+ explicit_command = false
10
+ options.command = "add"
11
+ # options.inplace = false
12
+ # options.encoding = "utf8"
13
+ # options.transfer_type = :auto
14
+ # options.verbose = false
15
+
16
+ opt_parser = OptionParser.new do |opts|
17
+ opts.banner = "Usage: gitodo [options]"
18
+
19
+ opts.separator ""
20
+ opts.separator "Specific options:"
21
+
22
+ # Commands
23
+ opts.on("--done", "Finish one or more todo items!") do
24
+ if explicit_command
25
+ puts "Specified multiple commands"
26
+ exit 1
27
+ end
28
+
29
+ options.command = "done"
30
+ explicit_command = true
31
+ end
32
+ # opts.on_tail("--version", "Show version") do
33
+ # puts ::Version.join('.')
34
+ # exit
35
+ # end
36
+
37
+ opts.on("--list", "List the open todo items!") do
38
+ if explicit_command
39
+ puts "Specified multiple commands"
40
+ exit 1
41
+ end
42
+
43
+ options.command = "list"
44
+ explicit_command = true
45
+ end
46
+
47
+ opts.on("--check", "Check if there are any open todo items, and fail if there are any") do
48
+ if explicit_command
49
+ puts "Specified multiple commands"
50
+ exit 1
51
+ end
52
+
53
+ options.command = "check"
54
+ explicit_command = true
55
+ end
56
+
57
+ opts.on("--add", "(Default) Add a new todo item") do
58
+ if explicit_command
59
+ puts "Specified multiple commands"
60
+ exit 1
61
+ end
62
+
63
+ options.command = "add"
64
+ explicit_command = true
65
+ end
66
+
67
+ # Mandatory argument.
68
+ # opts.on("-r", "--require LIBRARY",
69
+ # "Require the LIBRARY before executing your script") do |lib|
70
+ # options.library << lib
71
+ # end
72
+ #
73
+ # # Optional argument; multi-line description.
74
+ # opts.on("-i", "--inplace [EXTENSION]",
75
+ # "Edit ARGV files in place",
76
+ # " (make backup if EXTENSION supplied)") do |ext|
77
+ # options.inplace = true
78
+ # options.extension = ext || ''
79
+ # options.extension.sub!(/\A\.?(?=.)/, ".") # Ensure extension begins with dot.
80
+ # end
81
+ #
82
+ # # Cast 'delay' argument to a Float.
83
+ # opts.on("--delay N", Float, "Delay N seconds before executing") do |n|
84
+ # options.delay = n
85
+ # end
86
+ #
87
+ # # Cast 'time' argument to a Time object.
88
+ # opts.on("-t", "--time [TIME]", Time, "Begin execution at given time") do |time|
89
+ # options.time = time
90
+ # end
91
+
92
+ # Cast to octal integer.
93
+ # opts.on("-F", "--irs [OCTAL]", OptionParser::OctalInteger,
94
+ # "Specify record separator (default \\0)") do |rs|
95
+ # options.record_separator = rs
96
+ # end
97
+ #
98
+ # # List of arguments.
99
+ # opts.on("--list x,y,z", Array, "Example 'list' of arguments") do |list|
100
+ # options.list = list
101
+ # end
102
+
103
+ # Keyword completion. We are specifying a specific set of arguments (CODES
104
+ # and CODE_ALIASES - notice the latter is a Hash), and the user may provide
105
+ # the shortest unambiguous text.
106
+ # code_list = (CODE_ALIASES.keys + CODES).join(',')
107
+ # opts.on("--code CODE", CODES, CODE_ALIASES, "Select encoding",
108
+ # " (#{code_list})") do |encoding|
109
+ # options.encoding = encoding
110
+ # end
111
+
112
+ # Optional argument with keyword completion.
113
+ # opts.on("--type [TYPE]", [:text, :binary, :auto],
114
+ # "Select transfer type (text, binary, auto)") do |t|
115
+ # options.transfer_type = t
116
+ # end
117
+
118
+ # Boolean switch.
119
+ # opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
120
+ # options.verbose = v
121
+ # end
122
+
123
+ # opts.separator ""
124
+ # opts.separator "Common options:"
125
+
126
+ # No argument, shows at tail. This will print an options summary.
127
+ # Try it and see!
128
+ # opts.on_tail("-h", "--help", "Show this message") do
129
+ # puts opts
130
+ # exit
131
+ # end
132
+
133
+ # Another typical switch to print the version.
134
+ # opts.on_tail("--version", "Show version") do
135
+ # puts ::Version.join('.')
136
+ # exit
137
+ # end
138
+ end
139
+
140
+ opt_parser.parse!(args)
141
+ options
142
+ end # parse()
143
+ end
144
+ end
@@ -0,0 +1,18 @@
1
+ module Gitodo
2
+ class AddTodoCommand < Slayer::Command
3
+ def call(add_form:)
4
+ fail! message: "The arguments passed to the add todo command were invalid." unless add_form.is_a?(AddTodoForm)
5
+
6
+ fail! message: "Not in a git repository." unless GitService.is_git_repo
7
+
8
+ branch = GitService.current_branch
9
+
10
+ todo_service = TodoService.new
11
+
12
+ todo_service.add_todo(branch: branch, todo: add_form.todo)
13
+ todo_count = todo_service.get_todos(branch: branch).count
14
+
15
+ pass! value: OpenStruct.new( todo_count: todo_count, branch: branch)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ module Gitodo
2
+ class DoneTodoCommand < Slayer::Command
3
+ def call(done_form:)
4
+ fail! message: "The arguments passed to the add todo command were invalid." unless done_form.is_a?(DoneTodoForm)
5
+ fail! message: "Not in a git repository." unless GitService.is_git_repo
6
+
7
+ branch = GitService.current_branch
8
+
9
+ todo_service = TodoService.new
10
+ todos = todo_service.get_todos(branch: branch)
11
+
12
+ unless todos.any?
13
+ fail! message: %Q(There were no todos to finish.)
14
+ end
15
+
16
+ todo_indexes = done_form.todo_indexes.uniq
17
+
18
+ validated = todo_service.validate_todo_indexes(branch: branch, todo_indexes: todo_indexes)
19
+ fail! message: "One of the todo indexes was not valid." unless validated
20
+
21
+ todo_service.complete_todos(branch: branch, todo_indexes: todo_indexes)
22
+ todo_count = todo_service.get_todos(branch: branch).count
23
+
24
+ pass! value: OpenStruct.new(completed_count: todo_indexes.count, todo_count: todo_count, branch: branch)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ module Gitodo
2
+ class ListTodoCommand < Slayer::Command
3
+ def call(list_form: nil)
4
+ fail! message: "Not in a git repository." unless GitService.is_git_repo
5
+
6
+ branch = GitService.current_branch
7
+ todo_service = TodoService.new
8
+
9
+ matching = list_form ? list_form.todo_indexes : nil
10
+
11
+ if matching
12
+ validated = todo_service.validate_todo_indexes(branch: branch, todo_indexes: matching)
13
+ fail! message: "One of the todo indexes was not valid." unless validated
14
+ end
15
+
16
+ todos = todo_service.get_todos(branch: branch, todo_indexes: matching)
17
+
18
+ pass! value: OpenStruct.new(todos: todos, branch: branch)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module Gitodo
2
+ class AddTodoForm < Slayer::Form
3
+ attribute :todo, String
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Gitodo
2
+ class DoneTodoForm < Slayer::Form
3
+ attribute :todo_indexes, Array[String]
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Gitodo
2
+ class ListTodoForm < Slayer::Form
3
+ attribute :todo_indexes, Array[String]
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Gitodo
2
+ class Todo < Slayer::Form
3
+ attribute :display_index, String
4
+ attribute :internal_index, Integer
5
+ attribute :todo, String
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ module Gitodo
2
+ class GitService < Slayer::Service
3
+
4
+ def self.is_git_repo
5
+ `git rev-parse --is-inside-work-tree`.strip == "true"
6
+ end
7
+
8
+ def self.current_branch
9
+ branch = `git branch | grep \\* | cut -d ' ' -f2`.strip
10
+ end
11
+
12
+ def self.git_repo_root
13
+ `git rev-parse --show-toplevel`.strip
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,73 @@
1
+ require 'yaml'
2
+
3
+ module Gitodo
4
+ class TodoService < Slayer::Service
5
+ dependencies GitService
6
+
7
+ def initialize
8
+ @config = load_gitodo_config
9
+ end
10
+
11
+ def add_todo(branch:, todo:)
12
+ config[branch] ||= []
13
+ config[branch] << todo
14
+
15
+ write_gitodo_config
16
+ end
17
+
18
+ def get_todos(branch:, todo_indexes: nil)
19
+ raw_todos = config[branch] || []
20
+ todos = raw_todos.map.with_index {|todo, i| Todo.new(display_index: i+1, internal_index: i, todo: todo) }
21
+
22
+ todos = todos.reject{|t| !todo_indexes.include?(t.display_index) } if todo_indexes
23
+
24
+ todos
25
+ end
26
+
27
+ def complete_todos(branch:, todo_indexes:)
28
+ todos = get_todos(branch: branch)
29
+ todo_indexes = todo_indexes.uniq
30
+
31
+ to_complete = todos.reject{|t| !todo_indexes.include?(t.display_index) }
32
+
33
+ to_complete.each do |todo|
34
+ # index-1 to map from crazy user land indexes to real, sane indexes
35
+ config[branch][todo.internal_index] = nil
36
+ end
37
+
38
+ config[branch] = config[branch].reject(&:nil?)
39
+ write_gitodo_config
40
+ end
41
+
42
+ def validate_todo_indexes(branch:, todo_indexes:)
43
+ valid_todo_indexes = get_todos(branch: branch).map{|t| t.display_index}
44
+
45
+ todo_indexes = todo_indexes.uniq
46
+ todo_indexes = todo_indexes.each do |index|
47
+ return false unless valid_todo_indexes.include? index
48
+ end
49
+
50
+ return true
51
+ end
52
+
53
+ private
54
+ attr_accessor :config
55
+
56
+ def gitodo_file
57
+ return @gitodo_file if @gitodo_file
58
+ git_root = GitService.git_repo_root
59
+ @gitodo_file = "#{git_root}/.gitodo.yml"
60
+ end
61
+
62
+ def load_gitodo_config
63
+ return {} unless File.exist? gitodo_file
64
+ yaml = YAML.load_file(gitodo_file)
65
+ return {} unless yaml
66
+ return yaml
67
+ end
68
+
69
+ def write_gitodo_config
70
+ File.open(gitodo_file, 'w') {|f| f.write config.to_yaml }
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module Gitodo
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,212 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitodo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Noah Callaway
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slayer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-reporters
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.13'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.13'
111
+ - !ruby/object:Gem::Dependency
112
+ name: byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '9.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '9.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: yard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.9'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.9'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.47.1
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.47.1
153
+ description:
154
+ email:
155
+ - noah@apsis.io
156
+ executables:
157
+ - gitodo
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".githooks/pre-push"
162
+ - ".gitignore"
163
+ - ".rubocop.yml"
164
+ - ".travis.yml"
165
+ - CODE_OF_CONDUCT.md
166
+ - Gemfile
167
+ - LICENSE.txt
168
+ - README.md
169
+ - Rakefile
170
+ - bin/console
171
+ - bin/install-githooks
172
+ - bin/setup
173
+ - exe/gitodo
174
+ - gitodo.gemspec
175
+ - lib/.byebug_history
176
+ - lib/gitodo.rb
177
+ - lib/gitodo/command_line_options.rb
178
+ - lib/gitodo/commands/add_todo_command.rb
179
+ - lib/gitodo/commands/done_todo_command.rb
180
+ - lib/gitodo/commands/list_todo_command.rb
181
+ - lib/gitodo/forms/add_todo_form.rb
182
+ - lib/gitodo/forms/done_todo_form.rb
183
+ - lib/gitodo/forms/list_todo_form.rb
184
+ - lib/gitodo/forms/todo.rb
185
+ - lib/gitodo/services/git_service.rb
186
+ - lib/gitodo/services/todo_service.rb
187
+ - lib/gitodo/version.rb
188
+ homepage: http://www.apsis.io
189
+ licenses:
190
+ - MIT
191
+ metadata: {}
192
+ post_install_message:
193
+ rdoc_options: []
194
+ require_paths:
195
+ - lib
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ required_rubygems_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ requirements: []
207
+ rubyforge_project:
208
+ rubygems_version: 2.6.10
209
+ signing_key:
210
+ specification_version: 4
211
+ summary: Track developer todo items in git (per branch)
212
+ test_files: []