semaph 0.1.0 → 0.2.0
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/.gitignore +3 -1
- data/.rubocop.yml +18 -0
- data/.semaphore/semaphore.yml +19 -0
- data/.tool-versions +1 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +35 -0
- data/Rakefile +1 -1
- data/exe/semaph +5 -0
- data/lib/semaph.rb +17 -1
- data/lib/semaph/api.rb +61 -0
- data/lib/semaph/commands/reload_command.rb +16 -0
- data/lib/semaph/commands/visit_url_command.rb +16 -0
- data/lib/semaph/formatting.rb +9 -0
- data/lib/semaph/model/job.rb +40 -0
- data/lib/semaph/model/job_collection.rb +34 -0
- data/lib/semaph/model/pipeline.rb +22 -0
- data/lib/semaph/model/pipeline_collection.rb +21 -0
- data/lib/semaph/model/project.rb +34 -0
- data/lib/semaph/model/project_collection.rb +20 -0
- data/lib/semaph/model/workflow.rb +24 -0
- data/lib/semaph/model/workflow_collection.rb +20 -0
- data/lib/semaph/shells/organisation/organisation_shell.rb +29 -0
- data/lib/semaph/shells/organisation/projects_list_command.rb +20 -0
- data/lib/semaph/shells/organisation/projects_select_command.rb +26 -0
- data/lib/semaph/shells/organisations/organisations_list_command.rb +20 -0
- data/lib/semaph/shells/organisations/organisations_select_command.rb +25 -0
- data/lib/semaph/shells/organisations/organisations_shell.rb +20 -0
- data/lib/semaph/shells/pipeline/jobs_list_command.rb +33 -0
- data/lib/semaph/shells/pipeline/pipeline_shell.rb +25 -0
- data/lib/semaph/shells/project/project_shell.rb +48 -0
- data/lib/semaph/shells/project/workflows_list_command.rb +38 -0
- data/lib/semaph/shells/project/workflows_select_command.rb +24 -0
- data/lib/semaph/shells/workflow/pipelines_list_command.rb +20 -0
- data/lib/semaph/shells/workflow/pipelines_select_command.rb +24 -0
- data/lib/semaph/shells/workflow/workflow_shell.rb +64 -0
- data/lib/semaph/version.rb +1 -1
- data/semaph.gemspec +11 -7
- metadata +92 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b22217dbedbfa234279e494e23d64af812563e6fa8d57e2e2b14f185b3fbe52c
|
4
|
+
data.tar.gz: 36c3a0944ef6408730c18b2f147f734616300023792e9e82b0c5ebc0956bab05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fdda4999337920b39947b2c2fe09ea2cf62830998f948fed2d835dd74f5436172276dace4d59f0e493f14381aae349aaa0aafaa123b5f452ab4ed6a1fba0db0
|
7
|
+
data.tar.gz: c5f969a3450d98f8a9b7a9eeb66d134856558e0376259070206ad0a8e76d4e3c38e6a12e3b27312aa272a48cc08af50288e99b443983ffc1d374d5401f82eb85
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Style/Documentation:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Style/FrozenStringLiteralComment:
|
5
|
+
EnforcedStyle: never
|
6
|
+
|
7
|
+
Style/StringLiterals:
|
8
|
+
EnforcedStyle: double_quotes
|
9
|
+
|
10
|
+
Style/TrailingCommaInArguments:
|
11
|
+
EnforcedStyleForMultiline: consistent_comma
|
12
|
+
|
13
|
+
Style/TrailingCommaInArrayLiteral:
|
14
|
+
EnforcedStyleForMultiline: consistent_comma
|
15
|
+
|
16
|
+
Style/TrailingCommaInHashLiteral:
|
17
|
+
EnforcedStyleForMultiline: consistent_comma
|
18
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
version: v1.0
|
2
|
+
name: "Main Build"
|
3
|
+
agent:
|
4
|
+
machine:
|
5
|
+
type: e1-standard-2
|
6
|
+
os_image: ubuntu1804
|
7
|
+
|
8
|
+
auto_cancel:
|
9
|
+
queued:
|
10
|
+
when: true
|
11
|
+
|
12
|
+
blocks:
|
13
|
+
- name: "Build"
|
14
|
+
task:
|
15
|
+
jobs:
|
16
|
+
- name: Build
|
17
|
+
commands:
|
18
|
+
- checkout
|
19
|
+
- echo "done"
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.7.1
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
semaph (0.1.0)
|
5
|
+
faraday
|
6
|
+
rainbow
|
7
|
+
shell_shock
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
coderay (1.1.2)
|
13
|
+
faraday (1.0.1)
|
14
|
+
multipart-post (>= 1.2, < 3)
|
15
|
+
method_source (1.0.0)
|
16
|
+
minitest (5.14.1)
|
17
|
+
multipart-post (2.1.1)
|
18
|
+
pry (0.13.1)
|
19
|
+
coderay (~> 1.1)
|
20
|
+
method_source (~> 1.0)
|
21
|
+
rainbow (3.0.0)
|
22
|
+
rake (12.3.3)
|
23
|
+
shell_shock (0.0.5)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
minitest (~> 5.0)
|
30
|
+
pry
|
31
|
+
rake (~> 12.0)
|
32
|
+
semaph!
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
2.1.4
|
data/Rakefile
CHANGED
data/exe/semaph
ADDED
data/lib/semaph.rb
CHANGED
@@ -1,6 +1,22 @@
|
|
1
1
|
require "semaph/version"
|
2
|
+
require "semaph/shells/organisations/organisations_shell"
|
3
|
+
require "semaph/shells/organisation/organisation_shell"
|
4
|
+
require "yaml"
|
2
5
|
|
3
6
|
module Semaph
|
4
7
|
class Error < StandardError; end
|
5
|
-
|
8
|
+
|
9
|
+
def self.console
|
10
|
+
yaml_path = File.join(File.expand_path("~"), ".sem.yaml")
|
11
|
+
raise "Please install the sem tool and authenticate to semaphoreci.com" unless File.exist?(yaml_path)
|
12
|
+
|
13
|
+
sem_config = YAML.load_file(yaml_path)
|
14
|
+
contexts = sem_config["contexts"]
|
15
|
+
|
16
|
+
if contexts.count == 1
|
17
|
+
Shells::Organisation::OrganisationShell.new(contexts.values.first).push
|
18
|
+
else
|
19
|
+
Shells::Organisations::OrganisationsShell.new(contexts).push
|
20
|
+
end
|
21
|
+
end
|
6
22
|
end
|
data/lib/semaph/api.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module Semaph
|
5
|
+
# Refer to https://docs.semaphoreci.com/reference/api-v1alpha/
|
6
|
+
class Api
|
7
|
+
attr_reader :host
|
8
|
+
|
9
|
+
def initialize(token, host)
|
10
|
+
@token = token
|
11
|
+
@host = host
|
12
|
+
@base = "https://#{host}/api/v1alpha"
|
13
|
+
end
|
14
|
+
|
15
|
+
def projects
|
16
|
+
get "projects"
|
17
|
+
end
|
18
|
+
|
19
|
+
def workflows(project_id)
|
20
|
+
get "plumber-workflows", { project_id: project_id }
|
21
|
+
end
|
22
|
+
|
23
|
+
def pipelines(options)
|
24
|
+
get "pipelines", options
|
25
|
+
end
|
26
|
+
|
27
|
+
def pipeline(id)
|
28
|
+
get "pipelines/#{id}", { detailed: true }
|
29
|
+
end
|
30
|
+
|
31
|
+
def job(id)
|
32
|
+
get "jobs/#{id}"
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def get(path, params = {})
|
38
|
+
url = "#{@base}/#{path}"
|
39
|
+
puts url if ENV["SEMAPH_DEBUG"]
|
40
|
+
response = Faraday.get(url, params, headers)
|
41
|
+
check_response(response, url).tap do |hash|
|
42
|
+
pp hash if ENV["SEMAPH_DEBUG"]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def headers
|
47
|
+
{
|
48
|
+
"Authorization" => "Token #{@token}",
|
49
|
+
"Content-Type" => "application/json",
|
50
|
+
"Accept" => "application/json",
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def check_response(response, url)
|
55
|
+
return JSON.parse(response.body) if response.status == 200
|
56
|
+
|
57
|
+
puts "http response #{response.status} received for #{url}:\n#{response.body}"
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Semaph
|
2
|
+
module Model
|
3
|
+
class Job
|
4
|
+
attr_reader(
|
5
|
+
:pipeline,
|
6
|
+
:id,
|
7
|
+
:name,
|
8
|
+
:status,
|
9
|
+
:result,
|
10
|
+
:block_name,
|
11
|
+
:block_state,
|
12
|
+
:block_result,
|
13
|
+
)
|
14
|
+
|
15
|
+
def initialize(pipeline, raw_block, raw_job)
|
16
|
+
@pipeline = pipeline
|
17
|
+
@raw_block = raw_block
|
18
|
+
@raw_job = raw_job
|
19
|
+
assign_from_job(raw_job)
|
20
|
+
assign_from_block(raw_block)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def assign_from_job(raw)
|
26
|
+
@id = raw["job_id"]
|
27
|
+
@status = raw["status"]
|
28
|
+
@name = raw["name"]
|
29
|
+
@result = raw["result"]
|
30
|
+
end
|
31
|
+
|
32
|
+
def assign_from_block(raw)
|
33
|
+
@block_name = raw["name"]
|
34
|
+
@block_state = raw["state"]
|
35
|
+
@block_result = raw["result"]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "semaph/model/job"
|
2
|
+
|
3
|
+
module Semaph
|
4
|
+
module Model
|
5
|
+
class JobCollection
|
6
|
+
attr_reader :all
|
7
|
+
|
8
|
+
def initialize(pipeline)
|
9
|
+
@pipeline = pipeline
|
10
|
+
reload
|
11
|
+
end
|
12
|
+
|
13
|
+
def reload
|
14
|
+
workflow = @pipeline.workflow
|
15
|
+
project = workflow.project
|
16
|
+
@all = build_jobs(project.client.pipeline(@pipeline.id))
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def build_jobs(content)
|
22
|
+
result = []
|
23
|
+
blocks = content.delete("blocks")
|
24
|
+
blocks.each do |block|
|
25
|
+
jobs = block.delete("jobs").sort_by { |job| job["index"] }
|
26
|
+
jobs.each do |job|
|
27
|
+
result << Job.new(@pipeline, block, job)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
result
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "semaph/model/job_collection"
|
2
|
+
|
3
|
+
module Semaph
|
4
|
+
module Model
|
5
|
+
class Pipeline
|
6
|
+
attr_reader :workflow, :raw, :id, :yaml, :state, :result
|
7
|
+
|
8
|
+
def initialize(workflow, raw)
|
9
|
+
@workflow = workflow
|
10
|
+
@raw = raw
|
11
|
+
@id = raw["ppl_id"]
|
12
|
+
@yaml = raw["yaml_file_name"]
|
13
|
+
@state = raw["state"]
|
14
|
+
@result = raw["result"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def job_collection
|
18
|
+
JobCollection.new(self)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "semaph/model/pipeline"
|
2
|
+
|
3
|
+
module Semaph
|
4
|
+
module Model
|
5
|
+
class PipelineCollection
|
6
|
+
attr_reader :all
|
7
|
+
|
8
|
+
def initialize(workflow)
|
9
|
+
@workflow = workflow
|
10
|
+
reload
|
11
|
+
end
|
12
|
+
|
13
|
+
def reload
|
14
|
+
project = @workflow.project
|
15
|
+
@all = project.client.pipelines({ wf_id: @workflow.id }).map do |content|
|
16
|
+
Pipeline.new @workflow, content
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "semaph/model/workflow_collection"
|
2
|
+
|
3
|
+
module Semaph
|
4
|
+
module Model
|
5
|
+
class Project
|
6
|
+
GITHUB_REGGEXP = %r{git@github.com:(.*)/(.*).git}.freeze
|
7
|
+
|
8
|
+
attr_reader :client, :raw, :id, :name
|
9
|
+
|
10
|
+
def initialize(client, raw)
|
11
|
+
@client = client
|
12
|
+
@raw = raw
|
13
|
+
@id = raw["metadata"]["id"]
|
14
|
+
@name = raw["metadata"]["name"]
|
15
|
+
repo = raw["spec"]["repository"]["url"]
|
16
|
+
match = GITHUB_REGGEXP.match(repo)
|
17
|
+
return unless match
|
18
|
+
|
19
|
+
@repo_owner = match[1]
|
20
|
+
@repo_name = match[2]
|
21
|
+
end
|
22
|
+
|
23
|
+
def github_url
|
24
|
+
return nil unless @repo_owner && @repo_name
|
25
|
+
|
26
|
+
"https://github.com/#{@repo_owner}/#{@repo_name}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def workflow_collection
|
30
|
+
WorkflowCollection.new(self)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "semaph/model/project"
|
2
|
+
|
3
|
+
module Semaph
|
4
|
+
module Model
|
5
|
+
class ProjectCollection
|
6
|
+
attr_reader :all
|
7
|
+
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
reload
|
11
|
+
end
|
12
|
+
|
13
|
+
def reload
|
14
|
+
@all = @client.projects.map do |content|
|
15
|
+
Project.new @client, content
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "semaph/model/pipeline_collection"
|
2
|
+
|
3
|
+
module Semaph
|
4
|
+
module Model
|
5
|
+
class Workflow
|
6
|
+
attr_reader :project, :raw, :id, :sha, :branch, :branch_id, :created_at
|
7
|
+
|
8
|
+
def initialize(project, raw)
|
9
|
+
@project = project
|
10
|
+
@raw = raw
|
11
|
+
@id = raw["wf_id"]
|
12
|
+
@sha = raw["commit_sha"]
|
13
|
+
@created_at = Time.at(raw["created_at"]["seconds"].to_i)
|
14
|
+
@branch = raw["branch_name"]
|
15
|
+
@branch_id = raw["branch_id"]
|
16
|
+
# @summary = `git log -n 1 --format="%h %an %ci %s" #{sha}`
|
17
|
+
end
|
18
|
+
|
19
|
+
def pipeline_collection
|
20
|
+
PipelineCollection.new(self)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "semaph/model/workflow"
|
2
|
+
|
3
|
+
module Semaph
|
4
|
+
module Model
|
5
|
+
class WorkflowCollection
|
6
|
+
attr_reader :all
|
7
|
+
|
8
|
+
def initialize(project)
|
9
|
+
@project = project
|
10
|
+
reload
|
11
|
+
end
|
12
|
+
|
13
|
+
def reload
|
14
|
+
@all = @project.client.workflows(@project.id).map do |content|
|
15
|
+
Workflow.new @project, content
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "semaph/api"
|
2
|
+
require "semaph/commands/reload_command"
|
3
|
+
require "semaph/model/project_collection"
|
4
|
+
require "semaph/shells/organisation/projects_list_command"
|
5
|
+
require "semaph/shells/organisation/projects_select_command"
|
6
|
+
require "shell_shock/context"
|
7
|
+
|
8
|
+
module Semaph
|
9
|
+
module Shells
|
10
|
+
module Organisation
|
11
|
+
class OrganisationShell
|
12
|
+
include ShellShock::Context
|
13
|
+
|
14
|
+
def initialize(organisation)
|
15
|
+
host = organisation["host"]
|
16
|
+
@prompt = "🏗 #{host} > "
|
17
|
+
client = ::Semaph::Api.new(organisation["auth"]["token"], host)
|
18
|
+
project_collection = ::Semaph::Model::ProjectCollection.new(client)
|
19
|
+
add_command ProjectsListCommand.new(project_collection), "list-projects"
|
20
|
+
add_command ProjectsSelectCommand.new(project_collection), "select-project"
|
21
|
+
add_command(
|
22
|
+
::Semaph::Commands::ReloadCommand.new(project_collection, "reload projects"),
|
23
|
+
"reload-projects",
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Semaph
|
2
|
+
module Shells
|
3
|
+
module Organisation
|
4
|
+
class ProjectsListCommand
|
5
|
+
attr_reader :usage, :help
|
6
|
+
|
7
|
+
def initialize(project_collection)
|
8
|
+
@project_collection = project_collection
|
9
|
+
@help = "list available projects"
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute(_whatever)
|
13
|
+
@project_collection.all.each do |project|
|
14
|
+
puts project.name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "semaph/shells/project/project_shell"
|
2
|
+
|
3
|
+
module Semaph
|
4
|
+
module Shells
|
5
|
+
module Organisation
|
6
|
+
class ProjectsSelectCommand
|
7
|
+
attr_reader :usage, :help
|
8
|
+
|
9
|
+
def initialize(project_collection)
|
10
|
+
@project_collection = project_collection
|
11
|
+
@usage = "<project>"
|
12
|
+
@help = "choose project"
|
13
|
+
end
|
14
|
+
|
15
|
+
def completion(text)
|
16
|
+
@project_collection.all.map(&:name).grep(/^#{text}/).sort
|
17
|
+
end
|
18
|
+
|
19
|
+
def execute(name)
|
20
|
+
selected_project = @project_collection.all.find { |project| project.name == name }
|
21
|
+
::Semaph::Shells::Project::ProjectShell.new(selected_project).push
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Semaph
|
2
|
+
module Shells
|
3
|
+
module Organisations
|
4
|
+
class OrganisationsListCommand
|
5
|
+
attr_reader :usage, :help
|
6
|
+
|
7
|
+
def initialize(organisations)
|
8
|
+
@organisations = organisations
|
9
|
+
@help = "list available organisations"
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute(_whatever)
|
13
|
+
@organisations.each_key do |name|
|
14
|
+
puts "#{name} (#{@organisations[name]['host']})"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "semaph/shells/organisation/organisation_shell"
|
2
|
+
|
3
|
+
module Semaph
|
4
|
+
module Shells
|
5
|
+
module Organisations
|
6
|
+
class OrganisationsSelectCommand
|
7
|
+
attr_reader :usage, :help
|
8
|
+
|
9
|
+
def initialize(organisations)
|
10
|
+
@organisations = organisations
|
11
|
+
@usage = "<organisation>"
|
12
|
+
@help = "choose organisation"
|
13
|
+
end
|
14
|
+
|
15
|
+
def completion(text)
|
16
|
+
@organisations.keys.grep(/^#{text}/).sort
|
17
|
+
end
|
18
|
+
|
19
|
+
def execute(name)
|
20
|
+
::Semaph::Shells::Organisation::OrganisationShell.new(@organisations[name]).push
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "semaph/shells/organisations/organisations_list_command"
|
2
|
+
require "semaph/shells/organisations/organisations_select_command"
|
3
|
+
require "shell_shock/context"
|
4
|
+
|
5
|
+
module Semaph
|
6
|
+
module Shells
|
7
|
+
module Organisations
|
8
|
+
class OrganisationsShell
|
9
|
+
include ShellShock::Context
|
10
|
+
|
11
|
+
def initialize(organisations)
|
12
|
+
@organisations = organisations
|
13
|
+
@prompt = "🏗 > "
|
14
|
+
add_command OrganisationsListCommand.new(organisations), "list-organisations"
|
15
|
+
add_command OrganisationsSelectCommand.new(organisations), "select-organisation"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Semaph
|
2
|
+
module Shells
|
3
|
+
module Pipeline
|
4
|
+
class JobsListCommand
|
5
|
+
attr_reader :usage, :help
|
6
|
+
|
7
|
+
def initialize(job_collection)
|
8
|
+
@job_collection = job_collection
|
9
|
+
@help = "list jobs"
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute(_whatever)
|
13
|
+
@job_collection.all.each do |job|
|
14
|
+
puts description(job)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def description(job)
|
21
|
+
[
|
22
|
+
job.block_name,
|
23
|
+
job.block_state,
|
24
|
+
job.block_result,
|
25
|
+
job.name,
|
26
|
+
job.status,
|
27
|
+
job.result,
|
28
|
+
].join(" ")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "semaph/shells/pipeline/jobs_list_command"
|
2
|
+
require "shell_shock/context"
|
3
|
+
|
4
|
+
module Semaph
|
5
|
+
module Shells
|
6
|
+
module Pipeline
|
7
|
+
class PipelineShell
|
8
|
+
include ShellShock::Context
|
9
|
+
|
10
|
+
def initialize(pipeline)
|
11
|
+
@pipeline = pipeline
|
12
|
+
workflow = pipeline.workflow
|
13
|
+
project = workflow.project
|
14
|
+
@prompt = "🏗 #{project.client.host} #{project.name} #{workflow.id} #{pipeline.yaml} > "
|
15
|
+
job_collection = pipeline.job_collection
|
16
|
+
add_command(
|
17
|
+
::Semaph::Commands::ReloadCommand.new(job_collection, "reload jobs"),
|
18
|
+
"reload-jobs",
|
19
|
+
)
|
20
|
+
add_command JobsListCommand.new(job_collection), "list-jobs"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "semaph/commands/visit_url_command"
|
2
|
+
require "semaph/commands/reload_command"
|
3
|
+
require "semaph/shells/project/workflows_list_command"
|
4
|
+
require "semaph/shells/project/workflows_select_command"
|
5
|
+
require "shell_shock/context"
|
6
|
+
|
7
|
+
module Semaph
|
8
|
+
module Shells
|
9
|
+
module Project
|
10
|
+
class ProjectShell
|
11
|
+
include ShellShock::Context
|
12
|
+
|
13
|
+
def initialize(project)
|
14
|
+
@prompt = "🏗 #{project.client.host} #{project.name} > "
|
15
|
+
workflow_collection = project.workflow_collection
|
16
|
+
add_github_command(project)
|
17
|
+
add_command(
|
18
|
+
::Semaph::Commands::ReloadCommand.new(workflow_collection, "reload workflows"),
|
19
|
+
"reload-workflows",
|
20
|
+
)
|
21
|
+
add_command(
|
22
|
+
::Semaph::Commands::VisitUrlCommand.new(
|
23
|
+
"https://#{project.client.host}/projects/#{project.name}",
|
24
|
+
"browse to project",
|
25
|
+
),
|
26
|
+
"open-project",
|
27
|
+
)
|
28
|
+
add_command WorkflowsListCommand.new(workflow_collection), "list-workflows"
|
29
|
+
add_command WorkflowsSelectCommand.new(workflow_collection), "select-workflow"
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def add_github_command(project)
|
35
|
+
return unless project.github_url
|
36
|
+
|
37
|
+
add_command(
|
38
|
+
::Semaph::Commands::VisitUrlCommand.new(
|
39
|
+
project.github_url,
|
40
|
+
"browse to github project",
|
41
|
+
),
|
42
|
+
"open-github",
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Semaph
|
2
|
+
module Shells
|
3
|
+
module Project
|
4
|
+
class WorkflowsListCommand
|
5
|
+
TIME_FORMAT = "%Y-%m-%d %H:%M:%S".freeze
|
6
|
+
|
7
|
+
attr_reader :usage, :help
|
8
|
+
|
9
|
+
def initialize(workflow_collection)
|
10
|
+
@workflow_collection = workflow_collection
|
11
|
+
@usage = "<branch>"
|
12
|
+
@help = "list available workflows"
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute(branch)
|
16
|
+
@workflow_collection.all.each_with_index do |workflow, index|
|
17
|
+
next unless workflow.branch.include?(branch)
|
18
|
+
|
19
|
+
puts description(index, workflow)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def description(index, workflow)
|
26
|
+
[
|
27
|
+
index + 1,
|
28
|
+
workflow.created_at.strftime(TIME_FORMAT),
|
29
|
+
"SHA",
|
30
|
+
workflow.sha,
|
31
|
+
"on branch",
|
32
|
+
workflow.branch,
|
33
|
+
].join(" ")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "semaph/shells/workflow/workflow_shell"
|
2
|
+
|
3
|
+
module Semaph
|
4
|
+
module Shells
|
5
|
+
module Project
|
6
|
+
class WorkflowsSelectCommand
|
7
|
+
attr_reader :usage, :help
|
8
|
+
|
9
|
+
def initialize(workflow_collection)
|
10
|
+
@workflow_collection = workflow_collection
|
11
|
+
@usage = "<workflow index>"
|
12
|
+
@help = "choose workflow by index"
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute(index_string)
|
16
|
+
index = index_string.to_i - 1
|
17
|
+
::Semaph::Shells::Workflow::WorkflowShell.new(
|
18
|
+
@workflow_collection.all[index],
|
19
|
+
).push
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Semaph
|
2
|
+
module Shells
|
3
|
+
module Workflow
|
4
|
+
class PipelinesListCommand
|
5
|
+
attr_reader :usage, :help
|
6
|
+
|
7
|
+
def initialize(pipeline_collection)
|
8
|
+
@pipeline_collection = pipeline_collection
|
9
|
+
@help = "list pipelines"
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute(_whatever)
|
13
|
+
@pipeline_collection.all.each_with_index do |pipeline, index|
|
14
|
+
puts "#{index + 1} #{pipeline.yaml} #{pipeline.state} #{pipeline.result}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "semaph/shells/pipeline/pipeline_shell"
|
2
|
+
|
3
|
+
module Semaph
|
4
|
+
module Shells
|
5
|
+
module Workflow
|
6
|
+
class PipelinesSelectCommand
|
7
|
+
attr_reader :usage, :help
|
8
|
+
|
9
|
+
def initialize(pipeline_collection)
|
10
|
+
@pipeline_collection = pipeline_collection
|
11
|
+
@usage = "<pipeline index>"
|
12
|
+
@help = "choose pipeline by index"
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute(index_string)
|
16
|
+
index = index_string.to_i - 1
|
17
|
+
::Semaph::Shells::Pipeline::PipelineShell.new(
|
18
|
+
@pipeline_collection.all[index],
|
19
|
+
).push
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "semaph/commands/visit_url_command"
|
2
|
+
require "semaph/commands/reload_command"
|
3
|
+
require "semaph/shells/workflow/pipelines_list_command"
|
4
|
+
require "semaph/shells/workflow/pipelines_select_command"
|
5
|
+
require "shell_shock/context"
|
6
|
+
|
7
|
+
module Semaph
|
8
|
+
module Shells
|
9
|
+
module Workflow
|
10
|
+
class WorkflowShell
|
11
|
+
include ShellShock::Context
|
12
|
+
|
13
|
+
def initialize(workflow)
|
14
|
+
@workflow = workflow
|
15
|
+
project = @workflow.project
|
16
|
+
@prompt = "🏗 #{project.client.host} #{project.name} #{workflow.id} > "
|
17
|
+
pipeline_collection = workflow.pipeline_collection
|
18
|
+
add_command PipelinesListCommand.new(pipeline_collection), "list-pipelines"
|
19
|
+
add_command PipelinesSelectCommand.new(pipeline_collection), "select-pipeline"
|
20
|
+
add_command(
|
21
|
+
::Semaph::Commands::VisitUrlCommand.new(
|
22
|
+
"https://#{project.client.host}/workflows/#{workflow.id}",
|
23
|
+
"browse to workflow",
|
24
|
+
),
|
25
|
+
"open-workflow",
|
26
|
+
)
|
27
|
+
add_command(
|
28
|
+
::Semaph::Commands::VisitUrlCommand.new(
|
29
|
+
"https://#{project.client.host}/branches/#{workflow.branch_id}",
|
30
|
+
"browse to branch in semaphore",
|
31
|
+
),
|
32
|
+
"open-branch",
|
33
|
+
)
|
34
|
+
add_github_commands(workflow)
|
35
|
+
add_command(
|
36
|
+
::Semaph::Commands::ReloadCommand.new(pipeline_collection, "reload pipelines"),
|
37
|
+
"reload-pipelines",
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def add_github_commands(workflow)
|
44
|
+
return unless workflow.project.github_url
|
45
|
+
|
46
|
+
add_command(
|
47
|
+
::Semaph::Commands::VisitUrlCommand.new(
|
48
|
+
"#{workflow.project.github_url}/tree/#{workflow.branch}",
|
49
|
+
"browse to the branch in github",
|
50
|
+
),
|
51
|
+
"open-github-branch",
|
52
|
+
)
|
53
|
+
add_command(
|
54
|
+
::Semaph::Commands::VisitUrlCommand.new(
|
55
|
+
"#{workflow.project.github_url}/commit/#{workflow.sha}",
|
56
|
+
"browse to the commit in github",
|
57
|
+
),
|
58
|
+
"open-github-commit",
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/semaph/version.rb
CHANGED
data/semaph.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "lib/semaph/version"
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "semaph"
|
@@ -6,8 +6,8 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.authors = ["Mark Ryall"]
|
7
7
|
spec.email = ["mark@ryall.name"]
|
8
8
|
|
9
|
-
spec.summary =
|
10
|
-
spec.description =
|
9
|
+
spec.summary = "client for semaphore 2"
|
10
|
+
spec.description = "api client and shell for api"
|
11
11
|
spec.homepage = "http://github.com/markryall/semaph"
|
12
12
|
spec.license = "MIT"
|
13
13
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
@@ -16,12 +16,16 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.metadata["source_code_uri"] = spec.homepage
|
17
17
|
spec.metadata["changelog_uri"] = spec.homepage
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
23
21
|
end
|
24
22
|
spec.bindir = "exe"
|
25
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
24
|
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "faraday"
|
27
|
+
spec.add_dependency "rainbow"
|
28
|
+
spec.add_dependency "shell_shock"
|
29
|
+
|
30
|
+
spec.add_development_dependency "pry"
|
27
31
|
end
|
metadata
CHANGED
@@ -1,32 +1,120 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semaph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Ryall
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
12
|
-
dependencies:
|
11
|
+
date: 2020-05-30 00:00:00.000000000 Z
|
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: rainbow
|
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'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: shell_shock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
13
69
|
description: api client and shell for api
|
14
70
|
email:
|
15
71
|
- mark@ryall.name
|
16
|
-
executables:
|
72
|
+
executables:
|
73
|
+
- semaph
|
17
74
|
extensions: []
|
18
75
|
extra_rdoc_files: []
|
19
76
|
files:
|
20
77
|
- ".gitignore"
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- ".semaphore/semaphore.yml"
|
80
|
+
- ".tool-versions"
|
21
81
|
- ".travis.yml"
|
22
82
|
- CODE_OF_CONDUCT.md
|
23
83
|
- Gemfile
|
84
|
+
- Gemfile.lock
|
24
85
|
- LICENSE.txt
|
25
86
|
- README.md
|
26
87
|
- Rakefile
|
27
88
|
- bin/console
|
28
89
|
- bin/setup
|
90
|
+
- exe/semaph
|
29
91
|
- lib/semaph.rb
|
92
|
+
- lib/semaph/api.rb
|
93
|
+
- lib/semaph/commands/reload_command.rb
|
94
|
+
- lib/semaph/commands/visit_url_command.rb
|
95
|
+
- lib/semaph/formatting.rb
|
96
|
+
- lib/semaph/model/job.rb
|
97
|
+
- lib/semaph/model/job_collection.rb
|
98
|
+
- lib/semaph/model/pipeline.rb
|
99
|
+
- lib/semaph/model/pipeline_collection.rb
|
100
|
+
- lib/semaph/model/project.rb
|
101
|
+
- lib/semaph/model/project_collection.rb
|
102
|
+
- lib/semaph/model/workflow.rb
|
103
|
+
- lib/semaph/model/workflow_collection.rb
|
104
|
+
- lib/semaph/shells/organisation/organisation_shell.rb
|
105
|
+
- lib/semaph/shells/organisation/projects_list_command.rb
|
106
|
+
- lib/semaph/shells/organisation/projects_select_command.rb
|
107
|
+
- lib/semaph/shells/organisations/organisations_list_command.rb
|
108
|
+
- lib/semaph/shells/organisations/organisations_select_command.rb
|
109
|
+
- lib/semaph/shells/organisations/organisations_shell.rb
|
110
|
+
- lib/semaph/shells/pipeline/jobs_list_command.rb
|
111
|
+
- lib/semaph/shells/pipeline/pipeline_shell.rb
|
112
|
+
- lib/semaph/shells/project/project_shell.rb
|
113
|
+
- lib/semaph/shells/project/workflows_list_command.rb
|
114
|
+
- lib/semaph/shells/project/workflows_select_command.rb
|
115
|
+
- lib/semaph/shells/workflow/pipelines_list_command.rb
|
116
|
+
- lib/semaph/shells/workflow/pipelines_select_command.rb
|
117
|
+
- lib/semaph/shells/workflow/workflow_shell.rb
|
30
118
|
- lib/semaph/version.rb
|
31
119
|
- semaph.gemspec
|
32
120
|
homepage: http://github.com/markryall/semaph
|