waff 0.0.4 → 0.0.6

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
  SHA256:
3
- metadata.gz: 744646fcc820324175c80bc0ada8766f293ba881cbddf84528235fd03d718d06
4
- data.tar.gz: 840886eb82d25a476059d99905cc20fa9568f2cb861fade621e85f4daf2f9f2f
3
+ metadata.gz: ae6ede544fb5577239ae319898d03cbe1842fa98121e5aca07115987c5ec10a1
4
+ data.tar.gz: 90868e9d22cdc6cf444670512b84c41a2a7680426e91d66609ee0bec8c156315
5
5
  SHA512:
6
- metadata.gz: db425a59c78f44c59740e4dcce60f4e81842accc78a8fa489c45fd291b91b4f55527481afcf91e3ad3b39f0c9488ccc9fab15a60e60ae2abe29619108cab361c
7
- data.tar.gz: 91e4807ebb8852b8e07f007060867e7360a9502d930cb0ef0b29d2d6016df932507a7a35036da6a6c05eb9a5b1b1890ecbae95e47e94d98c43d6dc81da772240
6
+ metadata.gz: bc7a20506959df2ac67dd68b95f46d93df12eb261bf1c534019fd23ca360fa39795175aa5c91a9bee401b0616d560ecc7e4ea658a9810afc223b89d20d6d7df4
7
+ data.tar.gz: 7a9ae012e20fb29ff6877b1df1cc6d1f63c49eea1dafe370b72813a826fde0dd3903c3b944734fcd748ce0db5aab84a8ece5390982c2034dbefa31796fec2b82
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- waff (0.0.3)
4
+ waff (0.0.6)
5
5
  httparty (~> 0.16)
6
6
 
7
7
  GEM
data/bin/waff CHANGED
@@ -1,3 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../lib/waff'
4
+
5
+ Waff::Commander.call ARGV
@@ -0,0 +1,25 @@
1
+ module Waff
2
+ class Commander
3
+ class << self
4
+ def call params
5
+ LocalRepository.check_existence!
6
+ Config.init_config!
7
+
8
+ command = params.shift
9
+
10
+ case command
11
+ when 'take'
12
+ Commands::Take.call(params)
13
+ when 'pause'
14
+ Commands::Pause.call(params)
15
+ when 'list'
16
+ Commands::List.call(params)
17
+ when 'show'
18
+ Commands::Show.call(params)
19
+ else
20
+ puts HELP_TEXT
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ module Waff
2
+ module Commands
3
+ class Command
4
+ attr_reader :params
5
+
6
+ def self.call *args
7
+ new.call(*args)
8
+ end
9
+
10
+ def github_repo
11
+ @github_repo ||= Repository.new
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'command'
2
+
3
+ module Waff
4
+ module Commands
5
+ class List < Command
6
+ def call params
7
+ ready_issues = github_repo.get_open_issues 'ready'
8
+ ready_issues += github_repo.get_open_issues 'to do'
9
+ puts "Ready: \n\n"
10
+ ready_issues.each do |issue|
11
+ puts "##{issue.number}\t #{issue.title}"
12
+ end
13
+ puts
14
+
15
+ in_progress_issues = github_repo.get_open_issues 'in progress'
16
+ puts "In progress: \n\n"
17
+ in_progress_issues.each do |issue|
18
+ puts "##{issue.number}\t #{issue.title}"
19
+ end
20
+ puts
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ require_relative 'command'
2
+
3
+ module Waff
4
+ module Commands
5
+ class Pause < Command
6
+ def call params
7
+ issue_number = params.shift
8
+ issue = github_repo.get_issue issue_number
9
+
10
+ issue.mark_ready!
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ require_relative 'command'
2
+
3
+ module Waff
4
+ module Commands
5
+ class Show < Command
6
+ def call params
7
+ issue_number = params.shift || LocalRepository.current_issue_number
8
+ issue_number || raise('No issue number given as argument or found as current branch')
9
+ issue = github_repo.get_issue issue_number
10
+
11
+ puts "##{issue.number}\t #{issue.title}\n\n"
12
+ puts issue.body
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require_relative 'command'
2
+
3
+ module Waff
4
+ module Commands
5
+ class Take < Command
6
+ def call params
7
+ issue_number = params.shift
8
+ issue = github_repo.get_issue issue_number
9
+
10
+ issue.create_local_branch!
11
+ issue.assign_to_self!
12
+ issue.mark_in_progress!
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,60 @@
1
+ module Waff
2
+ class Config
3
+ REMOTE_NOT_FOUND = <<-EOF
4
+ Can't find owner and repository. Make sure the remote name is correctly set on the configuration file.
5
+ EOF
6
+
7
+ class << self
8
+ def user
9
+ config['user']
10
+ end
11
+
12
+ def token
13
+ config['token']
14
+ end
15
+
16
+ def remote
17
+ config['remote']
18
+ end
19
+
20
+ def get_owner_and_repo
21
+ url = `git config --get remote.#{remote}.url`.strip
22
+ url[/:(.*)\.git/, 1] || raise(REMOTE_NOT_FOUND)
23
+ end
24
+
25
+ def init_config!
26
+ return if File.exist?(CONFIG_FILE)
27
+
28
+ puts "No config file detected (#{CONFIG_FILE}). Will generate one now in current directory."
29
+ print 'Github username: '
30
+ user = $stdin.gets
31
+ print 'Github password/personal token: '
32
+ token = $stdin.gets
33
+ print 'Git remote (leave empty for "origin"): '
34
+ remote = $stdin.gets.strip
35
+ remote = remote.empty? ? 'origin' : remote
36
+
37
+ # Write config file
38
+ File.open(CONFIG_FILE, 'w') do |file|
39
+ file.puts "user: #{user}"
40
+ file.puts "token: #{token}"
41
+ file.puts "remote: #{remote}"
42
+ end
43
+
44
+ # Write exclude file
45
+ FileUtils.mkdir_p(File.dirname(EXCLUDE_FILE))
46
+ File.open(EXCLUDE_FILE, 'a+') do |file|
47
+ unless file.read =~ /^#{CONFIG_FILE}$/
48
+ file.puts CONFIG_FILE
49
+ end
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def config
56
+ @config ||= YAML.load_file(CONFIG_FILE)
57
+ end
58
+ end
59
+ end
60
+ end
data/lib/waff/issue.rb ADDED
@@ -0,0 +1,49 @@
1
+ module Waff
2
+ class Issue
3
+ attr_reader :repository, :number, :title, :labels, :body
4
+
5
+ def initialize(repository, data)
6
+ @repository = repository
7
+ @number = data['number']
8
+ @title = data['title']
9
+ @body = data['body']
10
+ parse_labels data
11
+ end
12
+
13
+ def create_local_branch!
14
+ branch_name = "#{number}-#{slug}"
15
+ puts "Creating branch #{branch_name}"
16
+ `git checkout -b '#{branch_name}'`
17
+ end
18
+
19
+ def assign_to_self!
20
+ repository.assign_issue number
21
+ end
22
+
23
+ def mark_in_progress!
24
+ labels.delete 'ready'
25
+ labels.delete 'to do'
26
+ labels << 'in progress'
27
+
28
+ repository.export_labels self
29
+ end
30
+
31
+ def mark_ready!
32
+ labels << 'ready'
33
+ labels << 'to do'
34
+ labels.delete 'in progress'
35
+
36
+ repository.export_labels self
37
+ end
38
+
39
+ private
40
+
41
+ def parse_labels(data)
42
+ @labels = data['labels'].map { |label| label['name'] }
43
+ end
44
+
45
+ def slug
46
+ title.downcase.strip.tr(' ', '-').gsub(/[^\w-]/, '')
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,16 @@
1
+ module Waff
2
+ class LocalRepository
3
+ class << self
4
+ def current_issue_number
5
+ branch_name = `git rev-parse --abbrev-ref HEAD`
6
+ branch_name[/^#?(\d+)-/, 1]
7
+ end
8
+
9
+ def check_existence!
10
+ unless File.exist?('.git')
11
+ raise 'No git repository found. Please move to the root of your project.'
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,66 @@
1
+ module Waff
2
+ class Repository
3
+ include HTTParty
4
+
5
+ def initialize
6
+ @user = Config.user
7
+ @token = Config.token
8
+ @owner_and_repo = Config.get_owner_and_repo
9
+
10
+ self.class.basic_auth @user, @token
11
+ end
12
+
13
+ def get_issue(number)
14
+ response = self.class.get github_url ['issues', number]
15
+
16
+ if response.success?
17
+ Issue.new(self, response.parsed_response)
18
+ else
19
+ puts 'ERROR requesting issue'
20
+ puts response.body
21
+ end
22
+ end
23
+
24
+ def assign_issue(number)
25
+ url = github_url ['issues', number, 'assignees']
26
+ response = self.class.post url, body: { assignees: [@user] }.to_json
27
+ if response.success?
28
+ puts "Successfully assigned issue ##{number} to #{@user}."
29
+ else
30
+ puts 'ERROR assigning user to issue'
31
+ puts response.body
32
+ end
33
+ end
34
+
35
+ def export_labels issue
36
+ url = github_url ['issues', issue.number, 'labels']
37
+ response = self.class.put url, body: issue.labels.to_json
38
+ if response.success?
39
+ puts "Successfully assigned #{issue.labels.inspect} labels to ##{issue.number}"
40
+ else
41
+ puts 'ERROR setting issue labels'
42
+ puts response.body
43
+ end
44
+ end
45
+
46
+ def get_open_issues label
47
+ response = self.class.get github_url(['issues']), query: { labels: label }
48
+
49
+ if response.success?
50
+ issues_data = response.parsed_response
51
+ issues_data.reject! { |data| data['pull_request'] }
52
+ issues_data.map { |data| Issue.new(self, data) }
53
+ else
54
+ puts 'ERROR requesting open issues'
55
+ puts response.body
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def github_url(nodes)
62
+ subpath = nodes.join '/'
63
+ "https://api.github.com/repos/#{@owner_and_repo}/" + subpath
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module Waff
2
+ VERSION = '0.0.6'.freeze
3
+ end
data/lib/waff.rb CHANGED
@@ -1,11 +1,15 @@
1
1
  require 'fileutils'
2
2
  require 'httparty'
3
- require_relative 'core.rb'
4
3
 
5
- CONFIG_FILE = '.waff.yml'
6
- EXCLUDE_FILE = '.git/info/exclude'
4
+ Dir[File.join(__dir__, 'waff', '**/*.rb')].each { |file| require file }
5
+
6
+ module Waff
7
+ CONFIG_FILE = '.waff.yml'
8
+ EXCLUDE_FILE = '.git/info/exclude'
9
+
10
+ HELP_TEXT = <<-EOF
11
+ Waff version #{Waff::VERSION}
7
12
 
8
- HELP_TEXT = <<-EOF
9
13
  Usage:
10
14
 
11
15
  waff [command] [params]
@@ -17,82 +21,6 @@ waff show -- Shows description of current issue (determined by current b
17
21
  waff show number -- Shows description of a given issue
18
22
  waff take number -- Sets the issue in progress, assigns it to yourself, and creates a branch for it
19
23
  waff pause number -- Sets the issue to ready state
20
- EOF
21
-
22
- def init_config
23
- unless File.exist?(CONFIG_FILE)
24
- puts "No config file detected (#{CONFIG_FILE}). Will generate one now in current directory."
25
- print 'Github username: '
26
- user = $stdin.gets
27
- print 'Github password/personal token: '
28
- token = $stdin.gets
29
- print 'Git remote (leave empty for "origin"): '
30
- remote = $stdin.gets.strip
31
- remote = remote.empty? ? 'origin' : remote
32
-
33
- # Write config file
34
- File.open(CONFIG_FILE, 'w') do |file|
35
- file.puts "user: #{user}"
36
- file.puts "token: #{token}"
37
- file.puts "remote: #{remote}"
38
- end
39
-
40
- # Write exclude file
41
- FileUtils.mkdir_p(File.dirname(EXCLUDE_FILE))
42
- File.open(EXCLUDE_FILE, 'a+') do |file|
43
- unless file.read =~ /^#{CONFIG_FILE}$/
44
- file.puts CONFIG_FILE
45
- end
46
- end
47
-
48
- end
49
- end
50
-
51
- def check_local_repository_exists
52
- unless File.exist?('.git')
53
- puts 'No git repository found. Please move to the root of your project.'
54
- exit
55
- end
56
- end
57
-
58
- check_local_repository_exists
59
- init_config
60
-
61
-
62
- command = ARGV[0]
63
- issue_number = ARGV[1]
64
- repo = Repository.new
65
-
66
- case command
67
- when 'take'
68
- issue = repo.get_issue issue_number
69
- issue.create_local_branch!
70
- issue.assign_to_self!
71
- issue.mark_in_progress!
72
- when 'pause'
73
- issue = repo.get_issue issue_number
74
- issue.mark_ready!
75
- when 'list'
76
- ready_issues = repo.get_open_issues 'ready'
77
- ready_issues += repo.get_open_issues 'to do'
78
- puts "Ready: \n\n"
79
- ready_issues.each do |issue|
80
- puts "##{issue.number}\t #{issue.title}"
81
- end
82
- puts
24
+ EOF
83
25
 
84
- in_progress_issues = repo.get_open_issues 'in progress'
85
- puts "In progress: \n\n"
86
- in_progress_issues.each do |issue|
87
- puts "##{issue.number}\t #{issue.title}"
88
- end
89
- puts
90
- when 'show'
91
- issue_number ||= LocalRepository.current_issue_number
92
- issue_number || raise('No issue number given as argument or found as current branch')
93
- issue = repo.get_issue issue_number
94
- puts "##{issue.number}\t #{issue.title}\n\n"
95
- puts issue.body
96
- else
97
- puts HELP_TEXT
98
26
  end
data/waff.gemspec CHANGED
@@ -1,7 +1,10 @@
1
1
  # coding: utf-8
2
+
3
+ require_relative 'lib/waff/version'
4
+
2
5
  Gem::Specification.new do |spec|
3
6
  spec.name = "waff"
4
- spec.version = "0.0.4"
7
+ spec.version = Waff::VERSION
5
8
  spec.authors = ["Armando Andini"]
6
9
  spec.email = ["armando.andini@gmail.com"]
7
10
  spec.summary = %q{Helps you with github flow based on Waffle tool}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Armando Andini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-23 00:00:00.000000000 Z
11
+ date: 2018-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -35,13 +35,18 @@ files:
35
35
  - Gemfile
36
36
  - Gemfile.lock
37
37
  - bin/waff
38
- - lib/config.rb
39
- - lib/core.rb
40
- - lib/helper.rb
41
- - lib/issue.rb
42
- - lib/local_repository.rb
43
- - lib/repository.rb
44
38
  - lib/waff.rb
39
+ - lib/waff/commander.rb
40
+ - lib/waff/commands/command.rb
41
+ - lib/waff/commands/list.rb
42
+ - lib/waff/commands/pause.rb
43
+ - lib/waff/commands/show.rb
44
+ - lib/waff/commands/take.rb
45
+ - lib/waff/config.rb
46
+ - lib/waff/issue.rb
47
+ - lib/waff/local_repository.rb
48
+ - lib/waff/repository.rb
49
+ - lib/waff/version.rb
45
50
  - waff.gemspec
46
51
  homepage: https://github.com/antico5/waff
47
52
  licenses:
data/lib/config.rb DELETED
@@ -1,30 +0,0 @@
1
- class Config
2
- REMOTE_NOT_FOUND = <<-EOF
3
- Can't find owner and repository. Make sure the remote name is correctly set on the configuration file.
4
- EOF
5
-
6
- class << self
7
- def user
8
- config['user']
9
- end
10
-
11
- def token
12
- config['token']
13
- end
14
-
15
- def remote
16
- config['remote']
17
- end
18
-
19
- def get_owner_and_repo
20
- url = `git config --get remote.#{remote}.url`.strip
21
- url[/:(.*)\.git/, 1] || raise(REMOTE_NOT_FOUND)
22
- end
23
-
24
- private
25
-
26
- def config
27
- @config ||= YAML.load_file(CONFIG_FILE)
28
- end
29
- end
30
- end
data/lib/core.rb DELETED
@@ -1,5 +0,0 @@
1
- require_relative 'config'
2
- require_relative 'helper'
3
- require_relative 'repository'
4
- require_relative 'local_repository'
5
- require_relative 'issue'
data/lib/helper.rb DELETED
@@ -1,5 +0,0 @@
1
- class Helper
2
- def self.slug(title)
3
- title.downcase.strip.tr(' ', '-').gsub(/[^\w-]/, '')
4
- end
5
- end
data/lib/issue.rb DELETED
@@ -1,43 +0,0 @@
1
- class Issue
2
- attr_reader :repository, :number, :title, :labels, :body
3
-
4
- def initialize(repository, data)
5
- @repository = repository
6
- @number = data['number']
7
- @title = data['title']
8
- @body = data['body']
9
- parse_labels data
10
- end
11
-
12
- def create_local_branch!
13
- branch_name = "#{number}-#{Helper.slug title}"
14
- puts "Creating branch #{branch_name}"
15
- `git checkout -b '#{branch_name}'`
16
- end
17
-
18
- def assign_to_self!
19
- repository.assign_issue number
20
- end
21
-
22
- def mark_in_progress!
23
- labels.delete 'ready'
24
- labels.delete 'to do'
25
- labels << 'in progress'
26
-
27
- repository.export_labels self
28
- end
29
-
30
- def mark_ready!
31
- labels << 'ready'
32
- labels << 'to do'
33
- labels.delete 'in progress'
34
-
35
- repository.export_labels self
36
- end
37
-
38
- private
39
-
40
- def parse_labels(data)
41
- @labels = data['labels'].map { |label| label['name'] }
42
- end
43
- end
@@ -1,8 +0,0 @@
1
- class LocalRepository
2
- class << self
3
- def current_issue_number
4
- branch_name = `git rev-parse --abbrev-ref HEAD`
5
- branch_name[/^#?(\d+)-/, 1]
6
- end
7
- end
8
- end
data/lib/repository.rb DELETED
@@ -1,64 +0,0 @@
1
- class Repository
2
- include HTTParty
3
-
4
- def initialize
5
- @user = Config.user
6
- @token = Config.token
7
- @owner_and_repo = Config.get_owner_and_repo
8
-
9
- self.class.basic_auth @user, @token
10
- end
11
-
12
- def get_issue(number)
13
- response = self.class.get github_url ['issues', number]
14
-
15
- if response.success?
16
- Issue.new(self, JSON.parse(response.body))
17
- else
18
- puts 'ERROR requesting issue'
19
- puts response.body
20
- end
21
- end
22
-
23
- def assign_issue(number)
24
- url = github_url ['issues', number, 'assignees']
25
- response = self.class.post url, body: { assignees: [@user] }.to_json
26
- if response.success?
27
- puts "Successfully assigned issue ##{number} to #{@user}."
28
- else
29
- puts 'ERROR assigning user to issue'
30
- puts response.body
31
- end
32
- end
33
-
34
- def export_labels issue
35
- url = github_url ['issues', issue.number, 'labels']
36
- response = self.class.put url, body: issue.labels.to_json
37
- if response.success?
38
- puts "Successfully assigned #{issue.labels.inspect} labels to ##{issue.number}"
39
- else
40
- puts 'ERROR setting issue labels'
41
- puts response.body
42
- end
43
- end
44
-
45
- def get_open_issues label
46
- response = self.class.get github_url(['issues']), query: { labels: label }
47
-
48
- if response.success?
49
- issues_data = JSON.parse response.body
50
- issues_data.reject! { |data| data['pull_request'] }
51
- issues_data.map { |data| Issue.new(self, data) }
52
- else
53
- puts 'ERROR requesting open issues'
54
- puts response.body
55
- end
56
- end
57
-
58
- private
59
-
60
- def github_url(nodes)
61
- subpath = nodes.join '/'
62
- "https://api.github.com/repos/#{@owner_and_repo}/" + subpath
63
- end
64
- end