semaph 0.2.0 → 0.7.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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.rubocop.yml +39 -0
  4. data/.semaphore/semaphore.yml +5 -1
  5. data/Gemfile.lock +21 -1
  6. data/README.md +85 -11
  7. data/Rakefile +4 -1
  8. data/lib/semaph/client.rb +115 -0
  9. data/lib/semaph/commands.rb +63 -0
  10. data/lib/semaph/commands/reload_command.rb +5 -4
  11. data/lib/semaph/commands/rerun_workflow_command.rb +16 -0
  12. data/lib/semaph/commands/stop_workflow_command.rb +16 -0
  13. data/lib/semaph/formatting.rb +15 -1
  14. data/lib/semaph/model/job.rb +70 -1
  15. data/lib/semaph/model/job_collection.rb +18 -5
  16. data/lib/semaph/model/pipeline.rb +54 -2
  17. data/lib/semaph/model/pipeline_collection.rb +0 -1
  18. data/lib/semaph/model/project.rb +1 -1
  19. data/lib/semaph/model/project_collection.rb +0 -1
  20. data/lib/semaph/model/promotion.rb +31 -0
  21. data/lib/semaph/model/promotion_collection.rb +21 -0
  22. data/lib/semaph/model/workflow.rb +28 -4
  23. data/lib/semaph/model/workflow_collection.rb +0 -1
  24. data/lib/semaph/shells/organisation/organisation_shell.rb +15 -11
  25. data/lib/semaph/shells/organisation/projects_list_command.rb +1 -0
  26. data/lib/semaph/shells/organisation/projects_select_command.rb +6 -0
  27. data/lib/semaph/shells/organisations/organisations_select_command.rb +8 -1
  28. data/lib/semaph/shells/organisations/organisations_shell.rb +6 -2
  29. data/lib/semaph/shells/pipeline/job_debug_command.rb +29 -0
  30. data/lib/semaph/shells/pipeline/job_log_command.rb +44 -0
  31. data/lib/semaph/shells/pipeline/job_log_grep_command.rb +28 -0
  32. data/lib/semaph/shells/pipeline/job_show_command.rb +28 -0
  33. data/lib/semaph/shells/pipeline/job_stop_command.rb +28 -0
  34. data/lib/semaph/shells/pipeline/jobs_list_command.rb +6 -16
  35. data/lib/semaph/shells/pipeline/jobs_poll_command.rb +55 -0
  36. data/lib/semaph/shells/pipeline/pipeline_shell.rb +42 -7
  37. data/lib/semaph/shells/pipeline/promote_command.rb +21 -0
  38. data/lib/semaph/shells/pipeline/promotions_list_command.rb +21 -0
  39. data/lib/semaph/shells/project/project_shell.rb +31 -18
  40. data/lib/semaph/shells/project/workflows_list_command.rb +4 -16
  41. data/lib/semaph/shells/project/workflows_select_command.rb +10 -3
  42. data/lib/semaph/shells/workflow/pipelines_list_command.rb +4 -1
  43. data/lib/semaph/shells/workflow/pipelines_select_command.rb +9 -3
  44. data/lib/semaph/shells/workflow/workflow_shell.rb +13 -42
  45. data/lib/semaph/version.rb +1 -1
  46. data/semaph.gemspec +1 -0
  47. metadata +33 -6
  48. data/lib/semaph/api.rb +0 -61
@@ -1,9 +1,9 @@
1
+ require "semaph/formatting"
2
+
1
3
  module Semaph
2
4
  module Shells
3
5
  module Project
4
6
  class WorkflowsListCommand
5
- TIME_FORMAT = "%Y-%m-%d %H:%M:%S".freeze
6
-
7
7
  attr_reader :usage, :help
8
8
 
9
9
  def initialize(workflow_collection)
@@ -13,25 +13,13 @@ module Semaph
13
13
  end
14
14
 
15
15
  def execute(branch)
16
+ @workflow_collection.reload
16
17
  @workflow_collection.all.each_with_index do |workflow, index|
17
18
  next unless workflow.branch.include?(branch)
18
19
 
19
- puts description(index, workflow)
20
+ puts [::Semaph::Formatting.index(index + 1), workflow.description].join(" ")
20
21
  end
21
22
  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
23
  end
36
24
  end
37
25
  end
@@ -1,4 +1,5 @@
1
1
  require "semaph/shells/workflow/workflow_shell"
2
+ require "semaph/shells/pipeline/pipeline_shell"
2
3
 
3
4
  module Semaph
4
5
  module Shells
@@ -14,9 +15,15 @@ module Semaph
14
15
 
15
16
  def execute(index_string)
16
17
  index = index_string.to_i - 1
17
- ::Semaph::Shells::Workflow::WorkflowShell.new(
18
- @workflow_collection.all[index],
19
- ).push
18
+
19
+ workflow = @workflow_collection.all[index]
20
+
21
+ unless workflow
22
+ puts "There is no workflow at position #{index}"
23
+ return
24
+ end
25
+
26
+ ::Semaph::Shells::Workflow::WorkflowShell.new(workflow).push
20
27
  end
21
28
  end
22
29
  end
@@ -1,3 +1,5 @@
1
+ require "semaph/formatting"
2
+
1
3
  module Semaph
2
4
  module Shells
3
5
  module Workflow
@@ -10,8 +12,9 @@ module Semaph
10
12
  end
11
13
 
12
14
  def execute(_whatever)
15
+ @pipeline_collection.reload
13
16
  @pipeline_collection.all.each_with_index do |pipeline, index|
14
- puts "#{index + 1} #{pipeline.yaml} #{pipeline.state} #{pipeline.result}"
17
+ puts [::Semaph::Formatting.index(index + 1), pipeline.description].join(" ")
15
18
  end
16
19
  end
17
20
  end
@@ -14,9 +14,15 @@ module Semaph
14
14
 
15
15
  def execute(index_string)
16
16
  index = index_string.to_i - 1
17
- ::Semaph::Shells::Pipeline::PipelineShell.new(
18
- @pipeline_collection.all[index],
19
- ).push
17
+
18
+ pipeline = @pipeline_collection.all[index]
19
+
20
+ unless pipeline
21
+ puts "There is no pipeline at position #{index}"
22
+ return
23
+ end
24
+
25
+ ::Semaph::Shells::Pipeline::PipelineShell.new(pipeline).push
20
26
  end
21
27
  end
22
28
  end
@@ -1,5 +1,4 @@
1
- require "semaph/commands/visit_url_command"
2
- require "semaph/commands/reload_command"
1
+ require "semaph/commands"
3
2
  require "semaph/shells/workflow/pipelines_list_command"
4
3
  require "semaph/shells/workflow/pipelines_select_command"
5
4
  require "shell_shock/context"
@@ -8,55 +7,27 @@ module Semaph
8
7
  module Shells
9
8
  module Workflow
10
9
  class WorkflowShell
10
+ attr_reader :workflow
11
+
11
12
  include ShellShock::Context
12
13
 
13
14
  def initialize(workflow)
14
15
  @workflow = workflow
15
16
  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
- )
17
+ @prompt = "🏗 #{project.client.name} #{project.name} #{workflow.id} > "
18
+ add_commands
19
+ @list_command.execute("")
39
20
  end
40
21
 
41
22
  private
42
23
 
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
- )
24
+ def add_commands
25
+ pipeline_collection = @workflow.pipeline_collection
26
+ @list_command = PipelinesListCommand.new(pipeline_collection)
27
+ add_command @list_command, "list-pipelines", "ls"
28
+ add_command PipelinesSelectCommand.new(pipeline_collection), "select-pipeline", "cd"
29
+ add_command ::Semaph::Commands::ReloadCommand.new, "reload" if ENV["SEMAPH_RELOAD"]
30
+ ::Semaph::Commands.workflow_commands(self, workflow)
60
31
  end
61
32
  end
62
33
  end
@@ -1,3 +1,3 @@
1
1
  module Semaph
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.7.0".freeze
3
3
  end
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency "shell_shock"
29
29
 
30
30
  spec.add_development_dependency "pry"
31
+ spec.add_development_dependency "rubocop"
31
32
  end
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.2.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Ryall
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-30 00:00:00.000000000 Z
11
+ date: 2020-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: api client and shell for api
70
84
  email:
71
85
  - mark@ryall.name
@@ -89,8 +103,11 @@ files:
89
103
  - bin/setup
90
104
  - exe/semaph
91
105
  - lib/semaph.rb
92
- - lib/semaph/api.rb
106
+ - lib/semaph/client.rb
107
+ - lib/semaph/commands.rb
93
108
  - lib/semaph/commands/reload_command.rb
109
+ - lib/semaph/commands/rerun_workflow_command.rb
110
+ - lib/semaph/commands/stop_workflow_command.rb
94
111
  - lib/semaph/commands/visit_url_command.rb
95
112
  - lib/semaph/formatting.rb
96
113
  - lib/semaph/model/job.rb
@@ -99,6 +116,8 @@ files:
99
116
  - lib/semaph/model/pipeline_collection.rb
100
117
  - lib/semaph/model/project.rb
101
118
  - lib/semaph/model/project_collection.rb
119
+ - lib/semaph/model/promotion.rb
120
+ - lib/semaph/model/promotion_collection.rb
102
121
  - lib/semaph/model/workflow.rb
103
122
  - lib/semaph/model/workflow_collection.rb
104
123
  - lib/semaph/shells/organisation/organisation_shell.rb
@@ -107,8 +126,16 @@ files:
107
126
  - lib/semaph/shells/organisations/organisations_list_command.rb
108
127
  - lib/semaph/shells/organisations/organisations_select_command.rb
109
128
  - lib/semaph/shells/organisations/organisations_shell.rb
129
+ - lib/semaph/shells/pipeline/job_debug_command.rb
130
+ - lib/semaph/shells/pipeline/job_log_command.rb
131
+ - lib/semaph/shells/pipeline/job_log_grep_command.rb
132
+ - lib/semaph/shells/pipeline/job_show_command.rb
133
+ - lib/semaph/shells/pipeline/job_stop_command.rb
110
134
  - lib/semaph/shells/pipeline/jobs_list_command.rb
135
+ - lib/semaph/shells/pipeline/jobs_poll_command.rb
111
136
  - lib/semaph/shells/pipeline/pipeline_shell.rb
137
+ - lib/semaph/shells/pipeline/promote_command.rb
138
+ - lib/semaph/shells/pipeline/promotions_list_command.rb
112
139
  - lib/semaph/shells/project/project_shell.rb
113
140
  - lib/semaph/shells/project/workflows_list_command.rb
114
141
  - lib/semaph/shells/project/workflows_select_command.rb
@@ -124,7 +151,7 @@ metadata:
124
151
  homepage_uri: http://github.com/markryall/semaph
125
152
  source_code_uri: http://github.com/markryall/semaph
126
153
  changelog_uri: http://github.com/markryall/semaph
127
- post_install_message:
154
+ post_install_message:
128
155
  rdoc_options: []
129
156
  require_paths:
130
157
  - lib
@@ -140,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
167
  version: '0'
141
168
  requirements: []
142
169
  rubygems_version: 3.1.2
143
- signing_key:
170
+ signing_key:
144
171
  specification_version: 4
145
172
  summary: client for semaphore 2
146
173
  test_files: []
@@ -1,61 +0,0 @@
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