mr_bump 0.0.8 → 0.0.10
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 +8 -8
- data/bin/mr_bump +6 -0
- data/lib/mr_bump/git_config.rb +47 -0
- data/lib/mr_bump/slack.rb +22 -63
- data/lib/mr_bump.rb +3 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDljMWFkOGIzNmMxZDViNWNmODNiZTdmMjYxNzg2OWJjYmE0NGNiNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZGFiZTIwNzI4Njk2YjFhMzA3OTkwNzY4YzI2ZmRlMjdjMjM4NjZlYw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjM5NjZjZjRjODcyNjRkMjg4ZGYxN2E3MDgyOTk0YTM0YTQxNmY2ZWU1MTc0
|
10
|
+
MjZmM2RiNWU1ZDdkMDllYWQyM2UxZjg3ZGJmM2UyYTg0ZTMxOTU2N2FlOGM5
|
11
|
+
ZTJhNTY1OTg0MzFmYmJmMTJkMGE5MjViNTBhOTQ5MDhlZjkxMWY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODUxNjNlN2UyMmYzMjAzZjgyMjk0ZThhNDEyYzk3ZjI1ZTUwZWE1NDU0ZTIy
|
14
|
+
MzY3ZGUzZGJiNmViYzQ5ZGZjOGE3NzllYmM3ZjM1NmQ1MjBkMDEwNDBjNzJm
|
15
|
+
NGMyYjViYmViNjQ1NWYwNWE2ZDQ0ZGM2ZDZkOWQyMTQ0NDlmZTA=
|
data/bin/mr_bump
CHANGED
@@ -10,6 +10,12 @@ unless release || master
|
|
10
10
|
exit 1
|
11
11
|
end
|
12
12
|
|
13
|
+
unless master || MrBump.current_branch.to_s == "release/#{MrBump.current_uat_major}"
|
14
|
+
puts "On release branch '#{MrBump.current_branch}'. " \
|
15
|
+
"Expected release branch 'release/#{MrBump.current_uat_major}'"
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
|
13
19
|
unless system('git remote update > /dev/null 2>&1')
|
14
20
|
puts 'Failed to update remotes. (Connectivity problems?)'
|
15
21
|
exit 1
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module MrBump
|
2
|
+
# This class gathers configuration infromation from git
|
3
|
+
class GitConfig
|
4
|
+
attr_reader :user, :username, :repo_url, :repo_name, :orgin
|
5
|
+
GITHUB_URL_REGEX = Regexp.new(
|
6
|
+
'(https?://((?<user>[\w_\-\d]+)@)?|git@)(?<domain>github.com)[:/](?<path>[\w_\-\d]+)/' \
|
7
|
+
'(?<repo_name>[\w_\-\d\.]+?)(\.git)?$'
|
8
|
+
).freeze
|
9
|
+
|
10
|
+
def initialize(origin, repo_name, repo_url, username, user)
|
11
|
+
@origin = origin
|
12
|
+
@repo_name = repo_name
|
13
|
+
@repo_url = repo_url
|
14
|
+
@username = username
|
15
|
+
@user = user || `git config user.name`
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.from_origin(origin, user = nil)
|
19
|
+
match = GITHUB_URL_REGEX.match(origin)
|
20
|
+
raise ArgumentError,
|
21
|
+
"Couldn't parse needed information from remote url '#{git_url}'" unless match
|
22
|
+
GitConfig.new(
|
23
|
+
origin,
|
24
|
+
match['repo_name'],
|
25
|
+
"https://#{match['domain']}/#{match['path']}/#{match['repo_name']}/",
|
26
|
+
match['user'],
|
27
|
+
user
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.from_current_path
|
32
|
+
from_origin(`git remote get-url origin`.strip)
|
33
|
+
end
|
34
|
+
|
35
|
+
def user_icon
|
36
|
+
'https://avatars.githubusercontent.com/' + username if username
|
37
|
+
end
|
38
|
+
|
39
|
+
def user_link
|
40
|
+
'https://github.com/' + username if username
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_sha(pattern)
|
44
|
+
`git log --grep=#{pattern} --merges --format=format:%H`.split("\n").first
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/mr_bump/slack.rb
CHANGED
@@ -2,19 +2,13 @@ require 'slack-notifier'
|
|
2
2
|
module MrBump
|
3
3
|
# This class uses a slack webhook to push notifications to slack
|
4
4
|
class Slack
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@
|
9
|
-
@
|
10
|
-
|
11
|
-
|
12
|
-
else
|
13
|
-
@jira_url = nil
|
14
|
-
end
|
15
|
-
if opts['icon']
|
16
|
-
@icon = (opts['icon'].is_a? Array) ? opts['icon'].sample : opts['icon']
|
17
|
-
end
|
5
|
+
def initialize(git_config, opts)
|
6
|
+
raise ArgumentError, 'No Slack webhook found.' unless opts['webhook_url']
|
7
|
+
@webhook = opts['webhook_url']
|
8
|
+
@username = opts['username'] || 'Mr Bump'
|
9
|
+
@jira_url = opts['jira_url']
|
10
|
+
@icon = (opts['icon'].is_a? Array) ? opts['icon'].sample : opts['icon']
|
11
|
+
@git = git_config
|
18
12
|
end
|
19
13
|
|
20
14
|
def bump(version, changes)
|
@@ -28,83 +22,48 @@ module MrBump
|
|
28
22
|
@notifier ||= ::Slack::Notifier.new(@webhook, username: @username)
|
29
23
|
end
|
30
24
|
|
31
|
-
def user
|
32
|
-
`git config user.name`.gsub(/\n/, '')
|
33
|
-
end
|
34
|
-
|
35
|
-
def git_url
|
36
|
-
@git_url ||= `git remote get-url origin`
|
37
|
-
end
|
38
|
-
|
39
|
-
def git_user
|
40
|
-
git_url[/[^@]+/].partition('//').last
|
41
|
-
end
|
42
|
-
|
43
|
-
def git_icon
|
44
|
-
'https://avatars.githubusercontent.com/' + git_user
|
45
|
-
end
|
46
|
-
|
47
|
-
def git_link
|
48
|
-
'https://github.com/' + git_user
|
49
|
-
end
|
50
|
-
|
51
|
-
def repo_name
|
52
|
-
`git config --get remote.origin.url`[/[\w\.]+(?=\.git$)/]
|
53
|
-
end
|
54
|
-
|
55
25
|
def jira_ids(changes)
|
56
|
-
changes.split('* ').map { |i| i.split(' - ',3)[1]}.compact
|
26
|
+
changes.split('* ').map { |i| i.split(' - ', 3)[1] }.compact
|
57
27
|
end
|
58
28
|
|
59
29
|
def jira_urls(changes)
|
60
30
|
jira_ids(changes).map do |ticket|
|
61
|
-
if ticket!= 'UNKNOWN'
|
62
|
-
|
31
|
+
if ticket != 'UNKNOWN'
|
32
|
+
"<#{@jira_url}/browse/#{ticket}|Jira link - #{ticket}>\n"
|
63
33
|
end
|
64
34
|
end.join
|
65
35
|
end
|
66
36
|
|
67
37
|
def jira_field(changes)
|
68
38
|
if @jira_url && !@jira_url.empty?
|
69
|
-
{value: jira_urls(changes), short: true, unfurl_links: false}
|
39
|
+
{ value: jira_urls(changes), short: true, unfurl_links: false }
|
70
40
|
end
|
71
41
|
end
|
72
42
|
|
73
|
-
def get_sha(id)
|
74
|
-
`git log --grep=#{id} --merges --format=format:%H`.split("\n").first
|
75
|
-
end
|
76
|
-
|
77
|
-
def git_repo_url
|
78
|
-
'https://' + git_url.partition('@').last.gsub(".git\n", '')
|
79
|
-
end
|
80
|
-
|
81
43
|
def git_shas(changes)
|
82
44
|
jira_ids(changes).map do |ticket|
|
83
|
-
if ticket!= 'UNKNOWN' &&
|
84
|
-
|
45
|
+
if ticket != 'UNKNOWN' && !@git.get_sha(ticket).nil?
|
46
|
+
"<#{@git.repo_url}/commit/#{@git.get_sha(ticket)}|Git merge link - #{ticket}>\n"
|
85
47
|
end
|
86
48
|
end.join
|
87
49
|
end
|
88
50
|
|
89
|
-
|
90
51
|
def attatchment(version, changes)
|
91
52
|
{
|
92
53
|
fallback: changes,
|
93
54
|
color: "#009de4",
|
94
|
-
author_name: user,
|
95
|
-
author_icon:
|
96
|
-
author_link:
|
55
|
+
author_name: @git.user,
|
56
|
+
author_icon: @git.user_icon,
|
57
|
+
author_link: @git.user_link,
|
97
58
|
fields: [
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
59
|
+
{ title: 'Version', value: version, short: true },
|
60
|
+
{ title: 'Repository', value: @git.repo_name, short: true },
|
61
|
+
{ title: 'Change Log', value: changes, short: false },
|
62
|
+
jira_field(changes),
|
63
|
+
{ value: git_shas(changes), short: true }
|
64
|
+
],
|
104
65
|
mrkdwn_in: ["text", "title", "fallback", "fields"]
|
105
66
|
}
|
106
67
|
end
|
107
|
-
|
108
|
-
|
109
68
|
end
|
110
69
|
end
|
data/lib/mr_bump.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'mr_bump/version'
|
2
2
|
require 'mr_bump/slack'
|
3
3
|
require 'mr_bump/config'
|
4
|
+
require 'mr_bump/git_config'
|
5
|
+
|
4
6
|
|
5
7
|
module MrBump
|
6
8
|
def self.current_branch
|
@@ -90,7 +92,7 @@ module MrBump
|
|
90
92
|
|
91
93
|
def self.slack_notifier(version, changelog)
|
92
94
|
if config_file.key? 'slack'
|
93
|
-
MrBump::Slack.new(config_file["slack"]).bump(version, changelog)
|
95
|
+
MrBump::Slack.new(MrBump::GitConfig.from_current_path, config_file["slack"]).bump(version, changelog)
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mr_bump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Fitzgerald
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- bin/mr_bump
|
36
36
|
- lib/mr_bump.rb
|
37
37
|
- lib/mr_bump/config.rb
|
38
|
+
- lib/mr_bump/git_config.rb
|
38
39
|
- lib/mr_bump/slack.rb
|
39
40
|
- lib/mr_bump/version.rb
|
40
41
|
homepage: https://github.com/xulaus/mr_bump
|