gitlab-ci-lint 0.1.1 → 0.1.2
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/.dockerignore +12 -0
- data/.gitignore +215 -60
- data/.gitlab-ci.yml +72 -0
- data/CHANGELOG.md +16 -0
- data/Dockerfile +35 -0
- data/Gemfile +15 -15
- data/Makefile +50 -0
- data/README.md +49 -1
- data/bin/gitlab_ci_lint +16 -11
- data/docker-compose.yml +45 -0
- data/docs/annotations/replace.md +128 -0
- data/gitlab.gemspec +0 -3
- data/lib/gitlab/ci/lint.rb +50 -50
- data/lib/gitlab/ci/lint/actions.rb +11 -0
- data/lib/gitlab/ci/lint/arguments.rb +69 -0
- data/lib/gitlab/ci/lint/client.rb +33 -0
- data/lib/gitlab/ci/lint/colors.rb +25 -0
- data/lib/gitlab/ci/lint/configuration.rb +27 -0
- data/lib/gitlab/ci/lint/log.rb +53 -0
- data/lib/gitlab/ci/lint/multio.rb +19 -0
- data/lib/gitlab/ci/lint/system.rb +21 -0
- data/lib/gitlab/ci/lint/version.rb +7 -7
- data/lib/gitlab/ci/lint/yml.rb +40 -0
- data/spec/gitlab/ci/lint/spec.rb +5 -5
- data/values.yml +11 -8
- metadata +14 -52
- data/.rspec +0 -3
- data/.rspec_status +0 -0
- data/file.log +0 -2
- data/lib/gitlab/ci/lint/reader/yml.rb +0 -19
- data/lib/gitlab/ci/lint/settings/arguments.rb +0 -27
- data/lib/gitlab/ci/lint/settings/colors.rb +0 -17
- data/lib/gitlab/ci/lint/settings/configuration.rb +0 -24
- data/lib/gitlab/ci/lint/settings/log.rb +0 -52
@@ -0,0 +1,33 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "json"
|
3
|
+
require_relative "./yml.rb"
|
4
|
+
|
5
|
+
module GitLab
|
6
|
+
module CI
|
7
|
+
module Lint
|
8
|
+
class Client
|
9
|
+
def get_gitlab_ci_lint url, content
|
10
|
+
begin
|
11
|
+
if url.kind_of? String
|
12
|
+
content = GitLab::CI::Lint::YMLReader.new(content).get_json_content()
|
13
|
+
if content
|
14
|
+
request = HTTParty.post(url, :body => { content: content }.to_json, :headers => { "Content-Type" => "application/json" })
|
15
|
+
if request.code == 200
|
16
|
+
return JSON.parse(request.body)
|
17
|
+
else
|
18
|
+
puts "Error - Bad Request #{request.code}"
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
else
|
22
|
+
puts "Error - No Content..."
|
23
|
+
exit
|
24
|
+
end
|
25
|
+
end
|
26
|
+
rescue => error
|
27
|
+
puts "\nError - #{error}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module GitLab
|
2
|
+
module CI
|
3
|
+
module Lint
|
4
|
+
class Colors
|
5
|
+
COLORS = {"default" => "38", "black" => "30", "red" => "31",
|
6
|
+
"green" => "32", "brown" => "33", "blue" => "34", "purple" => "35",
|
7
|
+
"cyan" => "36", "gray" => "37", "dark gray" => "1;30",
|
8
|
+
"light red" => "1;31", "light green" => "1;32", "yellow" => "1;33",
|
9
|
+
"light blue" => "1;34", "light purple" => "1;35", "light cyan" => "1;36",
|
10
|
+
"white" => "1;37"}
|
11
|
+
|
12
|
+
BACKGROUD_COLORS = {"default" => "0", "black" => "40", "red" => "41",
|
13
|
+
"green" => "42", "brown" => "43", "blue" => "44",
|
14
|
+
"purple" => "45", "cyan" => "46", "gray" => "47",
|
15
|
+
"dark gray" => "100", "light red" => "101", "light green" => "102",
|
16
|
+
"yellow" => "103", "light blue" => "104", "light purple" => "105",
|
17
|
+
"light cyan" => "106", "white" => "107"}
|
18
|
+
|
19
|
+
def self.colorize(message, color="default", backgroud_color="default")
|
20
|
+
return "\033[#{BACKGROUD_COLORS[backgroud_color]};#{COLORS[color]}m#{message}\033[0m"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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
|
+
@values = ENV["VALUES"]
|
12
|
+
@log_file = ENV["LOG_FILE"]
|
13
|
+
end
|
14
|
+
|
15
|
+
def variables
|
16
|
+
return {
|
17
|
+
"gitlab_endpoint" => @gitlab_endpoint,
|
18
|
+
"gitlab_token" => @gitlab_token,
|
19
|
+
"gitlab_ci_file" => @gitlab_ci_file,
|
20
|
+
"values" => @values,
|
21
|
+
"log_file" => @log_file
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "logger"
|
2
|
+
require "singleton"
|
3
|
+
require "gitlab/ci/lint/multio.rb"
|
4
|
+
require "gitlab/ci/lint/colors.rb"
|
5
|
+
|
6
|
+
module GitLab
|
7
|
+
module CI
|
8
|
+
module Lint
|
9
|
+
class Log < GitLab::CI::Lint::Colors
|
10
|
+
include Singleton
|
11
|
+
attr_accessor :logger
|
12
|
+
def initialize log_file="./file.log"
|
13
|
+
@logger = Logger.new GitLab::CI::Lint::MultiIO.new(STDOUT,
|
14
|
+
File.open(File.exist?(log_file) ? log_file : "./file.log", "a"))
|
15
|
+
|
16
|
+
@logger.level = Logger::INFO
|
17
|
+
|
18
|
+
@logger.formatter = proc do |severity, datetime, progname, msg|
|
19
|
+
datetime = "[#{datetime.strftime('%Y-%m-%d %H:%M:%S')}]"
|
20
|
+
case severity
|
21
|
+
when "INFO"
|
22
|
+
colorized_severity = self.class.colorize("#{severity}", "black", "green")
|
23
|
+
self.class.colorize("#{colorized_severity} - #{datetime} - #{msg}\n", "black", "green")
|
24
|
+
when "ERROR"
|
25
|
+
colorized_severity = self.class.colorize("#{severity}", "black", "red")
|
26
|
+
"#{colorized_severity} - #{datetime} - #{msg}\n"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_level level
|
32
|
+
@logger.level = level
|
33
|
+
end
|
34
|
+
|
35
|
+
def info message, color=:green
|
36
|
+
@logger.info(message)
|
37
|
+
end
|
38
|
+
|
39
|
+
def debug message, color=:green
|
40
|
+
@logger.debug(message)
|
41
|
+
end
|
42
|
+
|
43
|
+
def error message, color=:green
|
44
|
+
@logger.error(message)
|
45
|
+
end
|
46
|
+
|
47
|
+
def warn message
|
48
|
+
@logger.warn(message)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module GitLab
|
2
|
+
module CI
|
3
|
+
module Lint
|
4
|
+
class MultiIO
|
5
|
+
def initialize(*targets)
|
6
|
+
@targets = targets
|
7
|
+
end
|
8
|
+
|
9
|
+
def write(*args)
|
10
|
+
@targets.each {|target| target.write(*args)}
|
11
|
+
end
|
12
|
+
|
13
|
+
def close
|
14
|
+
@targets.each(&:close)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module GitLab
|
2
|
+
module CI
|
3
|
+
module Lint
|
4
|
+
class System
|
5
|
+
def file_exist? file, message
|
6
|
+
unless file
|
7
|
+
$stderr.puts("#{message}")
|
8
|
+
return 1
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def file_is_readable? file, message
|
13
|
+
unless File.readable?(file)
|
14
|
+
$stderr.puts("#{message}")
|
15
|
+
return 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
module Gitlab
|
2
|
-
module Ci
|
3
|
-
module Lint
|
4
|
-
VERSION = "0.1.
|
5
|
-
end
|
6
|
-
end
|
7
|
-
end
|
1
|
+
module Gitlab
|
2
|
+
module Ci
|
3
|
+
module Lint
|
4
|
+
VERSION = "0.1.2".freeze
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module GitLab
|
5
|
+
module CI
|
6
|
+
module Lint
|
7
|
+
class YMLReader
|
8
|
+
attr_reader :file
|
9
|
+
def initialize file
|
10
|
+
@file = file
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_content
|
14
|
+
begin
|
15
|
+
return YAML.load(File.read(@file))
|
16
|
+
rescue ArgumentError => error
|
17
|
+
puts "Could not parse the YAML File: #{error.message}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_json_content
|
22
|
+
content = JSON.pretty_generate(get_content())
|
23
|
+
return valid_json?(content) ? content : nil
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def valid_json? json
|
29
|
+
begin
|
30
|
+
JSON.parse(json)
|
31
|
+
return true
|
32
|
+
rescue
|
33
|
+
return false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/gitlab/ci/lint/spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
RSpec.describe Gitlab::Ci::Lint do
|
2
|
-
it "Has a version number" do
|
3
|
-
expect(Gitlab::Ci::Lint::VERSION).not_to be nil
|
4
|
-
end
|
5
|
-
end
|
1
|
+
RSpec.describe Gitlab::Ci::Lint do
|
2
|
+
it "Has a version number" do
|
3
|
+
expect(Gitlab::Ci::Lint::VERSION).not_to be nil
|
4
|
+
end
|
5
|
+
end
|
data/values.yml
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
# =============================================================================
|
2
|
-
# VALUES DEFINITION
|
3
|
-
# =============================================================================
|
4
|
-
|
5
|
-
---
|
6
|
-
gitlab:
|
7
|
-
endpoint: "
|
8
|
-
token: "
|
1
|
+
# =============================================================================
|
2
|
+
# VALUES DEFINITION
|
3
|
+
# =============================================================================
|
4
|
+
|
5
|
+
---
|
6
|
+
gitlab:
|
7
|
+
endpoint: "https://gitlab.com/api/v4/ci/lint"
|
8
|
+
token: "9q41a8mmjAs4zjxmY6sm"
|
9
|
+
file: ".gitlab-ci.yml"
|
10
|
+
log:
|
11
|
+
file: "file.log"
|
metadata
CHANGED
@@ -1,57 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab-ci-lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucca Pessoa da Silva Matos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.16'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.16'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '10.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '10.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '3.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '3.0'
|
55
13
|
- !ruby/object:Gem::Dependency
|
56
14
|
name: httparty
|
57
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,31 +73,35 @@ executables:
|
|
115
73
|
extensions: []
|
116
74
|
extra_rdoc_files: []
|
117
75
|
files:
|
76
|
+
- ".dockerignore"
|
118
77
|
- ".editorconfig"
|
119
78
|
- ".gitignore"
|
120
|
-
- ".
|
121
|
-
- ".rspec_status"
|
79
|
+
- ".gitlab-ci.yml"
|
122
80
|
- CHANGELOG.md
|
123
81
|
- Dockerfile
|
124
82
|
- Gemfile
|
125
83
|
- LICENSE
|
84
|
+
- Makefile
|
126
85
|
- README.md
|
127
86
|
- Rakefile
|
128
87
|
- bin/gitlab_ci_lint
|
129
88
|
- docker-compose.yml
|
130
89
|
- docs/annotations/docker.md
|
131
90
|
- docs/annotations/rake.md
|
91
|
+
- docs/annotations/replace.md
|
132
92
|
- docs/annotations/structure.md
|
133
|
-
- file.log
|
134
93
|
- gitlab.gemspec
|
135
94
|
- lib/gitlab/ci/lint.rb
|
95
|
+
- lib/gitlab/ci/lint/actions.rb
|
96
|
+
- lib/gitlab/ci/lint/arguments.rb
|
136
97
|
- lib/gitlab/ci/lint/client.rb
|
137
|
-
- lib/gitlab/ci/lint/
|
138
|
-
- lib/gitlab/ci/lint/
|
139
|
-
- lib/gitlab/ci/lint/
|
140
|
-
- lib/gitlab/ci/lint/
|
141
|
-
- lib/gitlab/ci/lint/
|
98
|
+
- lib/gitlab/ci/lint/colors.rb
|
99
|
+
- lib/gitlab/ci/lint/configuration.rb
|
100
|
+
- lib/gitlab/ci/lint/log.rb
|
101
|
+
- lib/gitlab/ci/lint/multio.rb
|
102
|
+
- lib/gitlab/ci/lint/system.rb
|
142
103
|
- lib/gitlab/ci/lint/version.rb
|
104
|
+
- lib/gitlab/ci/lint/yml.rb
|
143
105
|
- spec/gitlab/ci/lint/spec.rb
|
144
106
|
- spec/spec_helper.rb
|
145
107
|
- values.yml
|
data/.rspec
DELETED
data/.rspec_status
DELETED
File without changes
|
data/file.log
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require "yaml"
|
2
|
-
|
3
|
-
module Gitlab
|
4
|
-
module Ci
|
5
|
-
class ReaderYMLFile
|
6
|
-
attr_reader :file
|
7
|
-
def initialize file
|
8
|
-
@file = file
|
9
|
-
end
|
10
|
-
def get_content
|
11
|
-
begin
|
12
|
-
return eval(YAML.load_file(@file).inspect)
|
13
|
-
rescue ArgumentError => error
|
14
|
-
puts "Could not parse the YAML File: #{error.message}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require "optparse"
|
2
|
-
|
3
|
-
def program_name
|
4
|
-
return File.basename(__FILE__)
|
5
|
-
end
|
6
|
-
|
7
|
-
def help
|
8
|
-
string = """Command Line Helper to the Program - #{program_name()}
|
9
|
-
Usage Exemple: ruby example.rb [options]
|
10
|
-
Options:
|
11
|
-
-h | --helper HELPER.
|
12
|
-
-e | --endpoint GITLAB ENDPOINT.
|
13
|
-
-t | --token GITLAB PRIVATE TOKEN.\n
|
14
|
-
"""
|
15
|
-
return puts string
|
16
|
-
end
|
17
|
-
|
18
|
-
def command_line_parser
|
19
|
-
options = {}
|
20
|
-
OptionParser.new do |opts|
|
21
|
-
opts.banner = "Usage: example.rb [options]"
|
22
|
-
opts.on("-h", "--helper") { |value| help() }
|
23
|
-
opts.on("-e", "--endpoint GITLAB ENDPOINT", "GitLab Endpoint") { |value| options["endpoint"] = value }
|
24
|
-
opts.on("-t", "--token GITLAB PRIVATE TOKEN", "GitLab Private Token") { |value| options["token"] = value }
|
25
|
-
end.parse!
|
26
|
-
return options
|
27
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
class Colors
|
2
|
-
COLORS = {"default" => "38", "black" => "30", "red" => "31",
|
3
|
-
"green" => "32", "brown" => "33", "blue" => "34", "purple" => "35",
|
4
|
-
"cyan" => "36", "gray" => "37", "dark gray" => "1;30",
|
5
|
-
"light red" => "1;31", "light green" => "1;32", "yellow" => "1;33",
|
6
|
-
"light blue" => "1;34", "light purple" => "1;35", "light cyan" => "1;36",
|
7
|
-
"white" => "1;37"}
|
8
|
-
BACKGROUD_COLORS = {"default" => "0", "black" => "40", "red" => "41",
|
9
|
-
"green" => "42", "brown" => "43", "blue" => "44",
|
10
|
-
"purple" => "45", "cyan" => "46", "gray" => "47",
|
11
|
-
"dark gray" => "100", "light red" => "101", "light green" => "102",
|
12
|
-
"yellow" => "103", "light blue" => "104", "light purple" => "105",
|
13
|
-
"light cyan" => "106", "white" => "107"}
|
14
|
-
def self.colorize(message, color="default", backgroud_color="default")
|
15
|
-
return "\033[#{BACKGROUD_COLORS[backgroud_color]};#{COLORS[color]}m#{message}\033[0m"
|
16
|
-
end
|
17
|
-
end
|