gitsflow 0.6.3 → 0.8.2.alfa
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 +4 -4
- data/.env.yml +1 -0
- data/Gemfile.lock +66 -3
- data/README.md +5 -28
- data/bin/sflow +2 -2
- data/gitsflow.gemspec +62 -34
- data/lib/Git/git.rb +42 -42
- data/lib/GitLab/gitlab.rb +79 -46
- data/lib/GitLab/issue.rb +84 -52
- data/lib/GitLab/merge_request.rb +76 -57
- data/lib/GitLab/user.rb +3 -3
- data/lib/Utils/changelog.rb +10 -0
- data/lib/Utils/putdotenv.rb +3 -0
- data/lib/command.rb +19 -0
- data/lib/config.rb +30 -12
- data/lib/menu.rb +253 -0
- data/lib/sflow/sflow.rb +666 -0
- data/lib/sflow/version.rb +3 -0
- data/lib/tty_integration.rb +50 -0
- metadata +298 -11
- data/lib/sflow.rb +0 -651
data/lib/GitLab/issue.rb
CHANGED
@@ -1,27 +1,29 @@
|
|
1
|
+
require 'tty_integration'
|
2
|
+
class GitLab::Issue
|
3
|
+
include TtyIntegration
|
1
4
|
|
2
|
-
|
3
|
-
attr_accessor :title, :labels, :assignee_id, :description, :branch, :iid, :obj_gitlab, :status
|
4
|
-
@comments = []
|
5
|
-
@labels = []
|
5
|
+
attr_accessor :title, :labels, :assignee_id, :description, :branch, :iid, :obj_gitlab, :status, :web_url
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
@comments = []
|
8
|
+
@labels = []
|
9
|
+
|
10
|
+
attr_reader :comments
|
10
11
|
|
11
|
-
def comments=obj
|
12
|
+
def comments=(obj)
|
12
13
|
@comments << obj
|
13
14
|
end
|
14
15
|
|
15
16
|
def initialize(params = {})
|
16
17
|
@title = params[:title]
|
17
|
-
@
|
18
|
+
@parent_branch_name = params[:parent_branch_name]
|
19
|
+
@labels = params[:labels] || []
|
18
20
|
@description = params[:description]
|
19
21
|
@branch = params[:branch]
|
20
22
|
@comments = []
|
21
|
-
@assignee_id = GitLab::User.me[
|
23
|
+
@assignee_id = GitLab::User.me['id']
|
22
24
|
end
|
23
25
|
|
24
|
-
def set_default_branch
|
26
|
+
def set_default_branch(branch)
|
25
27
|
@description = "* ~default_branch #{branch}\n" + @description
|
26
28
|
end
|
27
29
|
|
@@ -31,15 +33,16 @@ class GitLab::Issue
|
|
31
33
|
params.merge!(description: @description.to_s)
|
32
34
|
params.merge!(labels: @labels.join(','))
|
33
35
|
params.merge!(assignee_id: @assignee_id)
|
34
|
-
|
36
|
+
|
35
37
|
# label = params.fetch(:label) || ''
|
36
38
|
# assignee_id = params.fetch(:assignee_id) || ''
|
37
|
-
print "\nCreate new GitLab issue \n\n".yellow
|
38
|
-
url = "projects/#{$GITLAB_PROJECT_ID}/issues"
|
39
|
+
# print "\nCreate new GitLab issue \n\n".yellow
|
40
|
+
url = "projects/#{$GITLAB_PROJECT_ID}/issues"
|
39
41
|
issue_json = GitLab.request_post(url, params)
|
40
|
-
@iid = issue_json[
|
41
|
-
|
42
|
-
|
42
|
+
@iid = issue_json['iid']
|
43
|
+
@web_url = issue_json['web_url']
|
44
|
+
self
|
45
|
+
# success("Issue created with success!\nURL: #{issue_json["web_url"]}")
|
43
46
|
end
|
44
47
|
|
45
48
|
def close
|
@@ -48,10 +51,10 @@ class GitLab::Issue
|
|
48
51
|
params.merge!(state_event: 'close')
|
49
52
|
params.merge!(description: @description.to_s)
|
50
53
|
params.merge!(labels: @labels.join(','))
|
51
|
-
|
52
|
-
url = "projects/#{$GITLAB_PROJECT_ID}/issues/#{@iid}"
|
54
|
+
|
55
|
+
url = "projects/#{$GITLAB_PROJECT_ID}/issues/#{@iid}"
|
53
56
|
GitLab.request_put(url, params)
|
54
|
-
print "Issue '#{@title}' closed with success!\n".green
|
57
|
+
# print "Issue '#{@title}' closed with success!\n".green
|
55
58
|
end
|
56
59
|
|
57
60
|
def update
|
@@ -60,36 +63,54 @@ class GitLab::Issue
|
|
60
63
|
params.merge!(description: @description.to_s)
|
61
64
|
params.merge!(labels: @labels.join(','))
|
62
65
|
params.merge!(assignee_id: @assignee_id)
|
63
|
-
|
66
|
+
|
64
67
|
# label = params.fetch(:label) || ''
|
65
68
|
# assignee_id = params.fetch(:assignee_id) || ''
|
66
|
-
print "\nUpdate GitLab issue\n\n".yellow
|
67
|
-
url = "projects/#{$GITLAB_PROJECT_ID}/issues/#{@iid}"
|
69
|
+
# print "\nUpdate GitLab issue\n\n".yellow
|
70
|
+
url = "projects/#{$GITLAB_PROJECT_ID}/issues/#{@iid}"
|
68
71
|
GitLab.request_put(url, params)
|
69
|
-
|
72
|
+
# prompt.say(pastel.cyan("\nIssue updated with success!"))
|
70
73
|
end
|
71
74
|
|
72
75
|
def self.find_by(search)
|
73
76
|
url = "projects/#{$GITLAB_PROJECT_ID}/issues?search=#{search.values[0]}&in=#{search.keys[0]}&state=opened"
|
74
77
|
issue_json = GitLab.request_get(url)[0]
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
raise "Issue not found #{search.keys[0]}" unless issue_json
|
79
|
+
|
80
|
+
issue = GitLab::Issue.new
|
81
|
+
issue.set_data issue_json
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.find_by_id(id)
|
85
|
+
url = "projects/#{$GITLAB_PROJECT_ID}/issues?iids[]=#{id}"
|
86
|
+
issue_json = GitLab.request_get(url)[0]
|
87
|
+
raise "Issue not found #{search.keys[0]}" unless issue_json
|
88
|
+
|
89
|
+
issue = GitLab::Issue.new
|
90
|
+
issue.set_data issue_json
|
91
|
+
end
|
82
92
|
|
83
93
|
def self.find_by_branch(branch)
|
84
|
-
url = "projects/#{$GITLAB_PROJECT_ID}/issues?search
|
94
|
+
url = "projects/#{$GITLAB_PROJECT_ID}/issues?search='~default_branch #{branch}'"
|
95
|
+
issue_json = GitLab.request_get(URI::Generic::DEFAULT_PARSER.escape(url))[0]
|
96
|
+
unless issue_json
|
97
|
+
raise "Issue não encontrada #{branch}. \nVerifique se existe a label 'default_branch' na descrição da issue"
|
98
|
+
end
|
99
|
+
|
100
|
+
issue = GitLab::Issue.new
|
101
|
+
issue.set_data issue_json
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.find_by_parent_branch(branch)
|
105
|
+
url = "projects/#{$GITLAB_PROJECT_ID}/issues?search='~parent #{branch}'"
|
85
106
|
issue_json = GitLab.request_get(url)[0]
|
86
|
-
|
87
|
-
|
88
|
-
issue.set_data issue_json
|
89
|
-
else
|
90
|
-
raise "Issue not found #{branch}. \nCheck if exist the label default_branch in the body description"
|
107
|
+
unless issue_json
|
108
|
+
raise "Issue não encontrada #{branch}. \nVerifique se existe a label 'default_branch' na descrição da issue"
|
91
109
|
end
|
92
|
-
|
110
|
+
|
111
|
+
issue = GitLab::Issue.new
|
112
|
+
issue.set_data issue_json
|
113
|
+
end
|
93
114
|
|
94
115
|
def self.all
|
95
116
|
url = "projects/#{$GITLAB_PROJECT_ID}/issues?state=opened"
|
@@ -106,7 +127,7 @@ class GitLab::Issue
|
|
106
127
|
issues = []
|
107
128
|
issues_gitlab = GitLab.request_get(url)
|
108
129
|
issues_gitlab.each do |obj|
|
109
|
-
issue =
|
130
|
+
issue = new
|
110
131
|
issue.set_data(obj)
|
111
132
|
|
112
133
|
issues << issue
|
@@ -121,33 +142,44 @@ class GitLab::Issue
|
|
121
142
|
|
122
143
|
def msg_changelog
|
123
144
|
# a.description.match(/(\* \~changelog .*\n)+/).to_a
|
124
|
-
|
145
|
+
|
146
|
+
description.match(/\* ~changelog .*\n?/).to_s.gsub('* ~changelog ', '')
|
147
|
+
rescue StandardError
|
148
|
+
nil
|
125
149
|
end
|
126
150
|
|
127
151
|
def list_tasks
|
128
152
|
# a.description.match(/(\* \~changelog .*\n)+/).to_a
|
129
|
-
|
153
|
+
|
154
|
+
description.match(/\* ~tasks .*\n?/).to_s.gsub('* ~tasks ', '')
|
155
|
+
rescue StandardError
|
156
|
+
nil
|
130
157
|
end
|
131
158
|
|
132
|
-
def add_comment
|
159
|
+
def add_comment(note)
|
133
160
|
comment = GitLab::Comment.new(issue_iid: @iid, body: note)
|
134
161
|
@comments << comment
|
135
162
|
comment.create
|
136
163
|
end
|
137
164
|
|
138
|
-
def set_data
|
139
|
-
@iid = obj[
|
140
|
-
@title = obj[
|
141
|
-
@labels = obj[
|
142
|
-
@description = obj[
|
143
|
-
@assignee_id = obj[
|
144
|
-
@branch =
|
145
|
-
|
165
|
+
def set_data(obj)
|
166
|
+
@iid = obj['iid']
|
167
|
+
@title = obj['title']
|
168
|
+
@labels = obj['labels']
|
169
|
+
@description = obj['description']
|
170
|
+
@assignee_id = obj['assignees'][0]['id']
|
171
|
+
@branch = begin
|
172
|
+
obj['description'].match(/\* ~default_branch .*\n?/).to_s.gsub('* ~default_branch ',
|
173
|
+
'').chomp.strip
|
174
|
+
rescue StandardError
|
175
|
+
nil
|
176
|
+
end
|
177
|
+
@obj_gitlab = obj
|
146
178
|
self
|
147
179
|
end
|
148
180
|
|
149
|
-
def create_link_issue
|
181
|
+
def create_link_issue(target_issue_iid)
|
150
182
|
url = "projects/#{$GITLAB_PROJECT_ID}/issues/#{@iid}/links?target_project_id=#{$GITLAB_PROJECT_ID}&target_issue_iid=#{target_issue_iid}"
|
151
183
|
GitLab.request_post(url, params)
|
152
184
|
end
|
153
|
-
end
|
185
|
+
end
|
data/lib/GitLab/merge_request.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
require 'tty_integration'
|
2
|
+
|
1
3
|
class GitLab::MergeRequest
|
4
|
+
include TtyIntegration
|
2
5
|
@options = {}
|
3
|
-
attr_accessor :source_branch, :target_branch, :title, :options, :assignee_id, :labels, :issue_iid, :obj_gitlab,
|
6
|
+
attr_accessor :source_branch, :target_branch, :title, :options, :assignee_id, :labels, :issue_iid, :obj_gitlab,
|
7
|
+
:type, :description
|
8
|
+
|
4
9
|
@labels = []
|
5
10
|
def initialize(params = {})
|
6
11
|
@source_branch = params[:source_branch]
|
@@ -10,73 +15,87 @@ class GitLab::MergeRequest
|
|
10
15
|
@issue_iid = params[:issue_iid]
|
11
16
|
@type = params[:type]
|
12
17
|
@description = params[:description]
|
13
|
-
@options
|
18
|
+
@options = params[:options]
|
14
19
|
end
|
15
20
|
|
16
21
|
def create
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
url = "projects/#{$GITLAB_PROJECT_ID}/merge_requests"
|
36
|
-
|
22
|
+
# if type != 'hotfix'
|
23
|
+
# users = GitLab::User.all
|
24
|
+
# print "Users list:\n\n".yellow
|
25
|
+
# print "----------------------------\n".blue
|
26
|
+
# print "#{"0".ljust(10)} - Empty\n".blue
|
27
|
+
# users.each do |user|
|
28
|
+
# print "#{user['id'].to_s.ljust(10)} - #{user['name']}\n".blue
|
29
|
+
# end
|
30
|
+
# print "----------------------------\n".blue
|
31
|
+
# print "Choice user ID for assignee:\n".yellow
|
32
|
+
# assignee_id = STDIN.gets.chomp
|
33
|
+
# print "\n#{assignee_id}, "
|
34
|
+
# print "ok!\n".green
|
35
|
+
# end
|
36
|
+
users_list = GitLab::User.all.map { |u| "#{u['id']} - #{u['name']}" }
|
37
|
+
user_selected = prompt.select('Quem vai aprovar o MR?', users_list, symbols: { marker: '>' }, filter: true)
|
38
|
+
assignee_id = user_selected.delete("\n").split('-')[0].strip
|
39
|
+
|
40
|
+
url = "projects/#{$GITLAB_PROJECT_ID}/merge_requests"
|
41
|
+
|
37
42
|
labels = ['merge_request']
|
38
43
|
labels << type if type
|
39
44
|
@obj_gitlab = GitLab.request_post(url, {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
print "Merge request created with success!\n\n".green
|
49
|
-
end
|
45
|
+
source_branch: @source_branch,
|
46
|
+
target_branch: @target_branch,
|
47
|
+
title: @title,
|
48
|
+
labels: labels.join(','),
|
49
|
+
description: @description,
|
50
|
+
assignee_id: assignee_id.to_i,
|
51
|
+
squash: true,
|
52
|
+
squash_on_merge: true
|
50
53
|
|
54
|
+
})
|
55
|
+
|
56
|
+
prompt.say(pastel.cyan("Merge request criado com sucesso!\n\n"))
|
57
|
+
end
|
51
58
|
|
52
59
|
def create_code_review
|
53
|
-
print "Create merge request for code review: ".yellow
|
54
|
-
print "#{@source_branch} into #{@target_branch}\n\n".green
|
60
|
+
# print "Create merge request for code review: ".yellow
|
61
|
+
# print "#{@source_branch} into #{@target_branch}\n\n".green
|
62
|
+
# users = GitLab::User.all
|
63
|
+
# print "Users list:\n\n".yellow
|
64
|
+
# print "----------------------------\n".blue
|
65
|
+
# print "#{"0".ljust(10)} - Empty\n".blue
|
66
|
+
# users.each do |user|
|
67
|
+
# print "#{user['id'].to_s.ljust(10)} - #{user['name']}\n".blue
|
68
|
+
# end
|
69
|
+
# print "----------------------------\n".blue
|
70
|
+
# print "Choice user ID for assignee code review:\n".yellow
|
71
|
+
# assignee_id = STDIN.gets.chomp
|
72
|
+
# print "\n#{assignee_id}, "
|
73
|
+
# print "ok!\n".green
|
74
|
+
|
55
75
|
users = GitLab::User.all
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
print "#{user['id'].to_s.ljust(10)} - #{user['name']}\n".blue
|
76
|
+
assignee_id = prompt.select('Quem vai fazer o codereview?', symbols: { marker: '>' }, filter: true) do |menu|
|
77
|
+
users.each do |user|
|
78
|
+
menu.choice user['name'], user['id']
|
79
|
+
end
|
61
80
|
end
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
print "ok!\n".green
|
67
|
-
|
68
|
-
url = "projects/#{$GITLAB_PROJECT_ID}/merge_requests"
|
69
|
-
title = "WIP: ##{@issue_iid} - Code review #{@source_branch}"
|
81
|
+
|
82
|
+
url = "projects/#{$GITLAB_PROJECT_ID}/merge_requests"
|
83
|
+
title = "Draft: ##{@issue_iid} - Code review #{@source_branch}"
|
84
|
+
description = 'Este Merge Request de codereview foi criado pelo gitsflow'
|
70
85
|
@obj_gitlab = GitLab.request_post(url, {
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
86
|
+
source_branch: @source_branch,
|
87
|
+
target_branch: @target_branch,
|
88
|
+
title:,
|
89
|
+
description:,
|
90
|
+
labels: @labels,
|
91
|
+
assignee_id: GitLab::User.me['id'].to_i,
|
92
|
+
reviewer_ids: [assignee_id.to_i]
|
93
|
+
})
|
80
94
|
|
95
|
+
return error(@obj_gitlab.dig('message').join('.')) if @obj_gitlab.has_key? 'message'
|
81
96
|
|
82
|
-
|
97
|
+
success("Code Review criado com sucesso!\n\n")
|
98
|
+
|
99
|
+
# print "Merge request for Code Review created with success!\n\n".green
|
100
|
+
end
|
101
|
+
end
|
data/lib/GitLab/user.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'tty_integration'
|
1
2
|
class GitLab::User
|
2
3
|
attr_accessor :id, :email, :name
|
3
4
|
|
@@ -7,14 +8,13 @@ class GitLab::User
|
|
7
8
|
|
8
9
|
def self.me
|
9
10
|
user = GitLab.request_get('user')
|
10
|
-
|
11
11
|
return user if user
|
12
12
|
|
13
|
-
raise "
|
13
|
+
raise "Quem é você? \nNão consegui localizar seu usuário no gitlab,\nTente novamente mais tarde ou verifique o arquivos de configuração."
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.all
|
17
|
-
GitLab.request_get("projects/#{$GITLAB_PROJECT_ID}/users")
|
17
|
+
GitLab.request_get("projects/#{$GITLAB_PROJECT_ID}/users?per_page=100")
|
18
18
|
end
|
19
19
|
|
20
20
|
def to_s; end
|
data/lib/command.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'tty-option'
|
2
|
+
class Command
|
3
|
+
include TTY::Option
|
4
|
+
|
5
|
+
usage do
|
6
|
+
program "sflow"
|
7
|
+
|
8
|
+
desc "Run a command in a new container"
|
9
|
+
end
|
10
|
+
|
11
|
+
flag :help do
|
12
|
+
short "-h"
|
13
|
+
long "--help"
|
14
|
+
desc "Print usage"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
cmd = Command.new
|
19
|
+
cmd.parse
|
data/lib/config.rb
CHANGED
@@ -1,17 +1,35 @@
|
|
1
1
|
begin
|
2
2
|
require 'dotenv'
|
3
3
|
Dotenv.load(File.join( Dir.pwd, ".env"))
|
4
|
-
|
4
|
+
rescue LoadError
|
5
5
|
# Gem loads as it should
|
6
6
|
end
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
7
|
+
|
8
|
+
require 'tty_integration.rb'
|
9
|
+
module Config
|
10
|
+
extend TtyIntegration
|
11
|
+
def self.init
|
12
|
+
project_name = cmd.run!("git remote -v | head -n1 | awk '{print $2}' | sed -e 's,.*:\(.*/\)\?,,' -e 's/\.git$//'").out
|
13
|
+
file = "#{Dir.home}/.config/gitsflow/#{project_name.gsub("\n","")}/config.yml"
|
14
|
+
config = TTY::Config.new
|
15
|
+
config.filename = file
|
16
|
+
|
17
|
+
begin
|
18
|
+
result = config.read(file).transform_keys(&:to_sym)
|
19
|
+
$GITLAB_PROJECT_ID = result[:GITLAB_PROJECT_ID]
|
20
|
+
$GITLAB_TOKEN = result[:GITLAB_TOKEN]
|
21
|
+
$GITLAB_URL_API = result[:GITLAB_URL_API]
|
22
|
+
$GITLAB_EMAIL = result[:GITLAB_EMAIL]
|
23
|
+
$GITLAB_LISTS = result[:GITLAB_LISTS].split(',')
|
24
|
+
$GITLAB_NEXT_RELEASE_LIST = result[:GITLAB_NEXT_RELEASE_LIST]
|
25
|
+
$GIT_BRANCH_MASTER = result[:GIT_BRANCH_MASTER]
|
26
|
+
$GIT_BRANCH_DEVELOP = result[:GIT_BRANCH_DEVELOP]
|
27
|
+
$GIT_BRANCHES_STAGING= result[:GIT_BRANCHES_STAGING].split(',')
|
28
|
+
$SFLOW_TEMPLATE_RELEASE= result[:SFLOW_TEMPLATE_RELEASE]
|
29
|
+
$SFLOW_TEMPLATE_RELEASE_DATE_FORMAT= result[:SFLOW_TEMPLATE_RELEASE_DATE_FORMAT]
|
30
|
+
|
31
|
+
rescue => e
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|