things-issues-diff 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f4e37ac5712ea4e85e8699718faf219b3c470f1c
4
+ data.tar.gz: 3b85637182c8da6d8ecbfc8d55afabeb8d0e0e66
5
+ SHA512:
6
+ metadata.gz: 67f394b0f70b6b42926a6e9007215b989fb9d060445e0bc2cb033aef5771d846920e33a5839af372466c83735d36f07fad9af5293a9f4241aa1d799ff3ef91ba
7
+ data.tar.gz: 75e1a6c2587adfae65b17c9def8c5cfc030e50417913097ce882e55545bcccfb7482ddeeebc25fc90a0003eee13d88d262d8e2caef6cb60a724de0837091e7e3
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *~
2
+ \#*
3
+ .\#*
4
+ tmp
5
+ .DS_Store
6
+ Thumbs.db
7
+ ehthumbs.db
8
+ Desktop.ini
9
+ *.ignore
10
+ *.stackdump
11
+
12
+ /.bundle/
13
+ /.yardoc
14
+ /Gemfile.lock
15
+ /_yardoc/
16
+ /coverage/
17
+ /doc/
18
+ /pkg/
19
+ /spec/reports/
20
+
21
+ /.ruby-version
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in things-issues-diff.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 KOSEKI Kengo
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,41 @@
1
+ # Things::Issues::Diff
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/things/issues/diff`. 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 'things-issues-diff'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install things-issues-diff
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. 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]/things-issues-diff.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "things/issues/diff"
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
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/things-diff ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "things/issues_diff"
@@ -0,0 +1,227 @@
1
+ # frozen_string_literal: true
2
+ require 'things/issues_diff/version'
3
+
4
+ require 'optparse'
5
+ require 'octokit'
6
+ require 'yaml'
7
+
8
+ class Things::IssuesDiff
9
+ def parse_options(argv)
10
+ opts = OptionParser.new
11
+ opts.version = VERSION
12
+
13
+ opts.on('-h', '--help', 'Show help') do
14
+ usage
15
+ end
16
+
17
+ @args = {}
18
+ opts.on('-c FILE', '--config', 'Config file') do |v|
19
+ @args[:config_file] = v
20
+ end
21
+ opts.on('--ignore-filter', 'Do not filter issues/tasks') do |v|
22
+ @args[:ignore_filter] = v
23
+ end
24
+ opts.parse!(argv)
25
+
26
+ commands = argv[0].nil? ? [] : argv.shift.split(/\s*,\s*/)
27
+ @commands = %w[help sampleconf fetch diff].& commands
28
+ end
29
+
30
+ def load_config
31
+ default_config_file = File.join(ENV['HOME'], '.things-diff/config.yml')
32
+ @config_file = @args[:config_file] || default_config_file
33
+ unless File.exist?(@config_file)
34
+ puts "Error: Config file not found: #{@config_file}"
35
+
36
+ unless File.exist?(default_config_file)
37
+ puts
38
+ puts 'Please create config.yml and edit.'
39
+ puts ' $ mkdir ~/.things-diff/'
40
+ puts ' $ things-diff sampleconf > ~/.things-diff/config.yml'
41
+ puts ' $ vi ~/.things-diff/config.yml'
42
+ end
43
+ exit 1
44
+ end
45
+ @config_file = File.absolute_path(@config_file)
46
+ @config = YAML.load_file(@config_file)
47
+
48
+ if @config['data_file']
49
+ @data_file = File.join(File.dirname(@config_file), @config['data_file'])
50
+ @data_file = File.absolute_path(@data_file)
51
+ else
52
+ puts 'Error: Please set the data_file'
53
+ exit 1
54
+ end
55
+ end
56
+
57
+ # https://octokit.github.io/octokit.rb/
58
+ def init_octokit
59
+ @client = Octokit::Client.new(access_token: @config['token'])
60
+ @client.auto_paginate = true
61
+ end
62
+
63
+ def execute(argv)
64
+ parse_options(argv)
65
+ if @commands.include?('help')
66
+ usage
67
+ end
68
+
69
+ if @commands.include?('sampleconf')
70
+ sample_config
71
+ exit
72
+ end
73
+
74
+ load_config
75
+ init_octokit
76
+
77
+ if @commands.empty?
78
+ usage
79
+ end
80
+
81
+ if @commands.include?('fetch')
82
+ fetch
83
+ end
84
+
85
+ if @commands.include?('diff')
86
+ diff
87
+ end
88
+ end
89
+
90
+ def fetch
91
+ result = {}
92
+ @config['projects'].each do |project|
93
+ puts "Loading: #{project['name']}"
94
+ result[project['name']] = {}
95
+ issues = @client.list_issues(project['name'], assignee: @config['user'])
96
+ issues.each do |issue|
97
+ labels = []
98
+ if issue[:labels]
99
+ labels = issue[:labels].map { |lbl| lbl[:name] }
100
+ end
101
+
102
+ milestone = issue[:milestone] ? issue[:milestone][:title] : ''
103
+ entry = {
104
+ 'title' => issue[:title],
105
+ 'url' => issue[:html_url],
106
+ 'milestone' => milestone,
107
+ 'labels' => labels
108
+ }
109
+ result[project['name']][issue[:number].to_i] = entry
110
+ end
111
+ end
112
+ yaml = YAML.dump(result)
113
+ File.open(@data_file, 'w') do |out|
114
+ out << yaml
115
+ end
116
+ puts "Saved: #{@data_file}"
117
+ end
118
+
119
+ def diff
120
+ all_issues = YAML.load_file(@data_file)
121
+ all_tasks = load_tasks
122
+ @config['projects'].each do |project|
123
+ issues = all_issues[project['name']] || {}
124
+ tasks = all_tasks[project['name']] || {}
125
+
126
+ unless @args[:ignore_filter]
127
+ excludes = project.dig('milestones', 'exclude') || []
128
+ includes = project.dig('milestones', 'include') || []
129
+
130
+ unless includes.empty?
131
+ issues = issues.select { |_, v| includes.include?(v['milestone']) }
132
+ end
133
+ unless excludes.empty?
134
+ issues = issues.reject { |_, v| excludes.include?(v['milestone']) }
135
+ end
136
+ end
137
+
138
+ new_issues = (issues.keys - tasks.keys).map { |number| issues[number] }
139
+ old_tasks = (tasks.keys - issues.keys).map { |number| tasks[number] }
140
+
141
+ if new_issues.empty? && old_tasks.empty?
142
+ puts "--- #{project['name']}: Clear! ---"
143
+ next
144
+ end
145
+
146
+ puts
147
+ puts "--- #{project['name']}: Only exists in the GitHub issues (#{new_issues.length}) ---"
148
+ puts
149
+ new_issues.each do |issue|
150
+ puts issue['title']
151
+ puts issue['url'] + ' ' + issue['milestone']
152
+ puts
153
+ end
154
+ puts
155
+ puts "--- #{project['name']}: Only exists in the Things tasks (#{old_tasks.length}) ---"
156
+ puts
157
+ old_tasks.each do |task|
158
+ puts task['title']
159
+ puts task['url']
160
+ puts
161
+ end
162
+ end
163
+ end
164
+
165
+ def load_tasks
166
+ tasks = `things.sh all`.split(/\r?\n/)
167
+ project_names = @config['projects'].map { |prj| prj['name'] }
168
+ result = project_names.map { |name| [name, {}] }.to_h
169
+ tasks.each do |task|
170
+ project_names.each do |name|
171
+ next unless task.include?(name)
172
+ next unless task =~ /\sIssue #(\d+)\s/
173
+
174
+ number = Regexp.last_match[1].to_i
175
+ if result[name][number]
176
+ puts "WARN: duplicated #{name} #{number}"
177
+ end
178
+ result[name][number] = {
179
+ 'url' => "https://github.com/#{name}/issues/#{number}",
180
+ 'title' => task
181
+ }
182
+ end
183
+ end
184
+ result
185
+ end
186
+
187
+ def usage
188
+ puts 'Usage: things-diff --config FILE [help|sampleconf|fetch|diff]'
189
+ exit 1
190
+ end
191
+
192
+ def sample_config
193
+ puts <<END_OF_CONFIG
194
+ # ----------------------------------------------------------------
195
+ # things-diff config file
196
+ # https://github.com/koseki/things-issues-diff
197
+ #
198
+ # $ mkdir ~/.things-diff
199
+ # $ things-diff sampleconf > ~/.things-diff/config.yml
200
+ # ----------------------------------------------------------------
201
+
202
+ # Create a token with the repo scope.
203
+ # https://github.com/settings/tokens/new
204
+ token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
205
+
206
+ # The relative path is based on the config file.
207
+ data_file: data.yml
208
+
209
+ user: assignee-user-name
210
+ projects:
211
+ - name: repos/path
212
+ milestones:
213
+ exclude:
214
+ - Icebox
215
+ - Backlog
216
+ labels:
217
+ include:
218
+ - important
219
+
220
+ - name: repos/path2
221
+ - name: repos/path3
222
+
223
+ END_OF_CONFIG
224
+ end
225
+ end
226
+
227
+ Things::IssuesDiff.new.execute(ARGV)
@@ -0,0 +1,5 @@
1
+ module Things
2
+ class IssuesDiff
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'things/issues_diff/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "things-issues-diff"
8
+ spec.version = Things::IssuesDiff::VERSION
9
+ spec.authors = ["KOSEKI Kengo"]
10
+ spec.email = ["koseki@gmail.com"]
11
+
12
+ spec.summary = %q{Get diff between Things3 tasks and GitHub issues}
13
+ spec.description = %q{Get diff between Things3 tasks and GitHub issues}
14
+ spec.homepage = "https://example.com"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
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_dependency "octokit", "~> 4.15"
25
+ spec.add_development_dependency "bundler", "~> 1.13"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "awesome_print"
28
+ spec.add_development_dependency "rubocop"
29
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: things-issues-diff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - KOSEKI Kengo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.15'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.15'
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.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
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: awesome_print
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
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Get diff between Things3 tasks and GitHub issues
84
+ email:
85
+ - koseki@gmail.com
86
+ executables:
87
+ - things-diff
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - exe/things-diff
99
+ - lib/things/issues_diff.rb
100
+ - lib/things/issues_diff/version.rb
101
+ - things-issues-diff.gemspec
102
+ homepage: https://example.com
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.5.2
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Get diff between Things3 tasks and GitHub issues
126
+ test_files: []