robopigeon 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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +1 -3
  4. data/.version +1 -1
  5. data/CHANGELOG.md +18 -0
  6. data/LICENSE.txt +7 -0
  7. data/README.md +34 -131
  8. data/lib/robopigeon/dsl/base.rb +8 -0
  9. data/lib/robopigeon/dsl/initial_jobs.rb +9 -0
  10. data/lib/robopigeon/dsl/job.rb +10 -0
  11. data/lib/robopigeon/dsl.rb +6 -4
  12. data/lib/robopigeon/extend/cli.rb +34 -0
  13. data/lib/robopigeon/extend/template.rb +53 -0
  14. data/lib/robopigeon/extend/templates/default/.gitignore +16 -0
  15. data/lib/robopigeon/extend/templates/default/.gitlab-ci.yml +27 -0
  16. data/lib/robopigeon/extend/templates/default/.rubocop.yml +50 -0
  17. data/lib/robopigeon/extend/templates/default/.version +1 -0
  18. data/lib/robopigeon/extend/templates/default/Gemfile +6 -0
  19. data/lib/robopigeon/extend/templates/default/README.erb.md +35 -0
  20. data/lib/robopigeon/extend/templates/default/lib/robopigeon-extension/dsl.erb.rb +39 -0
  21. data/lib/robopigeon/extend/templates/default/lib/robopigeon-extension/helper_dsl.erb.rb +18 -0
  22. data/lib/robopigeon/extend/templates/default/lib/robopigeon-extension/version.erb.rb +5 -0
  23. data/lib/robopigeon/extend/templates/default/lib/robopigeon-extension.erb.rb +25 -0
  24. data/lib/robopigeon/extend/templates/default/robopigeon-extension.erb.gemspec +41 -0
  25. data/lib/robopigeon/extend/templates/default/spec/robopigeon-extension/dsl_spec.erb.rb +33 -0
  26. data/lib/robopigeon/extend/templates/default/spec/robopigeon-extension/helper_dsl_spec.erb.rb +14 -0
  27. data/lib/robopigeon/extend/templates/default/spec/spec_helper.erb.rb +18 -0
  28. data/lib/robopigeon/extend.rb +2 -0
  29. data/lib/robopigeon/gitlab/commit.rb +31 -0
  30. data/lib/robopigeon/gitlab/commit_dsl.rb +67 -0
  31. data/lib/robopigeon/gitlab/dsl.rb +11 -7
  32. data/lib/robopigeon/gitlab.rb +2 -0
  33. data/lib/robopigeon/jenkins/client.rb +18 -0
  34. data/lib/robopigeon/jenkins/dsl.rb +98 -0
  35. data/lib/robopigeon/jenkins/job.rb +69 -0
  36. data/lib/robopigeon/jenkins.rb +22 -0
  37. data/lib/robopigeon/jira/dsl.rb +7 -10
  38. data/lib/robopigeon/jira/helper_dsl.rb +13 -0
  39. data/lib/robopigeon/resources/initial_robopigeon.rb +55 -0
  40. data/lib/robopigeon/slack/attachments_dsl.rb +2 -2
  41. data/lib/robopigeon/slack/dsl.rb +1 -7
  42. data/lib/robopigeon.rb +2 -0
  43. data/robopigeon.gemspec +19 -15
  44. data/robopigeon.rb +55 -0
  45. metadata +121 -47
  46. data/lib/robopigeon/gitlab/jira.rb +0 -0
@@ -0,0 +1,25 @@
1
+ require 'robopigeon-<%= extension_name_lower %>/helper_dsl'
2
+ require 'robopigeon-<%= extension_name_lower %>/dsl'
3
+ require 'robopigeon-<%= extension_name_lower %>/version'
4
+
5
+ module RoboPigeon::Dsl
6
+ module Helpers
7
+ include RoboPigeon::Dsl::Helpers::<%= extension_name_upper %>
8
+ end
9
+ end
10
+
11
+ module RoboPigeon::Dsl
12
+ class Root
13
+ def <%= extension_name_lower %>(&block)
14
+ RoboPigeon::Dsl::<%= extension_name_upper %>Root.run(&block)
15
+ end
16
+ end
17
+ end
18
+
19
+ module RoboPigeon::Dsl
20
+ class Job
21
+ def <%= extension_name_lower %>(&block)
22
+ RoboPigeon::Dsl::<%= extension_name_upper %>.run(&block)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,41 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'robopigeon-<%= extension_name_lower %>/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'robopigeon-<%= extension_name_lower %>'
7
+ spec.version = RoboPigeon::<%= extension_name_upper %>::VERSION
8
+ spec.authors = ['<%= user_name %>']
9
+ spec.email = ['<%= user_email %>']
10
+
11
+ spec.summary = 'An extension for RoboPigeon for <%= extension_name_upper %>'
12
+ spec.description = 'TODO: Add a description'
13
+ spec.homepage = 'TODO: Add a homepage'
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = 'TODO: Add source repo link'
20
+ else
21
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
22
+ 'public gem pushes.'
23
+ end
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
28
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
+ end
30
+ spec.bindir = 'exe'
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ['lib']
33
+
34
+ spec.add_dependency 'robopigeon'
35
+
36
+ spec.add_development_dependency 'bundler'
37
+ spec.add_development_dependency 'pry'
38
+ spec.add_development_dependency 'rake', '~> 10.0'
39
+ spec.add_development_dependency 'rspec', '~> 3.0'
40
+ spec.add_development_dependency 'rubocop'
41
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe RoboPigeon::Dsl::GitLabRoot do
4
+ subject { RoboPigeon::Dsl::Root }
5
+
6
+ context 'do_some_global_thing' do
7
+ it 'does some global thing' do
8
+ expect do
9
+ subject.run do
10
+ <%= extension_name_lower %> do
11
+ do_some_global_thing
12
+ end
13
+ end
14
+ end.not_to raise_error
15
+ end
16
+ end
17
+ end
18
+
19
+ describe RoboPigeon::Dsl::GitLab do
20
+ subject { RoboPigeon::Dsl::Job }
21
+
22
+ context 'do_something' do
23
+ it 'does some global thing' do
24
+ expect do
25
+ subject.run do
26
+ <%= extension_name_lower %> do
27
+ do_something
28
+ end
29
+ end
30
+ end.not_to raise_error
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe RoboPigeon::Dsl::Helpers::<%= extension_name_upper %> do
4
+ class <%= extension_name_upper %>HelperTest
5
+ include RoboPigeon::Dsl::Helpers::<%= extension_name_upper %>
6
+ end
7
+ subject { <%= extension_name_upper %>HelperTest.new }
8
+
9
+ context 'some_helper_dsl' do
10
+ it 'does something really cool!' do
11
+ expect(subject.some_helper_dsl).to eq('nothing happens here yet')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'bundler/setup'
3
+ require 'robopigeon'
4
+ require 'robopigeon-<%= extension_name_lower %>'
5
+ require 'pry'
6
+
7
+ RSpec.configure do |config|
8
+ # Enable flags like --only-failures and --next-failure
9
+ config.example_status_persistence_file_path = '.rspec_status'
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
15
+
16
+ def file_fixture(path)
17
+ File.join(Dir.pwd, 'spec', 'fixtures', path)
18
+ end
@@ -0,0 +1,2 @@
1
+ require 'robopigeon/extend/template'
2
+ require 'robopigeon/extend/cli'
@@ -0,0 +1,31 @@
1
+ module RoboPigeon::GitLab
2
+ class Commit
3
+ attr_accessor :files, :branch, :message, :author_name, :author_email
4
+ def initialize
5
+ self.files = []
6
+ self.author_name = ENV['GITLAB_USER_NAME']
7
+ self.author_email = ENV['GITLAB_USER_EMAIL']
8
+ self.branch = RoboPigeon::GitLab::Client.branch
9
+ end
10
+
11
+ def add_file(file, content=nil, method='update')
12
+ content ||= File.read(file)
13
+ files.push(action: method, file_path: file, content: content)
14
+ end
15
+
16
+ def client
17
+ RoboPigeon::GitLab::Client.client
18
+ end
19
+
20
+ def commit!
21
+ client.create_commit(
22
+ RoboPigeon::GitLab::Client.project,
23
+ branch,
24
+ message,
25
+ files,
26
+ author_name: author_name,
27
+ author_email: author_email
28
+ )
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,67 @@
1
+ require 'gitlab'
2
+ module RoboPigeon::Dsl
3
+ class GitLabCommit
4
+ attr_accessor :commit
5
+ def initialize
6
+ self.commit = RoboPigeon::GitLab::Commit.new
7
+ end
8
+
9
+ def self.run(&block)
10
+ instance = new
11
+ instance.instance_eval(&block)
12
+ instance.commit.commit!
13
+ end
14
+
15
+ RoboPigeon::Documentarian.add_command(
16
+ 'file',
17
+ block: %w[job gitlab commit],
18
+ params: [
19
+ { name: 'path', type: 'String', desc: 'repo path of the file to add', example: 'app/config.rb' },
20
+ { name: 'contents', type: 'Text', desc: 'the content of the file to add (optional)', example: 'here is the contents of my file', default: 'on disk contents of file' }
21
+ ],
22
+ desc: 'add a file to the commit'
23
+ )
24
+ def file(path, content=nil)
25
+ method = File.exist?(path) ? 'update' : 'create'
26
+ commit.add_file(path, content, method)
27
+ end
28
+
29
+ RoboPigeon::Documentarian.add_command(
30
+ 'message',
31
+ block: %w[job gitlab commit],
32
+ params: [
33
+ { name: 'message', type: 'string', desc: 'message to use in the commit', example: 'A commit to end all commits!' }
34
+ ],
35
+ desc: 'Set the message for the commit'
36
+ )
37
+ def message(message)
38
+ commit.message = message
39
+ end
40
+
41
+ RoboPigeon::Documentarian.add_command(
42
+ 'author',
43
+ block: %w[job gitlab commit],
44
+ params: [
45
+ { name: 'name', type: 'String', desc: 'name of the user who is making the commit', example: 'Robo Pigeon', default: "ENV['GITLAB_USER_NAME']" },
46
+ { name: 'email', type: 'String', desc: 'email of the user who is making the commit', example: 'robo.pigeon@example.com', default: "ENV['GITLAB_USER_EMAIL']" }
47
+ ],
48
+ desc: 'set the author name and email address.'
49
+ )
50
+ def author(name, email)
51
+ commit.author_email = email
52
+ commit.author_name = name
53
+ end
54
+
55
+ RoboPigeon::Documentarian.add_command(
56
+ 'branch',
57
+ block: %w[job gitlab commit],
58
+ params: [
59
+ { name: 'name', type: 'String', desc: 'name of the branch to commit to', example: 'master', defautl: "ENV['CI_COMMIT_REF_NAME']" }
60
+ ],
61
+ desc: 'Set the branch to commit to'
62
+ )
63
+ def branch(name)
64
+ commit.branch = name
65
+ end
66
+ end
67
+ end
@@ -1,11 +1,6 @@
1
1
  require 'gitlab'
2
2
  module RoboPigeon::Dsl
3
- class GitLabRoot
4
- def self.run(&block)
5
- gitlab = RoboPigeon::Dsl::GitLabRoot.new
6
- gitlab.instance_eval(&block)
7
- end
8
-
3
+ class GitLabRoot < RoboPigeon::Dsl::Base
9
4
  RoboPigeon::Documentarian.add_command(
10
5
  'enabled',
11
6
  block: ['gitlab'],
@@ -81,7 +76,6 @@ module RoboPigeon::Dsl
81
76
 
82
77
  class GitLab < GitLabRoot
83
78
  attr_accessor :merge_request
84
- include RoboPigeon::Dsl::Helpers
85
79
 
86
80
  def self.run(&block)
87
81
  if RoboPigeon::GitLab::Client.enabled
@@ -170,5 +164,15 @@ module RoboPigeon::Dsl
170
164
  def merge_merge_request
171
165
  merge_request.merge!
172
166
  end
167
+
168
+ RoboPigeon::Documentarian.add_block(
169
+ 'commit',
170
+ helpers: true,
171
+ block: %w[job gitlab],
172
+ desc: 'Create a commit on a branch'
173
+ )
174
+ def commit(&block)
175
+ RoboPigeon::GitLab::Commit.run(&block)
176
+ end
173
177
  end
174
178
  end
@@ -3,8 +3,10 @@ RoboPigeon::Documentarian.add_block('gitlab', helpers: true, block: ['job'], des
3
3
 
4
4
  require 'robopigeon/gitlab/dsl'
5
5
  require 'robopigeon/gitlab/client'
6
+ require 'robopigeon/gitlab/commit'
6
7
  require 'robopigeon/gitlab/merge_request'
7
8
  require 'robopigeon/gitlab/helper_dsl'
9
+ require 'robopigeon/gitlab/commit_dsl'
8
10
 
9
11
  module RoboPigeon::Dsl
10
12
  module Helpers
@@ -0,0 +1,18 @@
1
+ require 'jenkins_api_client'
2
+
3
+ module RoboPigeon::Jenkins
4
+ class Client
5
+ @enabled = true
6
+
7
+ class << self
8
+ attr_accessor :url, :user, :token, :enabled
9
+ def client
10
+ @client ||= JenkinsApi::Client.new(
11
+ server_url: url,
12
+ username: user,
13
+ password: token
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,98 @@
1
+ module RoboPigeon::Dsl
2
+ class JenkinsRoot
3
+ def self.run(&block)
4
+ instance = new
5
+ instance.instance_eval(&block)
6
+ end
7
+
8
+ RoboPigeon::Documentarian.add_command(
9
+ 'enabled',
10
+ block: ['jenkins'],
11
+ params: [
12
+ { name: 'enabled', type: 'boolean', desc: 'should it run Jenkins commands', example: 'false', default: 'true' }
13
+ ],
14
+ desc: 'Set whether or not to run Jenkins commands, defaults to true'
15
+ )
16
+ def enabled(bool)
17
+ RoboPigeon::Jenkins::Client.enabled = bool
18
+ end
19
+
20
+ RoboPigeon::Documentarian.add_command(
21
+ 'api_url',
22
+ block: ['jenkins'],
23
+ params: [
24
+ { name: 'url', type: 'String', desc: 'jenkins server url', example: 'https://jenkins.example.com' }
25
+ ],
26
+ desc: 'Set the url for your jenkins server'
27
+ )
28
+ def api_url(url)
29
+ RoboPigeon::Jenkins::Client.url = url
30
+ end
31
+
32
+ RoboPigeon::Documentarian.add_command(
33
+ 'api_user',
34
+ block: ['jenkins'],
35
+ params: [
36
+ { name: 'user', type: 'String', desc: 'jenkins server user', example: 'pigeon' }
37
+ ],
38
+ desc: 'Set the user for your jenkins server'
39
+ )
40
+ def api_user(user)
41
+ RoboPigeon::Jenkins::Client.user = user
42
+ end
43
+
44
+ RoboPigeon::Documentarian.add_command(
45
+ 'api_key',
46
+ block: ['jenkins'],
47
+ params: [
48
+ { name: 'token', type: 'String', desc: 'jenkins server token', example: '9eNVDMWuY3zf0DZ5yxLH9Q' }
49
+ ],
50
+ desc: 'Set the token for your jenkins server'
51
+ )
52
+ def api_key(token)
53
+ RoboPigeon::Jenkins::Client.token = token
54
+ end
55
+ end
56
+ class Jenkins
57
+ attr_accessor :job
58
+ def initialize
59
+ self.job = RoboPigeon::Jenkins::Job.new
60
+ end
61
+
62
+ def self.run(run_now = true, &block)
63
+ if RoboPigeon::Jenkins::Client.enabled
64
+ instance = new
65
+ instance.instance_eval(&block)
66
+ instance.job.build_and_watch! if run_now
67
+ instance.job
68
+ else
69
+ puts 'Jenkins is disabled, please remove `enabled false` from your global jenkins config'
70
+ end
71
+ end
72
+
73
+ RoboPigeon::Documentarian.add_command(
74
+ 'param',
75
+ block: ['jenkins'],
76
+ params: [
77
+ { name: 'key', type: 'String', desc: 'the key for the parameter to set', example: 'BUILD_PARAM' },
78
+ { name: 'value', type: 'String', desc: 'the value for the parameter to set', example: '42' }
79
+ ],
80
+ desc: 'Add a parameter to the job'
81
+ )
82
+ def param(key, value)
83
+ job.params[key] = value
84
+ end
85
+
86
+ def start_timeout(seconds)
87
+ job.start_timeout = seconds
88
+ end
89
+
90
+ def name(name)
91
+ job.name = name
92
+ end
93
+
94
+ def completion_timeout(seconds)
95
+ job.build_timeout = seconds
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,69 @@
1
+ module RoboPigeon::Jenkins
2
+ class Failure < StandardError; end
3
+ class Job
4
+ DEFAULT_START_TIMEOUT = (45 * 60) # 45 minutes
5
+ attr_accessor :build_timeout, :name, :params, :poll_interval, :build_opts, :logs, :jid
6
+ def initialize
7
+ self.build_timeout = 60 * 60 # 60 minutes in seconds
8
+ self.params = {}
9
+ self.poll_interval = 10
10
+ self.build_opts = {
11
+ 'build_start_timeout' => DEFAULT_START_TIMEOUT,
12
+ 'cancel_on_build_start_timeout' => true
13
+ }
14
+ end
15
+
16
+ def client
17
+ RoboPigeon::Jenkins::Client.client
18
+ end
19
+
20
+ def start_timeout=(timeout)
21
+ build_opts['build_start_timeout'] = timeout
22
+ end
23
+
24
+ def job_url(jid)
25
+ "#{RoboPigeon::Jenkins::Client.url}/jobs/#{name}/#{jid}"
26
+ end
27
+
28
+ def build_and_watch!
29
+ self.jid = client.job.build(name, params.to_h, build_opts)
30
+ puts "Created jenkins job: #{job_url(jid)}"
31
+
32
+ watch_build
33
+ end
34
+
35
+ private
36
+
37
+ def watch_build(iteration=0)
38
+ if iteration * poll_interval > build_timeout
39
+ output_logs(jid)
40
+ raise Timeout::Error, "Build timed out, see logs or look at #{job_url(jid)}" unless job_success?(jid)
41
+ elsif job_complete?(jid)
42
+ output_logs(jid)
43
+ raise RoboPigeon::Jenkins::Failure, "Build did not complete successfully, see logs or look at #{job_url(jid)}" unless job_success?(jid)
44
+
45
+ return
46
+ end
47
+
48
+ puts "Job not yet complete, Run time: #{(iteration * poll_interval / 60.0).round(2)} minutes"
49
+ sleep poll_interval
50
+ watch_build(iteration + 1)
51
+ end
52
+
53
+ def job_complete?(jid)
54
+ return true if client.job.get_build_details(name, jid)['result'] == 'SUCCESS'
55
+ return true if client.job.get_build_details(name, jid)['result'] == 'FAILURE'
56
+
57
+ false
58
+ end
59
+
60
+ def output_logs(jid)
61
+ self.logs = client.api_get_request("/job/#{name}/#{jid}/consoleText", nil, '')
62
+ puts logs
63
+ end
64
+
65
+ def job_success?(jid)
66
+ client.job.get_build_details(name, jid)['result'] == 'SUCCESS'
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,22 @@
1
+ RoboPigeon::Documentarian.add_block('jenkins', helpers: true, block: [], desc: 'a configuration block for jenkins')
2
+ RoboPigeon::Documentarian.add_block('jenkins', helpers: true, block: ['job'], desc: 'configure a jenkins job to create, run, and watch')
3
+
4
+ require 'robopigeon/jenkins/client'
5
+ require 'robopigeon/jenkins/job'
6
+ require 'robopigeon/jenkins/dsl'
7
+
8
+ module RoboPigeon::Dsl
9
+ class Root
10
+ def jenkins(&block)
11
+ RoboPigeon::Dsl::JenkinsRoot.run(&block)
12
+ end
13
+ end
14
+ end
15
+
16
+ module RoboPigeon::Dsl
17
+ class Job
18
+ def jenkins(&block)
19
+ RoboPigeon::Dsl::Jenkins.run(&block)
20
+ end
21
+ end
22
+ end
@@ -1,10 +1,5 @@
1
1
  module RoboPigeon::Dsl
2
- class JiraRoot
3
- def self.run(&block)
4
- jira = RoboPigeon::Dsl::JiraRoot.new
5
- jira.instance_eval(&block)
6
- end
7
-
2
+ class JiraRoot < RoboPigeon::Dsl::Base
8
3
  RoboPigeon::Documentarian.add_command(
9
4
  'enabled',
10
5
  block: ['jira'],
@@ -43,11 +38,13 @@ module RoboPigeon::Dsl
43
38
  end
44
39
 
45
40
  class Jira < JiraRoot
46
- include RoboPigeon::Dsl::Helpers
47
-
48
41
  def self.run(&block)
49
- jira = RoboPigeon::Dsl::Jira.new
50
- jira.instance_eval(&block)
42
+ if RoboPigeon::Jira::Client.enabled
43
+ jira = RoboPigeon::Dsl::Jira.new
44
+ jira.instance_eval(&block)
45
+ else
46
+ puts 'Jira is disabled, please remove `enabled false` from your global jira config'
47
+ end
51
48
  end
52
49
 
53
50
  RoboPigeon::Documentarian.add_block(
@@ -19,6 +19,19 @@ module RoboPigeon::Dsl
19
19
  jira_url = RoboPigeon::Jira::Client.api_url
20
20
  "<#{issue_id}|#{jira_url}/browse/#{issue_id}>"
21
21
  end
22
+
23
+ RoboPigeon::Documentarian.add_command(
24
+ 'jira_issue_slack_link',
25
+ params: [
26
+ { name: 'issue_id', type: 'String', desc: 'Issue to link to', example: 'TICK-1234' }
27
+ ],
28
+ block: ['helpers'],
29
+ desc: 'Returns a slack formatted link to the last created ticket.'
30
+ )
31
+ def jira_slack_link(issue_id)
32
+ jira_url = RoboPigeon::Jira::Client.api_url
33
+ "<#{issue_id}|#{jira_url}/browse/#{issue_id}>"
34
+ end
22
35
  end
23
36
  end
24
37
  end
@@ -31,6 +31,56 @@ jira do
31
31
  api_key ENV['JIRA_API_TOKEN'] # Always use an envrionment variable, don't check in secrets.
32
32
  end
33
33
 
34
+ jenkins do
35
+ # Jira is currently disabled, make sure you have a valid api token with acces to
36
+ # to your repo, then remove the following line
37
+ enabled false
38
+ # This is where you configure your global jenkins settings, like api url and api token
39
+ # always keep your api key either in an environment variable or encrypted with
40
+ # something like `encryptatron` or rails secrets.
41
+ api_url 'https://jenkins.example.com'
42
+ api_user ENV['JENKINS_USER']
43
+ api_key ENV['JENKINS_TOKEN']
44
+ end
45
+
46
+ # This job is an example of updating and tagging a new version of your project
47
+ job 'update_version', 'Used to update the version to a new one!' do
48
+ gitlab do
49
+ # Creates a commit
50
+ commit do
51
+ # Check in updated report file that helps split tests.
52
+ file 'spec/knapsack_report.json'
53
+ # Check in this version file with the contents of a new verison number
54
+ file '.version', ENV['NEW_VERSION_NUMBER']
55
+
56
+ # You can configure a message for the commit too
57
+ message "Updating version to #{ENV['NEW_VERSION_NUMBER']}"
58
+ # And the author's name and email address (also can be auto-pulled from git)
59
+ author 'Deployment Pigeon', 'pigeon@ives.dev'
60
+ # What branch to commit to
61
+ branch 'master'
62
+ end
63
+
64
+ # Now, tag that commit with the new version!
65
+ create_tag('master', ENV['NEW_VERSION_NUMBER'], "Updating version to #{ENV['NEW_VERSION_NUMBER']}")
66
+ end
67
+ end
68
+
69
+ # Here's an example job that runs something in jenkins.
70
+ job 'run_in_jenkins', 'Run a job in jenkins and make sure it passes' do
71
+ # The jenkins block takes arguments to configure an existing job, you have
72
+ # to at least specify a job name, and then everything else should be
73
+ # configured through parameters.
74
+ jenkins do
75
+ # This tells the job to run a job in jenkins named 'robopigoen-test'
76
+ name 'robopigeon-test'
77
+ # This tells it to set a parameter called 'BRANCH' to the branch from gitlab ci
78
+ param 'BRANCH', ENV['CI_COMMIT_REF_NAME']
79
+ end
80
+ # At this point the job will execute and then output the log to standard out so
81
+ # so you can keep a consistent log
82
+ end
83
+
34
84
  job 'deploy_complete', 'Notify slack and comment in gitlab that a deploy is complete' do
35
85
  # This configures a slack notification, at the end of the block it sends to
36
86
  # the users and channels in the body. Un-comment the channels and fill in the
@@ -109,11 +159,16 @@ job 'create ticket' do
109
159
  # Print out the ticket number for logging/deubgging
110
160
  puts 'Created ticket:'
111
161
  print_id
162
+
163
+ # This transitions the ticket using a transition called 'Start Work'
164
+ transition 'Start Work'
112
165
  end
113
166
  end
114
167
 
168
+ # Then it sends a notification in slack wit the link to the ticket
115
169
  slack do
116
170
  user ENV['GITLAB_USER_EMAIL']
171
+ # That helper gives you a slack formatted link for the jira ticket
117
172
  message "Created #{jira_last_created_ticket_slack_link}"
118
173
  end
119
174
  end
@@ -25,7 +25,7 @@ module RoboPigeon::Dsl
25
25
  attachment[:title] = title
26
26
  end
27
27
 
28
- RoboPigeon::Documentarian.add_command('title_linke', block: %w[job slack attachment], params: [{ name: 'link', type: 'String', desc: 'a url', example: 'https://gitlab.com/robopigeon/robopigeon/pipelines' }], desc: 'Add a link to the title so that users can click on it')
28
+ RoboPigeon::Documentarian.add_command('title_linke', block: %w[job slack attachment], params: [{ name: 'link', type: 'String', desc: 'a url', example: 'https://gitlab.com/pigeons/robopigeon/pipelines' }], desc: 'Add a link to the title so that users can click on it')
29
29
  def title_link(title_link)
30
30
  attachment[:title_link] = title_link
31
31
  end
@@ -46,7 +46,7 @@ module RoboPigeon::Dsl
46
46
  params: [
47
47
  { name: 'type', type: 'String', desc: 'Currently only supports `button`', example: 'button' },
48
48
  { name: 'text', type: 'String', desc: 'Field label', example: 'Pipeline' },
49
- { name: 'url', type: 'String', desc: 'Url to link to', example: 'https://gitlab.com/robopigeon/robopigeon/pipelines' },
49
+ { name: 'url', type: 'String', desc: 'Url to link to', example: 'https://gitlab.com/pigeons/robopigeon/pipelines' },
50
50
  { name: 'style', type: 'String', desc: 'button style, can be danger or primary', example: 'danger', defaut: 'nil' }
51
51
  ],
52
52
  desc: 'Add a Url linked button to your bot'
@@ -1,10 +1,5 @@
1
1
  module RoboPigeon::Dsl
2
- class SlackRoot
3
- def self.run(&block)
4
- slack = RoboPigeon::Dsl::SlackRoot.new
5
- slack.instance_eval(&block)
6
- end
7
-
2
+ class SlackRoot < RoboPigeon::Dsl::Base
8
3
  RoboPigeon::Documentarian.add_command(
9
4
  'enabled',
10
5
  block: ['slack'],
@@ -34,7 +29,6 @@ module RoboPigeon::Dsl
34
29
  end
35
30
 
36
31
  class Slack < SlackRoot
37
- include RoboPigeon::Dsl::Helpers
38
32
  attr_accessor :message
39
33
 
40
34
  def self.run(&block)
data/lib/robopigeon.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require 'robopigeon/documentarian'
2
2
  require 'robopigeon/dsl'
3
+ require 'robopigeon/extend'
3
4
  require 'robopigeon/git'
4
5
  require 'robopigeon/gitlab'
6
+ require 'robopigeon/jenkins'
5
7
  require 'robopigeon/jira'
6
8
  require 'robopigeon/markdown'
7
9
  require 'robopigeon/slack'