Skip to content

Commit 553213a

Browse files
improve release notifications
1 parent 4b0d806 commit 553213a

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

lib/tasks/hook.rake

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def open_json(url)
1818
end
1919
end
2020

21-
def last_deploy_commit
21+
def last_deploy_sha
2222
if LAST_DEPLOY_COMMIT_OVERRIDE
2323
return LAST_DEPLOY_COMMIT_OVERRIDE
2424
end
@@ -29,22 +29,46 @@ def last_deploy_commit
2929
(data[deploy_index] || {}).fetch("sha", nil)
3030
end
3131

32-
def commits_since_last_deploy
33-
last_sha_deployed = last_deploy_commit()
34-
deploy_commit_found = false
35-
commits = []
36-
open_json(COMMITS_URL_API + "?per_page=100").map do |commit|
37-
if commit.fetch("sha") == last_sha_deployed
38-
deploy_commit_found = true
39-
break
40-
end
41-
commits.push([commit["commit"]["message"].gsub("\n", " "), commit["sha"]])
32+
def branch
33+
ENVIRONMENT.include?("production") ? "main" : "staging"
34+
end
35+
36+
def first_branch_sha
37+
open_json(COMMITS_URL_API + "?per_page=1&sha=#{branch}")[0].fetch("sha")
38+
end
39+
40+
def commits_since(sha)
41+
compare_url = "#{COMPARE_URL_API}#{sha}...#{COMMIT_SHA}"
42+
open_json(compare_url)["commits"]
43+
end
44+
45+
def commit_list(commits)
46+
commits.map { |commit|
47+
[commit["commit"]["message"].gsub("\n", " "), commit["sha"]]
48+
}
49+
end
50+
51+
def compare_link(sha)
52+
web_compare_url = "#{COMPARE_URL_WEB}#{sha}...#{COMMIT_SHA}"
53+
"<#{web_compare_url}|compare>"
54+
end
55+
56+
def commits_and_compare_link
57+
commits = commits_since(last_deploy_sha)
58+
compare = compare_link(last_deploy_sha)
59+
if commits.nil?
60+
commits = commits_since(first_branch_sha)
61+
compare = compare_link(first_branch_sha)
4262
end
43-
if !deploy_commit_found
44-
commits = [commits.first]
45-
commits.push(["[Last deploy commit not found. Most recent commit below.]", "0000000"])
63+
if commits.nil?
64+
commits = []
65+
compare = ""
4666
end
47-
commits
67+
return {commits: commit_list(commits), compare: compare}
68+
end
69+
70+
def block_data
71+
@block_data ||= commits_and_compare_link
4872
end
4973

5074
def intro_block(start_text, environment)
@@ -53,14 +77,13 @@ def intro_block(start_text, environment)
5377
if !DESCRIPTION.nil?
5478
output += "#{DESCRIPTION}\n\n"
5579
end
56-
web_compare_url = "#{COMPARE_URL_WEB}#{last_deploy_commit}...#{COMMIT_SHA}"
57-
output += "<#{web_compare_url}|compare>"
80+
output += block_data[:compare]
5881
output
5982
end
6083

6184
def commit_blocks(environment)
6285
outputs = []
63-
commits_since_last_deploy.reverse.each_slice(50) do |commits|
86+
block_data[:commits].reverse.each_slice(50) do |commits|
6487
output = ""
6588
commits.map do |commit|
6689
output += "\n + #{commit[0]} | ##{commit[1][0..5]}"

0 commit comments

Comments
 (0)