terraspace_ci_github 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/terraspace_ci_github/pr.rb +14 -2
- data/lib/terraspace_ci_github/vars.rb +22 -2
- data/lib/terraspace_ci_github/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd1bc2f04e34e6cb7e0cc58e2d87f4dd393b28043f383fffe6f7e6e842da38fb
|
4
|
+
data.tar.gz: f53bedc944ff116d042877f47e1f3768a1549a6ab0c97956c7ad38e40a13f996
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31ffa1b4da8351b72a49c6fc0f95afd6679f1a0b936538ce0509a1fe97bea21737ee09a51da821a8f8e232b73d279f8340de3b8237b5df30d9f77be0a5094b63
|
7
|
+
data.tar.gz: 4b693db74e2d5aa7dab995039cde20909e7ad3f8b35a49585f58fb49b1e8bb48cb894ee3245bde054b2077cb3f4898eea271f64554d4a0e2c919ee05869d4922
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *tries* to adhere to [Semantic Versioning](http://semver.org/).
|
5
5
|
|
6
|
+
## [0.1.3] - 2022-06-15
|
7
|
+
- [#2](https://github.com/boltops-tools/terraspace_ci_github/pull/2) get pr url from push commit message
|
8
|
+
|
6
9
|
## [0.1.2] - 2022-06-15
|
7
10
|
- [#1](https://github.com/boltops-tools/terraspace_ci_github/pull/1) add faraday-retry gem to get rid of warning
|
8
11
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module TerraspaceCiGithub
|
2
2
|
class Pr < Base
|
3
3
|
def comment(url)
|
4
|
-
return unless
|
4
|
+
return unless pull_request_available?
|
5
5
|
return unless github_token?
|
6
6
|
|
7
7
|
repo = ENV['GITHUB_REPOSITORY'] # org/repo
|
8
|
-
number =
|
8
|
+
number = pr_number
|
9
9
|
marker = "<!-- terraspace marker -->"
|
10
10
|
body = marker + "\n"
|
11
11
|
body << "Terraspace Cloud Url #{url}"
|
@@ -25,5 +25,17 @@ module TerraspaceCiGithub
|
|
25
25
|
rescue Octokit::Unauthorized => e
|
26
26
|
puts "WARN: #{e.message}. Unable to create pull request comment. Please double check your github token"
|
27
27
|
end
|
28
|
+
|
29
|
+
def pull_request_available?
|
30
|
+
!!pr_number
|
31
|
+
end
|
32
|
+
|
33
|
+
def pr_number
|
34
|
+
if ENV['GITHUB_EVENT_NAME'] == 'pull_request'
|
35
|
+
ENV['GITHUB_REF_NAME'].split('/').first # IE: 2/merge
|
36
|
+
else
|
37
|
+
Vars.new.pr_number
|
38
|
+
end
|
39
|
+
end
|
28
40
|
end
|
29
41
|
end
|
@@ -12,7 +12,7 @@ module TerraspaceCiGithub
|
|
12
12
|
build_url: build_url,
|
13
13
|
# additional properties
|
14
14
|
build_type: build_type, # required IE: pull_request or push
|
15
|
-
pr_number:
|
15
|
+
pr_number: pr_number, # set when build_type=pull_request
|
16
16
|
sha: sha,
|
17
17
|
# additional properties
|
18
18
|
commit_message: commit_message,
|
@@ -25,8 +25,27 @@ module TerraspaceCiGithub
|
|
25
25
|
ENV['GITHUB_SERVER_URL'] || 'https://github.com'
|
26
26
|
end
|
27
27
|
|
28
|
+
COMMIT_PATTERN = %r{Merge pull request #(\d) from (.*)}
|
28
29
|
def pr_url
|
29
|
-
|
30
|
+
if pr['number']
|
31
|
+
"#{host}/#{full_repo}/pull/#{pr['number']}"
|
32
|
+
elsif md = commit_message.match(COMMIT_PATTERN)
|
33
|
+
# git push commit has commit with PR info
|
34
|
+
# IE: Merge pull request #4 from tongueroo/feature
|
35
|
+
number = md[1]
|
36
|
+
org_branch = md[2]
|
37
|
+
org = org_branch.split('/').first
|
38
|
+
repo = ENV['GITHUB_REPOSITORY'].split('/').last # IE: tongueroo/infra-ci
|
39
|
+
"#{host}/#{org}/#{repo}/pull/#{number}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def pr_number
|
44
|
+
if pr['number']
|
45
|
+
pr['number']
|
46
|
+
elsif md = commit_message.match(COMMIT_PATTERN)
|
47
|
+
md[1] # number
|
48
|
+
end
|
30
49
|
end
|
31
50
|
|
32
51
|
def build_url
|
@@ -46,6 +65,7 @@ module TerraspaceCiGithub
|
|
46
65
|
rescue Octokit::Unauthorized => e
|
47
66
|
puts "WARN: #{e.message}. Error getting commit message. Please double check your github token"
|
48
67
|
end
|
68
|
+
memoize :commit_message
|
49
69
|
|
50
70
|
def full_repo
|
51
71
|
ENV['GITHUB_REPOSITORY']
|