waff 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0efb147c1582e77b6b80de8e4cad702e5f66b3a9d7ddc7c9711f035d7477cdfe
4
+ data.tar.gz: 6bf40532d58191a2730b57212236c1091fc41fe70c1147a26a6febc473a55ef2
5
+ SHA512:
6
+ metadata.gz: 893120b15ec204bc7841c3df4d9d44fa8f3df1607c4388ed68e7fee23c1539c8e27968a39997b288a157ecdf76767c26aded0eceaf032c05fd31235808318a5e
7
+ data.tar.gz: 463c6e9352c8a67b750b14cefec0b4807a2740d4063f4ec0fa8b502e8e33311a2e3b7799a733bc3d0d2681d6fa937a1cfac4fe98902d0e329ff8b50e19c16c71
@@ -0,0 +1,30 @@
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
@@ -0,0 +1,5 @@
1
+ require_relative 'config'
2
+ require_relative 'helper'
3
+ require_relative 'repository'
4
+ require_relative 'local_repository'
5
+ require_relative 'issue'
@@ -0,0 +1,5 @@
1
+ class Helper
2
+ def self.slug(title)
3
+ title.downcase.strip.tr(' ', '-').gsub(/[^\w-]/, '')
4
+ end
5
+ end
@@ -0,0 +1,43 @@
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
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,64 @@
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
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+ require 'httparty'
5
+ require_relative 'core.rb'
6
+
7
+ CONFIG_FILE = '.waff.yml'
8
+ EXCLUDE_FILE = '.git/info/exclude'
9
+
10
+ HELP_TEXT = <<-EOF
11
+ Usage:
12
+
13
+ waff [command] [params]
14
+
15
+ Commands:
16
+
17
+ waff list -- Shows ready and in progress issues
18
+ waff show -- Shows description of current issue (determined by current branch)
19
+ waff show number -- Shows description of a given issue
20
+ waff take number -- Sets the issue in progress, assigns it to yourself, and creates a branch for it
21
+ waff pause number -- Sets the issue to ready state
22
+ EOF
23
+
24
+ def init_config
25
+ unless File.exist?(CONFIG_FILE)
26
+ puts "No config file detected (#{CONFIG_FILE}). Will generate one now in current directory."
27
+ print 'Github username: '
28
+ user = $stdin.gets
29
+ print 'Github password/personal token: '
30
+ token = $stdin.gets
31
+ print 'Git remote (leave empty for "origin"): '
32
+ remote = $stdin.gets.strip
33
+ remote = remote.empty? ? 'origin' : remote
34
+
35
+ # Write config file
36
+ File.open(CONFIG_FILE, 'w') do |file|
37
+ file.puts "user: #{user}"
38
+ file.puts "token: #{token}"
39
+ file.puts "remote: #{remote}"
40
+ end
41
+
42
+ # Write exclude file
43
+ FileUtils.mkdir_p(File.dirname(EXCLUDE_FILE))
44
+ File.open(EXCLUDE_FILE, 'a+') do |file|
45
+ unless file.read =~ /^#{CONFIG_FILE}$/
46
+ file.puts CONFIG_FILE
47
+ end
48
+ end
49
+
50
+ end
51
+ end
52
+
53
+ def check_local_repository_exists
54
+ unless File.exist?('.git')
55
+ puts 'No git repository found. Please move to the root of your project.'
56
+ exit
57
+ end
58
+ end
59
+
60
+ check_local_repository_exists
61
+ init_config
62
+
63
+
64
+ command = ARGV[0]
65
+ issue_number = ARGV[1]
66
+ repo = Repository.new
67
+
68
+ case command
69
+ when 'take'
70
+ issue = repo.get_issue issue_number
71
+ issue.create_local_branch!
72
+ issue.assign_to_self!
73
+ issue.mark_in_progress!
74
+ when 'pause'
75
+ issue = repo.get_issue issue_number
76
+ issue.mark_ready!
77
+ when 'list'
78
+ ready_issues = repo.get_open_issues 'ready'
79
+ ready_issues += repo.get_open_issues 'to do'
80
+ puts "Ready: \n\n"
81
+ ready_issues.each do |issue|
82
+ puts "##{issue.number}\t #{issue.title}"
83
+ end
84
+ puts
85
+
86
+ in_progress_issues = repo.get_open_issues 'in progress'
87
+ puts "In progress: \n\n"
88
+ in_progress_issues.each do |issue|
89
+ puts "##{issue.number}\t #{issue.title}"
90
+ end
91
+ puts
92
+ when 'show'
93
+ issue_number ||= LocalRepository.current_issue_number
94
+ issue_number || raise('No issue number given as argument or found as current branch')
95
+ issue = repo.get_issue issue_number
96
+ puts "##{issue.number}\t #{issue.title}\n\n"
97
+ puts issue.body
98
+ else
99
+ puts HELP_TEXT
100
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: waff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Armando Andini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.16'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.16'
27
+ description:
28
+ email:
29
+ - armando.andini@gmail.com
30
+ executables:
31
+ - waff.rb
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - bin/config.rb
36
+ - bin/core.rb
37
+ - bin/helper.rb
38
+ - bin/issue.rb
39
+ - bin/local_repository.rb
40
+ - bin/repository.rb
41
+ - bin/waff.rb
42
+ homepage: https://github.com/antico5/waff
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.7.3
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Helps you with github flow based on Waffle tool
66
+ test_files: []