ci_toolkit 1.0.19 → 1.1.1
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/Gemfile.lock +5 -1
- data/lib/ci_toolkit/bitrise_client.rb +69 -0
- data/lib/ci_toolkit/bitrise_env.rb +9 -2
- data/lib/ci_toolkit/github_pr.rb +8 -8
- data/lib/ci_toolkit/pr_messenger.rb +6 -1
- data/lib/ci_toolkit/pr_messenger_text.rb +5 -1
- data/lib/ci_toolkit/version.rb +1 -1
- data/lib/ci_toolkit.rb +1 -0
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a0fec524e468ec5a3ae2b94076c67927b9b7d113d182331c89dc7e852969436
|
4
|
+
data.tar.gz: 0c128f21987de61c07c5283a71709c35df383bb23dd4bf697669c3c14f672e04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e39c811e40d5b330c39338b6fac6560c32809ab2ea2c2a420e9ff51b36651acf0338e3fc3dcbfb59ad90b9226478072859b7f1b11979904cee257c2ac548cd4
|
7
|
+
data.tar.gz: bb637004d4a9043eda7695285c959e445a69542bacb67f8eec41417bee706ac768191b0475133264a4289b689e5ad0644df7d8201d32efacafedc5fe0911f477
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ci_toolkit (1.
|
4
|
+
ci_toolkit (1.1.1)
|
5
|
+
faraday
|
6
|
+
faraday_middleware
|
5
7
|
jwt
|
6
8
|
octokit
|
7
9
|
openssl
|
@@ -34,6 +36,8 @@ GEM
|
|
34
36
|
faraday-net_http_persistent (1.2.0)
|
35
37
|
faraday-patron (1.0.0)
|
36
38
|
faraday-rack (1.0.0)
|
39
|
+
faraday_middleware (1.1.0)
|
40
|
+
faraday (~> 1.0)
|
37
41
|
json (2.5.1)
|
38
42
|
jwt (2.2.3)
|
39
43
|
multipart-post (2.1.1)
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "faraday_middleware"
|
4
|
+
require "faraday"
|
5
|
+
|
6
|
+
module CiToolkit
|
7
|
+
# client to use with the Bitrise API
|
8
|
+
class BitriseClient
|
9
|
+
HOST = "https://api.bitrise.io"
|
10
|
+
API_VERSION = "v0.1"
|
11
|
+
attr_reader :connection
|
12
|
+
|
13
|
+
def initialize(token = ENV["BITRISE_TOKEN"], app_slug = ENV["BITRISE_APP_SLUG"], faraday = nil)
|
14
|
+
@token = token
|
15
|
+
@app_slug = app_slug
|
16
|
+
@connection = faraday
|
17
|
+
configure_connection
|
18
|
+
end
|
19
|
+
|
20
|
+
def configure_connection
|
21
|
+
return unless @connection.nil?
|
22
|
+
|
23
|
+
@connection = Faraday.new(
|
24
|
+
url: base_url,
|
25
|
+
headers: { "Content-Type" => "application/json", "Authorization" => @token }
|
26
|
+
)
|
27
|
+
@connection.use Faraday::Request::UrlEncoded
|
28
|
+
@connection.use Faraday::Request::Retry
|
29
|
+
@connection.use FaradayMiddleware::ParseJson
|
30
|
+
@connection.use FaradayMiddleware::EncodeJson
|
31
|
+
@connection.use FaradayMiddleware::FollowRedirects
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_pull_request_build(pull_request, branch, commit, workflow)
|
35
|
+
@connection&.post("/apps/#{@app_slug}/builds", {
|
36
|
+
hook_info: { type: "bitrise" },
|
37
|
+
build_params: {
|
38
|
+
branch: branch,
|
39
|
+
branch_dest: "develop",
|
40
|
+
pull_request_id: pull_request,
|
41
|
+
workflow_id: workflow,
|
42
|
+
commit_hash: commit
|
43
|
+
}
|
44
|
+
})
|
45
|
+
end
|
46
|
+
|
47
|
+
def abort_pull_request_builds(pull_request, branch, commit)
|
48
|
+
find_pull_request_builds(pull_request, branch, commit).each do |build|
|
49
|
+
@connection&.post("/apps/#{@app_slug}/builds/#{build[:slug]}/abort", {
|
50
|
+
abort_reason: "Aborting due to other build failed for pull request #{pull_request}"
|
51
|
+
})
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def find_pull_request_builds(pull_request, branch, commit)
|
56
|
+
builds = @connection&.get("/apps/#{@app_slug}/builds", {
|
57
|
+
branch: branch,
|
58
|
+
pull_request_id: pull_request.to_i,
|
59
|
+
status: 0 # status: 0 == not finished
|
60
|
+
})
|
61
|
+
builds&.select! { |build| build[:commit_hash] == commit }
|
62
|
+
builds || []
|
63
|
+
end
|
64
|
+
|
65
|
+
def base_url
|
66
|
+
"#{HOST}/#{API_VERSION}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -2,11 +2,13 @@
|
|
2
2
|
|
3
3
|
module CiToolkit
|
4
4
|
# Bitrise constants
|
5
|
+
# noinspection RubyTooManyInstanceVariablesInspection
|
5
6
|
class BitriseEnv
|
6
7
|
attr_reader :build_number, :build_url,
|
7
8
|
:pull_request_number,
|
8
9
|
:app_url,
|
9
|
-
:git_branch
|
10
|
+
:git_branch,
|
11
|
+
:app_slug
|
10
12
|
|
11
13
|
def initialize(options = {
|
12
14
|
build_number: ENV["BITRISE_BUILD_NUMBER"],
|
@@ -16,7 +18,10 @@ module CiToolkit
|
|
16
18
|
repository_owner: ENV["BITRISEIO_GIT_REPOSITORY_OWNER"] || "crvshlab",
|
17
19
|
repository_slug: ENV["BITRISEIO_GIT_REPOSITORY_SLUG"],
|
18
20
|
app_url: ENV["BITRISE_APP_URL"],
|
19
|
-
|
21
|
+
app_slug: ENV["BITRISE_APP_SLUG"],
|
22
|
+
git_branch: ENV["BITRISE_GIT_BRANCH"],
|
23
|
+
git_commit: ENV["BITRISE_GIT_COMMIT"],
|
24
|
+
api_token: ENV["BITRISE_TOKEN"]
|
20
25
|
})
|
21
26
|
@build_number = options[:build_number]
|
22
27
|
@build_url = options[:build_url]
|
@@ -25,7 +30,9 @@ module CiToolkit
|
|
25
30
|
@repository_owner = options[:repository_owner]
|
26
31
|
@repository_slug = options[:repository_slug]
|
27
32
|
@app_url = options[:app_url]
|
33
|
+
@app_slug = options[:app_slug]
|
28
34
|
@git_branch = options[:git_branch]
|
35
|
+
@git_commit = options[:git_commit]
|
29
36
|
end
|
30
37
|
|
31
38
|
def build_from_pr?
|
data/lib/ci_toolkit/github_pr.rb
CHANGED
@@ -19,7 +19,7 @@ module CiToolkit
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def title
|
22
|
-
client.pull_request(@repo_slug, @pr_number).[](:title)
|
22
|
+
client.pull_request(@repo_slug, @pr_number).[](:title) || ""
|
23
23
|
end
|
24
24
|
|
25
25
|
def number
|
@@ -39,21 +39,21 @@ module CiToolkit
|
|
39
39
|
client.add_comment(@repo_slug, @pr_number, text[0...65_500]) # github comment character limit is 65536
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
43
|
-
|
44
|
-
delete_comment(comment[:id]) unless comment.nil?
|
42
|
+
def delete_comments_including_text(text)
|
43
|
+
comments = find_comments_including_text(text)
|
44
|
+
comments.each { |comment| delete_comment(comment[:id]) unless comment.nil? }
|
45
45
|
end
|
46
46
|
|
47
47
|
def delete_comment(comment_id)
|
48
48
|
client.delete_comment(@repo_slug, comment_id)
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
52
|
-
|
51
|
+
def find_comments_including_text(text)
|
52
|
+
comments = []
|
53
53
|
client.issue_comments(@repo_slug, @pr_number).map do |item|
|
54
|
-
|
54
|
+
comments << item if item[:body]&.include? text
|
55
55
|
end
|
56
|
-
|
56
|
+
comments
|
57
57
|
end
|
58
58
|
|
59
59
|
def labels
|
@@ -17,9 +17,14 @@ module CiToolkit
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def send_ci_failed(reason)
|
20
|
+
delete_ci_failed
|
20
21
|
send(@messenger_text.for_build_failure(reason))
|
21
22
|
end
|
22
23
|
|
24
|
+
def delete_ci_failed
|
25
|
+
delete(@messenger_text.build_failure_title)
|
26
|
+
end
|
27
|
+
|
23
28
|
def send_duplicate_files_report(finder)
|
24
29
|
delete_duplicate_files_report
|
25
30
|
report = @messenger_text.create_duplicate_files_report(finder)
|
@@ -72,7 +77,7 @@ module CiToolkit
|
|
72
77
|
def delete(message)
|
73
78
|
return unless @is_connected
|
74
79
|
|
75
|
-
@github_pr.
|
80
|
+
@github_pr.delete_comments_including_text(message)
|
76
81
|
end
|
77
82
|
end
|
78
83
|
end
|
@@ -18,7 +18,7 @@ module CiToolkit
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def for_build_failure(reason)
|
21
|
-
"
|
21
|
+
"#{build_failure_title}️\n#{body(reason.to_s)}"
|
22
22
|
end
|
23
23
|
|
24
24
|
def for_duplicated_files_report(report)
|
@@ -29,6 +29,10 @@ module CiToolkit
|
|
29
29
|
"#{lint_report_title}\n#{body(report)}"
|
30
30
|
end
|
31
31
|
|
32
|
+
def build_failure_title
|
33
|
+
"#### Build failed ⛔"
|
34
|
+
end
|
35
|
+
|
32
36
|
def duplicated_files_title
|
33
37
|
warning_with_message("There are duplicated files found")
|
34
38
|
end
|
data/lib/ci_toolkit/version.rb
CHANGED
data/lib/ci_toolkit.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ci_toolkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gero Keller
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: jwt
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -171,6 +199,7 @@ files:
|
|
171
199
|
- bin/setup
|
172
200
|
- duplicate_files_whitelist.txt
|
173
201
|
- lib/ci_toolkit.rb
|
202
|
+
- lib/ci_toolkit/bitrise_client.rb
|
174
203
|
- lib/ci_toolkit/bitrise_env.rb
|
175
204
|
- lib/ci_toolkit/build.rb
|
176
205
|
- lib/ci_toolkit/duplicate_files_finder.rb
|