prima-twig 0.0.4

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 52a29cea0a6accb2dda2de94929e2a8d04e41bdb
4
+ data.tar.gz: ce10a9852acabd152144bbb89506114177fad993
5
+ SHA512:
6
+ metadata.gz: 228cdd74a2241fe2f64be29344711a0a02df71a9f01a4ae3e50da693027633b0a2b0e5a26833183f2988196f12a8ebb12615c2d0ff36023941a1ebd8fc8ce863
7
+ data.tar.gz: 1cd926a745a749c6938c8316da1cc12b654f5bd8540de8a5bad1c19a059a511caafe5d240efa9fc8649638a8efa02d692efb6c1423ebaedb6d8ce3f871296d8c
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require_relative '../lib/prima_twig.rb'
5
+ require 'colorize'
6
+ require 'highline/import'
7
+
8
+
9
+ def help_content
10
+ <<-HELP
11
+
12
+ twig-open-pr
13
+ ============
14
+
15
+ Opens a PR on github for this branch, if not already opened
16
+
17
+ Synopsis
18
+ --------
19
+
20
+ twig open-pr [-b|--branch <branch>]
21
+
22
+ Description
23
+ -----------
24
+
25
+ Checks if a pr is already opened for this branch, if not opens it, otherwise do nothing
26
+
27
+ Subcommand for Twig: <http://rondevera.github.io/twig/>
28
+ Author: Matteo Giachino <https://github.com/matteosister>
29
+
30
+ HELP
31
+ end
32
+
33
+ args = ARGV.dup
34
+
35
+ if args.include?('--help')
36
+ puts help_content
37
+ exit
38
+ end
39
+
40
+ class OpenPR
41
+ def initialize
42
+ @prima = Prima.new
43
+ end
44
+
45
+ def execute
46
+ unless @prima.gh.user_authenticated?
47
+ puts 'Non autenticato'
48
+ exit 1
49
+ end
50
+ unless is_a_valid_branch?
51
+ puts "Non puoi creare una pull request dal branch #{ @prima.current_branch_name }".red
52
+ exit 1
53
+ end
54
+
55
+ unless is_on_github?
56
+ puts "Il branch #{ @prima.current_branch_name } non è su github".red
57
+ exit 1
58
+ end
59
+
60
+ unless @prima.get_pr_url.nil?
61
+ puts "Esiste già una pull request per il branch #{ @prima.current_branch_name }. url: #{ @prima.get_pr_url }".yellow
62
+ pr_property = @prima.twig.get_branch_property(@prima.current_branch_name, 'pr')
63
+ if pr_property.nil?
64
+ cmd = %{ twig pr "#{ @prima.get_pr.number }"}
65
+ exec(cmd)
66
+ end
67
+ exit 0
68
+ end
69
+
70
+ pr = create_pull_request
71
+ puts "Pull Request ##{ pr.number } created"
72
+ cmd = %{ twig pr "#{ pr.number }"}
73
+ exec(cmd)
74
+ puts pr.html_url
75
+ exit 0
76
+ end
77
+
78
+ def is_a_valid_branch?
79
+ not @prima.disabled_branches.include? @prima.current_branch_name
80
+ end
81
+
82
+ def is_on_github?
83
+ begin
84
+ @prima.gh.branch @prima.repo_name, @prima.current_branch_name
85
+ true
86
+ rescue Octokit::NotFound
87
+ return false
88
+ end
89
+ end
90
+
91
+ def create_pull_request
92
+ title = ask('Titolo: ')
93
+ head = @prima.current_branch_name
94
+ base = 'dev'
95
+ body = ask('Body: ')
96
+ @prima.gh.create_pull_request @prima.repo_name, base, head, title, body
97
+ end
98
+ end
99
+
100
+ OpenPR.new.execute
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require_relative '../lib/prima_twig.rb'
5
+ require 'colorize'
6
+ require 'highline/import'
7
+
8
+
9
+ def help_content
10
+ <<-HELP
11
+
12
+ twig-review
13
+ ===========
14
+
15
+ Puts the pull request for the current branch in review
16
+
17
+ Synopsis
18
+ --------
19
+
20
+ twig review [-b|--branch <branch>]
21
+
22
+ Description
23
+ -----------
24
+
25
+ Puts the current branch pr in review
26
+
27
+ Subcommand for Twig: <http://rondevera.github.io/twig/>
28
+ Author: Matteo Giachino <https://github.com/matteosister>
29
+
30
+ HELP
31
+ end
32
+
33
+ args = ARGV.dup
34
+
35
+ if args.include?('--help')
36
+ puts help_content
37
+ exit
38
+ end
39
+
40
+ class Review
41
+ def initialize
42
+ @prima = Prima.new
43
+ end
44
+
45
+ def execute
46
+ unless @prima.is_already_a_pr?
47
+ puts 'Il branch attuale non è una pull request'
48
+ exit 1
49
+ end
50
+
51
+ if @prima.is_review?
52
+ puts 'Il branch attuale è già in fase di review'
53
+ exit
54
+ end
55
+
56
+ @prima.gh.add_labels_to_an_issue @prima.repo_name, @prima.get_property('pr'), [ Prima::REVIEW_LABEL ]
57
+ puts "Il branch #{ @prima.current_branch_name } è ora in review".green
58
+ cmd = %{ twig review si }
59
+ exec(cmd)
60
+ exit 0
61
+ end
62
+ end
63
+
64
+ Review.new.execute
@@ -0,0 +1,90 @@
1
+ require 'twig'
2
+ require 'octokit'
3
+ require 'trello'
4
+ require 'yaml'
5
+
6
+ class Prima
7
+ REVIEW_LABEL='review'
8
+ GITHUB='github'
9
+ TRELLO='trello'
10
+ attr_reader :gh, :twig, :config
11
+
12
+ def initialize
13
+ @twig = Twig.new(:read_options => true)
14
+ unless has_config?
15
+ generate_config
16
+ end
17
+ @config = YAML.load_file 'twig.yml'
18
+ create_clients
19
+ end
20
+
21
+ def has_config?
22
+ File.exist? 'twig.yml'
23
+ end
24
+
25
+ def generate_config
26
+ puts 'Progetto non inizializzato'.red
27
+ puts 'Creazione del file di configurazione'.yellow
28
+ githubToken = ask 'github token: '
29
+ trelloToken = ask 'trello token: '
30
+ conf = {
31
+ GITHUB => githubToken.to_s,
32
+ TRELLO => trelloToken.to_s
33
+ }
34
+ File.open('twig.yml', 'w') { |file|
35
+ file.write conf.to_yaml
36
+ puts 'File di configurazione creato'.green
37
+ }
38
+ end
39
+
40
+ def create_clients
41
+ @gh = Octokit::Client.new(:access_token => @config['github'])
42
+ end
43
+
44
+ def disabled_branches
45
+ %w(master dev)
46
+ end
47
+
48
+ def repo_name
49
+ `git config --get remote.origin.url`.split(':').last.chomp.chomp('.git')
50
+ end
51
+
52
+ def current_branch_ref
53
+ "primait:#{ @current_branch_name }"
54
+ end
55
+
56
+ def current_branch_name
57
+ @twig.current_branch_name
58
+ end
59
+
60
+ def get_pr_url
61
+ pr = get_pr
62
+ if pr.nil?
63
+ nil
64
+ else
65
+ pr.html_url
66
+ end
67
+ end
68
+
69
+ def get_pr
70
+ prs = @gh.pulls repo_name, { head: current_branch_ref }
71
+ if prs.length > 0
72
+ prs[0]
73
+ else
74
+ nil
75
+ end
76
+ end
77
+
78
+ def is_already_a_pr?
79
+ not get_pr_url.nil?
80
+ end
81
+
82
+ def is_review?
83
+ labels = @gh.labels_for_issue repo_name, get_property('pr')
84
+ not labels.find_index{ |l| l.name == REVIEW_LABEL }.nil?
85
+ end
86
+
87
+ def get_property (name)
88
+ @twig.get_branch_property current_branch_name, name
89
+ end
90
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prima-twig
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Matteo Giachino
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-26 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: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ description: Our tools to manage git and github
28
+ email: matteog@gmail.com
29
+ executables:
30
+ - twig-open-pr
31
+ - twig-review
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - bin/twig-open-pr
36
+ - bin/twig-review
37
+ - lib/prima_twig.rb
38
+ homepage: http://rubygems.org/gems/prima-twig
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.2.2
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: The Prima twig toolbelt
62
+ test_files: []