gitlab-ci-lint 0.1.4 → 0.1.5
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/lib/gitlab/ci/lint.rb +53 -43
- data/lib/gitlab/ci/lint/actions.rb +21 -20
- data/lib/gitlab/ci/lint/arguments.rb +4 -4
- data/lib/gitlab/ci/lint/client.rb +2 -6
- data/lib/gitlab/ci/lint/configuration.rb +30 -28
- data/lib/gitlab/ci/lint/version.rb +1 -1
- data/values.yml +11 -10
- 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: 0ef5eb902372d22fc7c7976e8e09f5582e2f98fdec2415adf82d1b4b12fd6f73
|
4
|
+
data.tar.gz: e4380981cff13d8c9481155f18baa12d45d0f6e67a6c1e84a3d0fc4d5ff65aca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d282caeea425a3b2bc0159b905d232d3f88ffc5a1287ab985a80384f328b444bd61137bcd71eeb5c2d758a9cf887b91b4227ff90b23794841eda41b4aa9d7b62
|
7
|
+
data.tar.gz: 43384ddb7c10def3f4fd4ef9b3ff1e1da5eeb73929ad3ee6e55ae7cfa02806b7f7174c5a36cb3cc2c5d535d1e2bcd9cb2b625a12a268565a24e0b5c6df183b0e
|
data/lib/gitlab/ci/lint.rb
CHANGED
@@ -1,43 +1,53 @@
|
|
1
|
-
require "gitlab/ci/lint/yml"
|
2
|
-
require "gitlab/ci/lint/log"
|
3
|
-
require "gitlab/ci/lint/system"
|
4
|
-
require "gitlab/ci/lint/actions"
|
5
|
-
|
6
|
-
module Gitlab
|
7
|
-
module Ci
|
8
|
-
module Lint
|
9
|
-
def self.validate values, configuration, options
|
10
|
-
system = GitLab::CI::Lint::System.new
|
11
|
-
actions = GitLab::CI::Lint::Actions.new
|
12
|
-
|
13
|
-
system.file_exist?(values, "Error: You must specify the values.yml file")
|
14
|
-
|
15
|
-
values = File.absolute_path(values)
|
16
|
-
|
17
|
-
system.file_is_readable?(values, "Error: Could not find file at '#{values}'")
|
18
|
-
|
19
|
-
yml_reader = GitLab::CI::Lint::YMLReader.new(values)
|
20
|
-
content = yml_reader.get_content
|
21
|
-
|
22
|
-
gitlab = content["gitlab"]
|
23
|
-
|
24
|
-
logger = GitLab::CI::Lint::Log.instance
|
25
|
-
|
26
|
-
gitlab_endpoint = options["endpoint"] ?
|
27
|
-
options["endpoint"] : ((!gitlab["endpoint"].to_s.empty? && !gitlab["endpoint"].nil?) ?
|
28
|
-
gitlab["endpoint"] : configuration.gitlab_endpoint)
|
29
|
-
|
30
|
-
|
31
|
-
options["
|
32
|
-
gitlab["
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
1
|
+
require "gitlab/ci/lint/yml"
|
2
|
+
require "gitlab/ci/lint/log"
|
3
|
+
require "gitlab/ci/lint/system"
|
4
|
+
require "gitlab/ci/lint/actions"
|
5
|
+
|
6
|
+
module Gitlab
|
7
|
+
module Ci
|
8
|
+
module Lint
|
9
|
+
def self.validate values, configuration, options
|
10
|
+
system = GitLab::CI::Lint::System.new
|
11
|
+
actions = GitLab::CI::Lint::Actions.new
|
12
|
+
|
13
|
+
system.file_exist?(values, "Error: You must specify the values.yml file")
|
14
|
+
|
15
|
+
values = File.absolute_path(values)
|
16
|
+
|
17
|
+
system.file_is_readable?(values, "Error: Could not find file at '#{values}'")
|
18
|
+
|
19
|
+
yml_reader = GitLab::CI::Lint::YMLReader.new(values)
|
20
|
+
content = yml_reader.get_content
|
21
|
+
|
22
|
+
gitlab = content["gitlab"]
|
23
|
+
|
24
|
+
logger = GitLab::CI::Lint::Log.instance
|
25
|
+
|
26
|
+
gitlab_endpoint = options["endpoint"] ?
|
27
|
+
options["endpoint"] : ((!gitlab["endpoint"].to_s.empty? && !gitlab["endpoint"].nil?) ?
|
28
|
+
gitlab["endpoint"] : configuration.gitlab_endpoint)
|
29
|
+
|
30
|
+
gitlab_token = options["token"] ?
|
31
|
+
options["token"] : ((!gitlab["token"].to_s.empty? && !gitlab["token"].nil?) ?
|
32
|
+
gitlab["token"] : configuration.gitlab_token)
|
33
|
+
|
34
|
+
timeout = options["timeout"] ?
|
35
|
+
options["timeout"] : ((!gitlab["timeout"].to_s.empty? && !gitlab["timeout"].nil?) ?
|
36
|
+
gitlab["timeout"] : configuration.timeout)
|
37
|
+
|
38
|
+
gitlab_ci_file = options["file"] ?
|
39
|
+
options["file"] : ((!gitlab["file"].to_s.empty? && !gitlab["file"].nil?) ?
|
40
|
+
gitlab["file"] : configuration.gitlab_ci_file)
|
41
|
+
|
42
|
+
logger.info("Starting GitLab CI YML Validation...")
|
43
|
+
|
44
|
+
headers = gitlab_token ? { "Content-Type" => "application/json", "Private-Token" => gitlab_token } : { "Content-Type" => "application/json"}
|
45
|
+
|
46
|
+
actions.validate_gitlab_ci_yml(gitlab_endpoint, gitlab_ci_file, headers, timeout)
|
47
|
+
|
48
|
+
return 0
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -1,20 +1,21 @@
|
|
1
|
-
require "gitlab/ci/lint/client"
|
2
|
-
require "gitlab/ci/lint/serializer"
|
3
|
-
|
4
|
-
module GitLab
|
5
|
-
module CI
|
6
|
-
module Lint
|
7
|
-
class Actions < GitLab::CI::Lint::Client
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
1
|
+
require "gitlab/ci/lint/client"
|
2
|
+
require "gitlab/ci/lint/serializer"
|
3
|
+
|
4
|
+
module GitLab
|
5
|
+
module CI
|
6
|
+
module Lint
|
7
|
+
class Actions < GitLab::CI::Lint::Client
|
8
|
+
|
9
|
+
def validate_gitlab_ci_yml url, content, headers, timeout
|
10
|
+
result = post(url, headers, timeout, content)
|
11
|
+
message = GitLab::CI::Lint::Serializer.new(result)
|
12
|
+
if result["status"] == "valid"
|
13
|
+
message.success()
|
14
|
+
else
|
15
|
+
message.failure()
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -23,13 +23,13 @@ module GitLab
|
|
23
23
|
opts.on("-e", "--endpoint", "GitLab Endpoint") { |value| @options[:endpoint] = value }
|
24
24
|
opts.on("-t", "--token", "GitLab Token") { |value| @options[:token] = value }
|
25
25
|
opts.on("-f", "--file", "GitLab CI File") { |value| @options[:file] = value }
|
26
|
-
opts.on("-d", "--directory", "GitLab CI Directory") { |value| @options[:
|
27
|
-
opts.on("-T", "--timeout", "Request Timeout") { |value| @options[:
|
28
|
-
opts.on("-n", "--no-color", "Color Usage") { |value| @options[:
|
26
|
+
opts.on("-d", "--directory", "GitLab CI Directory") { |value| @options[:directory] = value }
|
27
|
+
opts.on("-T", "--timeout", "Request Timeout") { |value| @options[:timeout] = value }
|
28
|
+
opts.on("-n", "--no-color", "Color Usage") { |value| @options[:nocolor] = value }
|
29
29
|
opts.on("-v", "--values", "Values File") { |value| @options[:values] = value }
|
30
30
|
opts.on("-l", "--log", "Log File") { |value| @options[:log] = value }
|
31
31
|
opts.on("--verbose", "If set, print verbose output") { |value| @options[:verbose] = true }
|
32
|
-
opts.on("--version", "Show GitLab CI Lint Version") { |value| @options[:
|
32
|
+
opts.on("--version", "Show GitLab CI Lint Version") { |value| @options[:version] = version() }
|
33
33
|
end.parse!
|
34
34
|
return @options
|
35
35
|
end
|
@@ -8,15 +8,11 @@ module GitLab
|
|
8
8
|
class Client
|
9
9
|
include HTTParty
|
10
10
|
|
11
|
-
def
|
12
|
-
@headers = { "Content-Type" => "application/json", "Private-Token" => "uNNACNQdxg1iSnieM2nG" }
|
13
|
-
end
|
14
|
-
|
15
|
-
def post url, content
|
11
|
+
def post url, content, headers={ "Content-Type" => "application/json"}, timeout=10
|
16
12
|
begin
|
17
13
|
if content = GitLab::CI::Lint::YMLReader.new(content).get_json_content()
|
18
14
|
body = { content: content }.to_json
|
19
|
-
request = self.class.post(url, :body => body, :headers =>
|
15
|
+
request = self.class.post(url, :body => body, :headers => headers, :timeout => timeout)
|
20
16
|
if request.code == 200
|
21
17
|
puts "\nSuccessful request!"
|
22
18
|
return JSON.parse(request.body)
|
@@ -1,28 +1,30 @@
|
|
1
|
-
module GitLab
|
2
|
-
module CI
|
3
|
-
module Lint
|
4
|
-
class Configuration
|
5
|
-
attr_reader :gitlab_endpoint, :gitlab_token, :gitlab_ci_file,
|
6
|
-
:values, :log_file
|
7
|
-
def initialize
|
8
|
-
@gitlab_endpoint = ENV["GITLAB_ENDPOINT"]
|
9
|
-
@gitlab_token = ENV["GITLAB_TOKEN"]
|
10
|
-
@gitlab_ci_file = ENV["GITLAB_CI_FILE"]
|
11
|
-
@
|
12
|
-
@
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
"
|
19
|
-
"
|
20
|
-
"
|
21
|
-
"
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
1
|
+
module GitLab
|
2
|
+
module CI
|
3
|
+
module Lint
|
4
|
+
class Configuration
|
5
|
+
attr_reader :gitlab_endpoint, :gitlab_token, :gitlab_ci_file,
|
6
|
+
:timeout, :values, :log_file
|
7
|
+
def initialize
|
8
|
+
@gitlab_endpoint = ENV["GITLAB_ENDPOINT"]
|
9
|
+
@gitlab_token = ENV["GITLAB_TOKEN"]
|
10
|
+
@gitlab_ci_file = ENV["GITLAB_CI_FILE"]
|
11
|
+
@timeout = ENV["TIMEOUT"]
|
12
|
+
@values = ENV["VALUES"]
|
13
|
+
@log_file = ENV["LOG_FILE"]
|
14
|
+
end
|
15
|
+
|
16
|
+
def variables
|
17
|
+
return {
|
18
|
+
"gitlab_endpoint" => @gitlab_endpoint,
|
19
|
+
"gitlab_token" => @gitlab_token,
|
20
|
+
"gitlab_ci_file" => @gitlab_ci_file,
|
21
|
+
"timeout" => @timeout,
|
22
|
+
"values" => @values,
|
23
|
+
"log_file" => @log_file
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/values.yml
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
# =============================================================================
|
2
|
-
# VALUES DEFINITION
|
3
|
-
# =============================================================================
|
4
|
-
|
5
|
-
---
|
6
|
-
gitlab:
|
7
|
-
endpoint: "https://gitlab.com/api/v4/ci/lint"
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
# =============================================================================
|
2
|
+
# VALUES DEFINITION
|
3
|
+
# =============================================================================
|
4
|
+
|
5
|
+
---
|
6
|
+
gitlab:
|
7
|
+
endpoint: "https://gitlab.com/api/v4/ci/lint"
|
8
|
+
timeout: 10
|
9
|
+
file: ".gitlab-ci.yml"
|
10
|
+
log:
|
11
|
+
file: "file.log"
|