lex-jenkins 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a93e6c69dd6b08de53ae6388909689144d27c32686406af79072371ea4f14d99
4
+ data.tar.gz: 7508f8b943dad5b207bdde53b7009b1c7eeece7e58981c9592eae94fa58aa348
5
+ SHA512:
6
+ metadata.gz: 9f0b5b592fddc986dcc3ac7dfc22542dd4d904d78c47aee2be5aa6239ea8a006dade15d90cafc4b1e95bdf8b01928dc923233e2e9f82239e25df91b42955ee5e
7
+ data.tar.gz: 8369df66bd389598ad1aafca4d51dfbe7fa3f92753c184afd965a4504c431a2e6604659ea846a5e71cd652a5d7024d8fb8bf961e6c2e30599f2234d3bf14bacf
@@ -0,0 +1,16 @@
1
+ name: CI
2
+ on:
3
+ push:
4
+ branches: [origin]
5
+ pull_request:
6
+
7
+ jobs:
8
+ ci:
9
+ uses: LegionIO/.github/.github/workflows/ci.yml@main
10
+
11
+ release:
12
+ needs: ci
13
+ if: github.event_name == 'push' && github.ref == 'refs/heads/origin'
14
+ uses: LegionIO/.github/.github/workflows/release.yml@main
15
+ secrets:
16
+ rubygems-api-key: ${{ secrets.RUBYGEMS_API_KEY }}
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,53 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.4
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Layout/LineLength:
7
+ Max: 160
8
+
9
+ Layout/SpaceAroundEqualsInParameterDefault:
10
+ EnforcedStyle: space
11
+
12
+ Layout/HashAlignment:
13
+ EnforcedHashRocketStyle: table
14
+ EnforcedColonStyle: table
15
+
16
+ Metrics/MethodLength:
17
+ Max: 50
18
+
19
+ Metrics/ClassLength:
20
+ Max: 1500
21
+
22
+ Metrics/ModuleLength:
23
+ Max: 1500
24
+
25
+ Metrics/BlockLength:
26
+ Max: 40
27
+ Exclude:
28
+ - 'spec/**/*'
29
+
30
+ Metrics/ParameterLists:
31
+ Max: 8
32
+
33
+ Metrics/AbcSize:
34
+ Max: 60
35
+
36
+ Metrics/CyclomaticComplexity:
37
+ Max: 15
38
+
39
+ Metrics/PerceivedComplexity:
40
+ Max: 17
41
+
42
+ Style/Documentation:
43
+ Enabled: false
44
+
45
+ Style/SymbolArray:
46
+ Enabled: true
47
+
48
+ Style/FrozenStringLiteralComment:
49
+ Enabled: true
50
+ EnforcedStyle: always
51
+
52
+ Naming/FileName:
53
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2026-03-21
4
+
5
+ ### Added
6
+ - Initial release
7
+ - `Helpers::Client` with Faraday Basic auth connection builder
8
+ - `Runners::Jobs`: list_jobs, get_job, create_job, delete_job, enable_job, disable_job
9
+ - `Runners::Builds`: get_build, get_last_build, trigger_build, get_build_log
10
+ - `Runners::Nodes`: list_nodes, get_node
11
+ - Standalone `Client` class with all runner modules included
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ gem 'bundler', '>= 2'
8
+ gem 'rake'
9
+ gem 'rspec'
10
+ gem 'rubocop'
11
+ gem 'rubocop-rspec'
12
+ gem 'webmock'
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # lex-jenkins
2
+
3
+ LegionIO extension that connects to Jenkins CI/CD via the Jenkins REST API.
4
+
5
+ ## Installation
6
+
7
+ Add to your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'lex-jenkins'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Standalone
16
+
17
+ ```ruby
18
+ require 'legion/extensions/jenkins'
19
+
20
+ client = Legion::Extensions::Jenkins::Client.new(
21
+ url: 'http://jenkins.example.com',
22
+ username: 'admin',
23
+ token: 'your-api-token'
24
+ )
25
+
26
+ # List all jobs
27
+ client.list_jobs
28
+
29
+ # Trigger a build with parameters
30
+ client.trigger_build(name: 'my-pipeline', parameters: { BRANCH: 'main' })
31
+
32
+ # Get last build result
33
+ client.get_last_build(name: 'my-pipeline')
34
+ ```
35
+
36
+ ## Runners
37
+
38
+ ### Jobs
39
+ - `list_jobs` - List all jobs
40
+ - `get_job(name:)` - Get job details
41
+ - `create_job(name:, xml_config:)` - Create a job from XML config
42
+ - `delete_job(name:)` - Delete a job
43
+ - `enable_job(name:)` - Enable a job
44
+ - `disable_job(name:)` - Disable a job
45
+
46
+ ### Builds
47
+ - `get_build(name:, build_number:)` - Get a specific build
48
+ - `get_last_build(name:)` - Get the last build
49
+ - `trigger_build(name:, parameters: {})` - Trigger a build
50
+ - `get_build_log(name:, build_number:)` - Get console output
51
+
52
+ ### Nodes
53
+ - `list_nodes` - List all nodes
54
+ - `get_node(name:)` - Get node details
55
+
56
+ ## License
57
+
58
+ MIT
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/legion/extensions/jenkins/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'lex-jenkins'
7
+ spec.version = Legion::Extensions::Jenkins::VERSION
8
+ spec.authors = ['Esity']
9
+ spec.email = ['matthewdiverson@gmail.com']
10
+
11
+ spec.summary = 'LEX Jenkins'
12
+ spec.description = 'Connects LegionIO to Jenkins CI/CD'
13
+ spec.homepage = 'https://github.com/LegionIO/lex-jenkins'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.4'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/LegionIO/lex-jenkins'
19
+ spec.metadata['documentation_uri'] = 'https://github.com/LegionIO/lex-jenkins'
20
+ spec.metadata['changelog_uri'] = 'https://github.com/LegionIO/lex-jenkins'
21
+ spec.metadata['bug_tracker_uri'] = 'https://github.com/LegionIO/lex-jenkins/issues'
22
+ spec.metadata['rubygems_mfa_required'] = 'true'
23
+
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_dependency 'faraday', '~> 2.0'
30
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/jenkins/helpers/client'
4
+ require 'legion/extensions/jenkins/runners/jobs'
5
+ require 'legion/extensions/jenkins/runners/builds'
6
+ require 'legion/extensions/jenkins/runners/nodes'
7
+
8
+ module Legion
9
+ module Extensions
10
+ module Jenkins
11
+ class Client
12
+ include Helpers::Client
13
+ include Runners::Jobs
14
+ include Runners::Builds
15
+ include Runners::Nodes
16
+
17
+ attr_reader :opts
18
+
19
+ def initialize(url: 'http://localhost:8080', username: nil, token: nil, **extra)
20
+ @opts = { url: url, username: username, token: token, **extra }.compact
21
+ end
22
+
23
+ def connection(**override)
24
+ super(**@opts.merge(override))
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Jenkins
8
+ module Helpers
9
+ module Client
10
+ def connection(url: 'http://localhost:8080', username: nil, token: nil, **_opts)
11
+ Faraday.new(url: url) do |conn|
12
+ conn.request :json
13
+ conn.response :json, content_type: /\bjson$/
14
+ conn.headers['Accept'] = 'application/json'
15
+ conn.request :authorization, :basic, username, token if username && token
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/jenkins/helpers/client'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Jenkins
8
+ module Runners
9
+ module Builds
10
+ include Legion::Extensions::Jenkins::Helpers::Client
11
+
12
+ def get_build(name:, build_number:, **)
13
+ response = connection(**).get("/job/#{name}/#{build_number}/api/json")
14
+ { result: response.body }
15
+ end
16
+
17
+ def get_last_build(name:, **)
18
+ response = connection(**).get("/job/#{name}/lastBuild/api/json")
19
+ { result: response.body }
20
+ end
21
+
22
+ def trigger_build(name:, parameters: {}, **)
23
+ response = if parameters.empty?
24
+ connection(**).post("/job/#{name}/build")
25
+ else
26
+ connection(**).post("/job/#{name}/buildWithParameters", parameters)
27
+ end
28
+ { result: [201, 200].include?(response.status) }
29
+ end
30
+
31
+ def get_build_log(name:, build_number:, **)
32
+ response = connection(**).get("/job/#{name}/#{build_number}/consoleText")
33
+ { result: response.body }
34
+ end
35
+
36
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
37
+ Legion::Extensions::Helpers.const_defined?(:Lex)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/jenkins/helpers/client'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Jenkins
8
+ module Runners
9
+ module Jobs
10
+ include Legion::Extensions::Jenkins::Helpers::Client
11
+
12
+ def list_jobs(**)
13
+ response = connection(**).get('/api/json', tree: 'jobs[name,url,color]')
14
+ { result: response.body }
15
+ end
16
+
17
+ def get_job(name:, **)
18
+ response = connection(**).get("/job/#{name}/api/json")
19
+ { result: response.body }
20
+ end
21
+
22
+ def create_job(name:, xml_config:, **)
23
+ conn = connection(**)
24
+ conn.headers['Content-Type'] = 'application/xml'
25
+ response = conn.post("/createItem?name=#{name}", xml_config)
26
+ { result: response.status == 200 }
27
+ end
28
+
29
+ def delete_job(name:, **)
30
+ response = connection(**).post("/job/#{name}/doDelete")
31
+ { result: [302, 200].include?(response.status) }
32
+ end
33
+
34
+ def enable_job(name:, **)
35
+ response = connection(**).post("/job/#{name}/enable")
36
+ { result: [302, 200].include?(response.status) }
37
+ end
38
+
39
+ def disable_job(name:, **)
40
+ response = connection(**).post("/job/#{name}/disable")
41
+ { result: [302, 200].include?(response.status) }
42
+ end
43
+
44
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
45
+ Legion::Extensions::Helpers.const_defined?(:Lex)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/jenkins/helpers/client'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Jenkins
8
+ module Runners
9
+ module Nodes
10
+ include Legion::Extensions::Jenkins::Helpers::Client
11
+
12
+ def list_nodes(**)
13
+ response = connection(**).get('/computer/api/json', tree: 'computer[displayName,offline,numExecutors]')
14
+ { result: response.body }
15
+ end
16
+
17
+ def get_node(name:, **)
18
+ response = connection(**).get("/computer/#{name}/api/json")
19
+ { result: response.body }
20
+ end
21
+
22
+ include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
23
+ Legion::Extensions::Helpers.const_defined?(:Lex)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Jenkins
6
+ VERSION = '0.1.1'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/jenkins/version'
4
+ require 'legion/extensions/jenkins/helpers/client'
5
+ require 'legion/extensions/jenkins/runners/jobs'
6
+ require 'legion/extensions/jenkins/runners/builds'
7
+ require 'legion/extensions/jenkins/runners/nodes'
8
+ require 'legion/extensions/jenkins/client'
9
+
10
+ module Legion
11
+ module Extensions
12
+ module Jenkins
13
+ extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
14
+ end
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lex-jenkins
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Esity
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ description: Connects LegionIO to Jenkins CI/CD
27
+ email:
28
+ - matthewdiverson@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".github/workflows/ci.yml"
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - CHANGELOG.md
38
+ - Gemfile
39
+ - README.md
40
+ - lex-jenkins.gemspec
41
+ - lib/legion/extensions/jenkins.rb
42
+ - lib/legion/extensions/jenkins/client.rb
43
+ - lib/legion/extensions/jenkins/helpers/client.rb
44
+ - lib/legion/extensions/jenkins/runners/builds.rb
45
+ - lib/legion/extensions/jenkins/runners/jobs.rb
46
+ - lib/legion/extensions/jenkins/runners/nodes.rb
47
+ - lib/legion/extensions/jenkins/version.rb
48
+ homepage: https://github.com/LegionIO/lex-jenkins
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: https://github.com/LegionIO/lex-jenkins
53
+ source_code_uri: https://github.com/LegionIO/lex-jenkins
54
+ documentation_uri: https://github.com/LegionIO/lex-jenkins
55
+ changelog_uri: https://github.com/LegionIO/lex-jenkins
56
+ bug_tracker_uri: https://github.com/LegionIO/lex-jenkins/issues
57
+ rubygems_mfa_required: 'true'
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '3.4'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.6.9
73
+ specification_version: 4
74
+ summary: LEX Jenkins
75
+ test_files: []