semaph 0.7.0 → 0.8.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/.semaph +9 -0
- data/Gemfile.lock +1 -1
- data/lib/semaph.rb +43 -8
- data/lib/semaph/model/job_collection.rb +19 -3
- data/lib/semaph/shells/organisations/organisations_list_command.rb +2 -2
- data/lib/semaph/shells/organisations/organisations_select_command.rb +4 -2
- data/lib/semaph/shells/pipeline/job_log_command.rb +11 -11
- data/lib/semaph/shells/pipeline/jobs_poll_command.rb +23 -6
- data/lib/semaph/shells/project/project_shell.rb +2 -0
- data/lib/semaph/shells/project/save_command.rb +26 -0
- data/lib/semaph/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c17a30876e3fab18baefc8d5055a1c079f58711f03f70fbd9bc29ad45fc2733e
|
4
|
+
data.tar.gz: a30b3f23dc8d7f1111add796133b2d72bff6d3dbd7369f4a2923fc98f38a317f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88d9f42701e59b2b93f004c6a51eed5ebed4b047556ddc0eb959075522afeeb499fcd0da29348b61a56359c167418bdf225af7bcf0a2e38425b91146a7df9fce
|
7
|
+
data.tar.gz: 8671942b1efd8e43106aaebc50bc096ae073961c21bd2b86287bb588bb22b5e82ca1c049e84fdd1cace3e713cd7cdfdd9024138ec3f491274ee62736ae2f94eb
|
data/.semaph
ADDED
data/Gemfile.lock
CHANGED
data/lib/semaph.rb
CHANGED
@@ -1,22 +1,57 @@
|
|
1
|
+
require "semaph/client"
|
2
|
+
require "semaph/model/project"
|
1
3
|
require "semaph/version"
|
2
4
|
require "semaph/shells/organisations/organisations_shell"
|
3
5
|
require "semaph/shells/organisation/organisation_shell"
|
6
|
+
require "semaph/shells/project/project_shell"
|
4
7
|
require "yaml"
|
5
8
|
|
6
9
|
module Semaph
|
7
10
|
class Error < StandardError; end
|
8
11
|
|
9
12
|
def self.console
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
sem_config = YAML.load_file(yaml_path)
|
14
|
-
contexts = sem_config["contexts"]
|
13
|
+
organisations = load_organisations
|
14
|
+
config = load_config
|
15
15
|
|
16
|
-
if
|
17
|
-
|
16
|
+
if config
|
17
|
+
console_with_config(organisations, config)
|
18
|
+
elsif organisations.count == 1
|
19
|
+
Shells::Organisation::OrganisationShell.new(organisations.first).push
|
18
20
|
else
|
19
|
-
Shells::Organisations::OrganisationsShell.new(
|
21
|
+
Shells::Organisations::OrganisationsShell.new(organisations).push
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.console_with_config(organisations, config)
|
26
|
+
organisation = organisations.find { |o| o["host"] == config[:host] }
|
27
|
+
|
28
|
+
Shells::Project::ProjectShell.new(
|
29
|
+
Model::Project.new(
|
30
|
+
::Semaph::Client.new(
|
31
|
+
organisation["auth"]["token"],
|
32
|
+
organisation["host"],
|
33
|
+
),
|
34
|
+
config[:project],
|
35
|
+
),
|
36
|
+
).push
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.load_organisations
|
40
|
+
yaml_path = File.join(File.expand_path("~"), ".sem.yaml")
|
41
|
+
|
42
|
+
unless File.exist?(yaml_path)
|
43
|
+
unless organisations
|
44
|
+
puts "Please install the sem tool and authenticate to semaphoreci.com"
|
45
|
+
exit 1
|
46
|
+
end
|
20
47
|
end
|
48
|
+
|
49
|
+
YAML.load_file(yaml_path)["contexts"].values
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.load_config
|
53
|
+
return nil unless File.exist?(".semaph")
|
54
|
+
|
55
|
+
YAML.load_file(".semaph")
|
21
56
|
end
|
22
57
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
+
require "date"
|
1
2
|
require "semaph/model/job"
|
2
3
|
|
3
4
|
module Semaph
|
4
5
|
module Model
|
5
6
|
class JobCollection
|
6
|
-
attr_reader :all, :pipeline
|
7
|
+
attr_reader :all, :pipeline, :stopping_at, :running_at, :queuing_at, :pending_at, :done_at, :created_at
|
7
8
|
|
8
9
|
def initialize(pipeline)
|
9
10
|
@pipeline = pipeline
|
@@ -12,7 +13,7 @@ module Semaph
|
|
12
13
|
def reload
|
13
14
|
workflow = @pipeline.workflow
|
14
15
|
project = workflow.project
|
15
|
-
@all =
|
16
|
+
@all = parse_content(project.client.pipeline(@pipeline.id))
|
16
17
|
end
|
17
18
|
|
18
19
|
def incomplete
|
@@ -25,7 +26,8 @@ module Semaph
|
|
25
26
|
|
26
27
|
private
|
27
28
|
|
28
|
-
def
|
29
|
+
def parse_content(content)
|
30
|
+
parse_pipeline(content["pipeline"])
|
29
31
|
result = []
|
30
32
|
blocks = content.delete("blocks")
|
31
33
|
blocks.each do |block|
|
@@ -35,6 +37,15 @@ module Semaph
|
|
35
37
|
result
|
36
38
|
end
|
37
39
|
|
40
|
+
def parse_pipeline(pipeline_content)
|
41
|
+
with_time(pipeline_content["stopping_at"]) { |time| @stopping_at = time }
|
42
|
+
with_time(pipeline_content["running_at"]) { |time| @running_at = time }
|
43
|
+
with_time(pipeline_content["queuing_at"]) { |time| @queuing_at = time }
|
44
|
+
with_time(pipeline_content["pending_at"]) { |time| @pending_at = time }
|
45
|
+
with_time(pipeline_content["done_at"]) { |time| @done_at = time }
|
46
|
+
with_time(pipeline_content["created_at"]) { |time| @created_at = time }
|
47
|
+
end
|
48
|
+
|
38
49
|
def append_jobs(result, block, jobs)
|
39
50
|
if jobs.count.positive?
|
40
51
|
jobs.each { |job| result << Job.new(@pipeline, block, job) }
|
@@ -42,6 +53,11 @@ module Semaph
|
|
42
53
|
result << Job.new(@pipeline, block, {})
|
43
54
|
end
|
44
55
|
end
|
56
|
+
|
57
|
+
def with_time(string)
|
58
|
+
time = DateTime.parse(string).to_time
|
59
|
+
yield time unless time.to_i.zero?
|
60
|
+
end
|
45
61
|
end
|
46
62
|
end
|
47
63
|
end
|
@@ -13,11 +13,13 @@ module Semaph
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def completion(text)
|
16
|
-
@organisations.
|
16
|
+
@organisations.map { |org| org["host"].split(".").first }.grep(/^#{text}/).sort
|
17
17
|
end
|
18
18
|
|
19
19
|
def execute(name)
|
20
|
-
organisation = @organisations
|
20
|
+
organisation = @organisations.find do |org|
|
21
|
+
org["host"].split(".").first == name
|
22
|
+
end
|
21
23
|
|
22
24
|
unless organisation
|
23
25
|
puts "There is no organisation called #{name}"
|
@@ -4,7 +4,7 @@ module Semaph
|
|
4
4
|
module Shells
|
5
5
|
module Pipeline
|
6
6
|
class JobLogCommand
|
7
|
-
attr_reader :usage, :help
|
7
|
+
attr_reader :usage, :help, :job_collection
|
8
8
|
|
9
9
|
def initialize(job_collection)
|
10
10
|
@job_collection = job_collection
|
@@ -13,23 +13,23 @@ module Semaph
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def execute(index_string)
|
16
|
-
|
17
|
-
with_job(index_string) do |job|
|
18
|
-
unless job.finished?
|
19
|
-
puts "This job has not finished yet"
|
20
|
-
return
|
21
|
-
end
|
22
|
-
|
23
|
-
system("less #{job.write_log(base)}")
|
24
|
-
end
|
16
|
+
with_job(index_string) { |job| system(command(job)) }
|
25
17
|
end
|
26
18
|
|
27
19
|
private
|
28
20
|
|
21
|
+
def command(job)
|
22
|
+
base = "tmp/logs/pipeline/#{job_collection.pipeline.id}"
|
23
|
+
|
24
|
+
return "less #{job.write_log(base)}" if job.finished?
|
25
|
+
|
26
|
+
"open https://#{job_collection.pipeline.workflow.project.client.host}/jobs/#{job.id}"
|
27
|
+
end
|
28
|
+
|
29
29
|
def with_job(index_string)
|
30
30
|
index = index_string.to_i - 1
|
31
31
|
|
32
|
-
job =
|
32
|
+
job = job_collection.all[index]
|
33
33
|
|
34
34
|
unless job
|
35
35
|
puts "There is no job at position #{index}"
|
@@ -21,8 +21,7 @@ module Semaph
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def report_and_reload(period)
|
24
|
-
report_incomplete
|
25
|
-
sleep period
|
24
|
+
period.times { report_incomplete }
|
26
25
|
job_collection.reload
|
27
26
|
end
|
28
27
|
|
@@ -36,10 +35,28 @@ module Semaph
|
|
36
35
|
)
|
37
36
|
end
|
38
37
|
|
39
|
-
def report_incomplete
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
def report_incomplete
|
39
|
+
base = [nil, elapsed, report_ratio, job_collection.pipeline.workflow.description].join(" ")
|
40
|
+
erase base
|
41
|
+
end
|
42
|
+
|
43
|
+
def report_ratio
|
44
|
+
[
|
45
|
+
job_collection.incomplete.count.to_s.rjust(2, "0"),
|
46
|
+
job_collection.all.count.to_s.rjust(2, "0"),
|
47
|
+
].join("/")
|
48
|
+
end
|
49
|
+
|
50
|
+
def elapsed
|
51
|
+
duration = Time.now.to_i - job_collection.created_at.to_i
|
52
|
+
mins = duration / 60
|
53
|
+
secs = duration % 60
|
54
|
+
[mins.to_s.rjust(2, "0"), secs.to_s.rjust(2, "0")].join(":")
|
55
|
+
end
|
56
|
+
|
57
|
+
def erase(string)
|
58
|
+
print string
|
59
|
+
print "\b" * string.length
|
43
60
|
end
|
44
61
|
|
45
62
|
def notify(title, message, failed)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "semaph/commands/reload_command"
|
2
2
|
require "semaph/commands/visit_url_command"
|
3
|
+
require "semaph/shells/project/save_command"
|
3
4
|
require "semaph/shells/project/workflows_list_command"
|
4
5
|
require "semaph/shells/project/workflows_select_command"
|
5
6
|
require "shell_shock/context"
|
@@ -28,6 +29,7 @@ module Semaph
|
|
28
29
|
def add_commands
|
29
30
|
add_github_command
|
30
31
|
add_open_project_command
|
32
|
+
add_command SaveCommand.new(project), "save"
|
31
33
|
@workflows_list_command = WorkflowsListCommand.new(workflow_collection)
|
32
34
|
add_command @workflows_list_command, "list-workflows", "ls"
|
33
35
|
add_command WorkflowsSelectCommand.new(workflow_collection), "select-workflow", "cd"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module Semaph
|
4
|
+
module Shells
|
5
|
+
module Project
|
6
|
+
class SaveCommand
|
7
|
+
attr_reader :help, :project
|
8
|
+
|
9
|
+
def initialize(project)
|
10
|
+
@project = project
|
11
|
+
@help = "save current project as default for this folder"
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute(_ignored)
|
15
|
+
config = {
|
16
|
+
host: project.client.host,
|
17
|
+
project: project.raw,
|
18
|
+
}
|
19
|
+
File.open(".semaph", "w") do |file|
|
20
|
+
file.puts config.to_yaml
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/semaph/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semaph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.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-
|
11
|
+
date: 2020-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -90,6 +90,7 @@ extra_rdoc_files: []
|
|
90
90
|
files:
|
91
91
|
- ".gitignore"
|
92
92
|
- ".rubocop.yml"
|
93
|
+
- ".semaph"
|
93
94
|
- ".semaphore/semaphore.yml"
|
94
95
|
- ".tool-versions"
|
95
96
|
- ".travis.yml"
|
@@ -137,6 +138,7 @@ files:
|
|
137
138
|
- lib/semaph/shells/pipeline/promote_command.rb
|
138
139
|
- lib/semaph/shells/pipeline/promotions_list_command.rb
|
139
140
|
- lib/semaph/shells/project/project_shell.rb
|
141
|
+
- lib/semaph/shells/project/save_command.rb
|
140
142
|
- lib/semaph/shells/project/workflows_list_command.rb
|
141
143
|
- lib/semaph/shells/project/workflows_select_command.rb
|
142
144
|
- lib/semaph/shells/workflow/pipelines_list_command.rb
|