robopigeon 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.gitlab-ci.yml +27 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +65 -0
  6. data/.ruby-version +1 -0
  7. data/.version +1 -0
  8. data/Gemfile +4 -0
  9. data/README.md +256 -0
  10. data/Rakefile +11 -0
  11. data/bin/console +14 -0
  12. data/bin/rake +29 -0
  13. data/bin/rspec +29 -0
  14. data/bin/rubocop +29 -0
  15. data/bin/setup +8 -0
  16. data/exe/robopigeon +22 -0
  17. data/lib/robopigeon/documentarian.rb +39 -0
  18. data/lib/robopigeon/dsl/helpers.rb +17 -0
  19. data/lib/robopigeon/dsl/initial_jobs.rb +36 -0
  20. data/lib/robopigeon/dsl/job.rb +34 -0
  21. data/lib/robopigeon/dsl.rb +46 -0
  22. data/lib/robopigeon/git/helper_dsl.rb +60 -0
  23. data/lib/robopigeon/git.rb +7 -0
  24. data/lib/robopigeon/gitlab/client.rb +42 -0
  25. data/lib/robopigeon/gitlab/dsl.rb +174 -0
  26. data/lib/robopigeon/gitlab/helper_dsl.rb +44 -0
  27. data/lib/robopigeon/gitlab/jira.rb +0 -0
  28. data/lib/robopigeon/gitlab/merge_request.rb +78 -0
  29. data/lib/robopigeon/gitlab.rb +29 -0
  30. data/lib/robopigeon/jira/client.rb +17 -0
  31. data/lib/robopigeon/jira/dsl.rb +81 -0
  32. data/lib/robopigeon/jira/helper_dsl.rb +24 -0
  33. data/lib/robopigeon/jira/ticket.rb +186 -0
  34. data/lib/robopigeon/jira/ticket_dsl.rb +155 -0
  35. data/lib/robopigeon/jira.rb +37 -0
  36. data/lib/robopigeon/markdown/helper_dsl.rb +73 -0
  37. data/lib/robopigeon/markdown.rb +11 -0
  38. data/lib/robopigeon/resources/initial_robopigeon.rb +156 -0
  39. data/lib/robopigeon/slack/attachments_dsl.rb +63 -0
  40. data/lib/robopigeon/slack/client.rb +46 -0
  41. data/lib/robopigeon/slack/dsl.rb +74 -0
  42. data/lib/robopigeon/slack/helper_dsl.rb +26 -0
  43. data/lib/robopigeon/slack/message.rb +35 -0
  44. data/lib/robopigeon/slack.rb +30 -0
  45. data/lib/robopigeon/version.rb +3 -0
  46. data/lib/robopigeon.rb +13 -0
  47. data/robopigeon +0 -0
  48. data/robopigeon.gemspec +47 -0
  49. data/robopigeon.rb +156 -0
  50. metadata +264 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fe9a65f475eff9c6c1204035fd2fa3acd934346e59b0562890fa787d70dd63eb
4
+ data.tar.gz: 62e54d559418f871ffb4e84a6bca22699f036653c75bf0433158fcdeef017d1e
5
+ SHA512:
6
+ metadata.gz: 19eb5edf119c685f46e81fda2829aae511627d69565a4452f5cad707b955521cf64ff6dd07aa450d7d164605813bd30819ef8547b108c10bd1d636df7a8a7ebc
7
+ data.tar.gz: 51583e67e7f97a049bc6f92649f34c91caa1aff8ccab8ed4a82b90dea97312e589d04291e881852ec030ebb20b9abd2d5d85a7b3c199c61c4a1de4eb2e24bf22
data/.gitignore ADDED
@@ -0,0 +1,16 @@
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
+
13
+ # Ignore this so that we get up to date stuff.
14
+ Gemfile.lock
15
+ .env
16
+ robopigeon-0.1.0.gem
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,27 @@
1
+ .rspec: &rspec
2
+ stage: test
3
+ script:
4
+ - bundle install
5
+ - ./bin/rspec
6
+
7
+ stages:
8
+ - test
9
+
10
+ Rspec:2.5:
11
+ <<: *rspec
12
+ image: ruby:2.5
13
+
14
+ Rspec:2.3:
15
+ <<: *rspec
16
+ image: ruby:2.3
17
+
18
+ Rspec:2.1:
19
+ <<: *rspec
20
+ image: ruby:2.1
21
+
22
+ Rubocop:
23
+ image: ruby:2.5
24
+ stage: test
25
+ script:
26
+ - bundle install
27
+ - ./bin/rubocop
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,65 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'db/**/*'
4
+ - 'Vagrantfile'
5
+ - 'vendor/**/*'
6
+ Style/SingleLineBlockParams:
7
+ Enabled: false
8
+ Style/MultilineBlockChain:
9
+ Enabled: false
10
+ Metrics/LineLength:
11
+ Enabled: false
12
+ Metrics/ClassLength:
13
+ Enabled: false
14
+ Documentation:
15
+ Enabled: false
16
+ Style/ClassAndModuleChildren:
17
+ Enabled: false
18
+ Metrics/ParameterLists:
19
+ Enabled: false
20
+ Style/CommentAnnotation:
21
+ Enabled: false
22
+ Style/GuardClause:
23
+ Enabled: false
24
+ Style/EachWithObject:
25
+ Enabled: false
26
+ Style/ExpandPathArguments:
27
+ Enabled: false
28
+ Metrics/CyclomaticComplexity:
29
+ Enabled: false
30
+ Metrics/PerceivedComplexity:
31
+ Enabled: false
32
+ Metrics/AbcSize:
33
+ Enabled: false
34
+ Metrics/MethodLength:
35
+ Enabled: false
36
+ Naming/AccessorMethodName:
37
+ Enabled: false
38
+ Style/SignalException:
39
+ Enabled: false
40
+ Style/RegexpLiteral:
41
+ Enabled: false
42
+ Style/Next:
43
+ Enabled: false
44
+ Lint/AssignmentInCondition:
45
+ Enabled: false
46
+ Style/PercentLiteralDelimiters:
47
+ Enabled: false
48
+ Layout/SpaceAroundEqualsInParameterDefault:
49
+ Enabled: false
50
+ Metrics/BlockLength:
51
+ Enabled: false
52
+ Style/FrozenStringLiteralComment:
53
+ Enabled: false
54
+ Layout/IndentHeredoc:
55
+ Enabled: false
56
+
57
+ # We use this to inject the dsl into the right file
58
+ Security/Eval:
59
+ Exclude:
60
+ - 'lib/robopigeon/dsl.rb'
61
+
62
+ # We use a single class variable to keep track of the documentation across
63
+ Style/ClassVars:
64
+ Exclude:
65
+ - 'lib/robopigeon/documentarian.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.3
data/.version ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in robopigeon.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,256 @@
1
+ # RoboPigeon
2
+
3
+ RoboPigeon is here to solve your CI problems. It's a set of tools that you can use to add complexity while simplfying your proccesses.
4
+
5
+ Some of the things it can do:
6
+
7
+ Send your team a slack notification when a job fails.
8
+
9
+ ## Sponsors
10
+
11
+ <a href="https://granicus.com/careers/"><img alt="Granicus" src="https://granicus.com/wp-content/uploads/2018/07/logo.svg" width="300"></a>
12
+
13
+ ## Installation
14
+
15
+ This Gem is developed against ruby 2.5, but is tested in CI against the latest versions of `2.1`, `2.3`, and `2.5`
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'robopigeon'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install robopigeon
30
+
31
+ ## Usage
32
+
33
+ Best way to get started is by running `robopigeon init` and having it write the default robopigeon.rb file.
34
+
35
+ Then, you can reference the DSL below to make changes to your file.
36
+
37
+ ## DSL Reference:
38
+ - [Helpers](#helpers)
39
+ - [Slack](#slack-1)
40
+ - [GitLab](#gitlab-1)
41
+
42
+ ### Helpers
43
+
44
+ Helpers can be used anywhere in your config! They're useful for things like looking up someone's slack username to mention it in an email, or looking up who's oncall via pagerduty!
45
+
46
+ #### Slack
47
+ ```ruby
48
+ slack_name_for 'Email or Name' # slack username just with the @ sign
49
+ slack_user_for 'Email or Name' # slack message formatted slack user
50
+ slack_user_group 'Group id' # slack message group mention with an id
51
+ ```
52
+
53
+ #### Git
54
+ ```ruby
55
+ git_committer_name # name of the person who made the last commit
56
+ git_committer_email # email address of the person who made the last commit
57
+ git_merger_name # name of the person who made the last merge
58
+ git_merger_email # email address of the person who made the last merge
59
+ git_branch_merged_source # source branch of the last merge
60
+ git_branch_merged_target # target branch of the last merge
61
+ ```
62
+
63
+ #### GitLab
64
+ ```ruby
65
+ deployment_sha 'environment name' # the current deployed sha for a given environment
66
+ deployment_ref 'environment name' # the current deploy ref for a given environment
67
+ deployment_shortlog 'environment name' # the shortlog comparison between head and an environment
68
+ ```
69
+
70
+ ### Slack
71
+
72
+ Here's an example of how to use the slack integration!
73
+
74
+ There are two basic parts of the slack integration, there's the top level with the api_key, bot name, and emoji icon. And the job configuration that let's you select channels, users, and specify the text and attachments.
75
+
76
+ ```ruby
77
+ slack do
78
+ api_key ENV['SLACK_API_KEY'] # Sets the api key, I like to set it as an env var, defaults to ENV['SLACK_API_KEY']
79
+ name 'RoboPigeon 9000' # The name that Slack displays in the chat
80
+ emoji ':robot:' # The emoji icon that the bot uses
81
+ end
82
+
83
+ job 'super basic' do
84
+ slack do
85
+ channel '#testing-slackbots'
86
+ text 'some information you want to relate'
87
+ end
88
+ end
89
+
90
+ job 'mention a user' do
91
+ slack do
92
+ channel '#testing-slackbots'
93
+ text "#{slack_user_for ENV['GITLAB_USER_EMAIL']} did something awesome!"
94
+ end
95
+ end
96
+
97
+ job 'test failed' do
98
+ slack do
99
+ channel '#testing-slackbots' # A channel to post the message to
100
+ channel '#testing-more-slackbots' # Another channel to post the message to
101
+ user 'someone@example.com' # A user that it also sends the message to
102
+ user 'someone-else@example.com' # Another user that it also sends the message to
103
+ text "Test on #{ENV['CI_MERGE_REQUEST_SOURCE_BRANCH_NAME']} has failed!"
104
+ attachment do
105
+ title 'Website'
106
+ title_link 'http://alex.ives.mn'
107
+ pretext 'Here is a button!'
108
+ color 'danger'
109
+ # Actions take type, text, url, and style
110
+ action 'button', 'Website', 'https://alex.ives.mn', 'danger'
111
+ end
112
+ end
113
+ end
114
+
115
+ job 'in a different workspace' do
116
+ slack do
117
+ api_key ENV['SLACK_KEY_FOR_SECOND_SPACE']
118
+ name 'SadBot 9000'
119
+ emoji ':sad-pigeon:'
120
+ channel '#testing-slackbots'
121
+ user 'someone@example.com'
122
+ text 'Sent to a different workspace'
123
+ end
124
+ end
125
+
126
+ job 'with complex attachments' do
127
+ slack do
128
+ user ENV['GITLAB_USER_EMAIL']
129
+ attachment do
130
+ color 'good'
131
+ fallback "Stuff is happening! <#{ENV['CI_PIPELINE_URL']}|Pipeline> <#{ENV['CI_PROJECT_URL']}|Project>"
132
+ action 'button', 'Pipeline', ENV['CI_PIPELINE_URL'], 'primary'
133
+ action 'button', 'Project', ENV['CI_PROJECT_URL'], 'primary'
134
+ end
135
+ attachment do
136
+ color 'danger'
137
+ fallback "Stuff is happening! <#{ENV['CI_PIPELINE_URL']}|Pipeline> <#{ENV['CI_PROJECT_URL']}|Project>"
138
+ action 'button', 'Bad Pipeline', ENV['CI_PIPELINE_URL'], 'danger'
139
+ action 'button', 'Bad Project', ENV['CI_PROJECT_URL']
140
+ end
141
+ end
142
+ end
143
+ ```
144
+
145
+ ### GitLab
146
+
147
+ ```ruby
148
+ gitlab do
149
+ api_url 'https://gitlab.example.com/api/v4' # api endpoint for your gitlab server, defaults to ENV['CI_API_V4_URL']
150
+ api_key ENV['GITLAB_API_KEY'] # api key for your gitlab server, defaults to ENV['GITLAB_API_KEY']
151
+ end
152
+
153
+ job 'comment on a merge request' do
154
+ gitlab do
155
+ branch ENV['CI_COMMIT_REF_NAME']
156
+ merge_request_comment 'This comment will appear on all merge requests for the current specified branch'
157
+ end
158
+ end
159
+ ```
160
+
161
+ ## Development
162
+
163
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
164
+
165
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
166
+
167
+ ## Contributing
168
+
169
+ Bug reports and pull requests are welcome on GitLab at https://gitlab.com/robopigeon/robopigeon.
170
+
171
+ ### Contributors
172
+
173
+ [Alex Ives](https://alex.ives.mn)
174
+ [Erik Braegelmann](https://gitlab.com/ebraegelmann)
175
+ [Bill Bushey](https://gitlab.com/wbushey)
176
+
177
+ ### History
178
+
179
+ RoboPigeon grew out of a tool at [Granicus](https://granicus.com) called `gitlab_tools`. As the company grew, the team that created it (the pigeon team) recognized the need for a more flexible tool, and thus robopigeon was born! We also realized that with more flexibility comes more usefulness to other people. Since we get so much from open source, we recognized this as an opportunity to give back.
180
+
181
+ ## Future Development
182
+
183
+ ### Features for 1.0
184
+
185
+ GitLab
186
+ - [x] Create, comment on, and merge merge requests
187
+ - [x] Get data from the gitlab deployments api as a helper
188
+ - [x] Add helpers to get a list of jira tickets since the provided deployment
189
+ - [x] Create Tag
190
+ - [ ] Create Commits
191
+
192
+ Semver Helpers
193
+ - [ ] Read a version from a file
194
+ - [ ] Update version files
195
+
196
+ Slack
197
+ - [x] Post notifications to channels or users
198
+ - [x] Post notifications with url button actions
199
+ - [ ] Post a notification and wait for a threaded response from an authorized user before continuing
200
+ - [ ] Post a notification and wait for a reaction from an authorized user before continuing
201
+
202
+ Jira
203
+ - [x] Create tickets in jira
204
+ - [x] Transition a ticket between states
205
+ - [x] Comment on tickets
206
+ - [x] Add fix version to ticket
207
+
208
+ Git
209
+ - [x] Add helpers to get information about changes since the last release
210
+
211
+ Jenkins
212
+ - [ ] Kick off and monitor a jenkins job until it is completed
213
+
214
+ Extensions
215
+ - [ ] Create basic example dsl extension gem template
216
+
217
+ ### Features for future version
218
+
219
+ GitLab
220
+ - [ ] Wait for a merge request to be ready to merge
221
+ - [ ] Kick off a pipeline
222
+ - [ ] Find a pipeline
223
+ - [ ] Wait on a pipeline until completion, failing if the pipeline fails
224
+ - [ ] Push subtree
225
+ - [ ] Create releases
226
+ - [ ] Create Issue
227
+ - [ ] Update issue tags
228
+ - [ ] Assign Issue
229
+
230
+ GitHub
231
+ - [ ] Create, comment on, and merge pull requests
232
+ - [ ] Create Tag
233
+ - [ ] Create Commits
234
+ - [ ] Create Release
235
+ - [ ] Push subtree
236
+ - [ ] Create Issue
237
+ - [ ] Update issue tags
238
+ - [ ] Assign Issue
239
+
240
+ Slack
241
+ - [ ] Migrate to block syntax for messages
242
+
243
+ Changelog
244
+ - [ ] Aggregates changes into log
245
+ - [ ] Helpers provide changes since last deployment
246
+
247
+ Extensions
248
+ - [ ] Default jobs extension
249
+ - [ ] Jira ticket configuration extension
250
+ - [ ] Slack action template
251
+
252
+ ### Technical Debt
253
+
254
+ - [x] Document all the dsl methods with RoboPigeon::Documentarian
255
+ - [x] Re-organize code into modules by subject (eg: git, slack, gitlab, jira, ect)
256
+ - [ ] Generate human readable documentation from RoboPigeon::Documentarian
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
7
+
8
+ task :generate_docs do
9
+ require 'robopigeon'
10
+ File.write('documentation.json', RoboPigeon::Documentarian.generate_docs)
11
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'robopigeon'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/rake ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path('../bundle', __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
+
29
+ load Gem.bin_path('rake', 'rake')
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path('../bundle', __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
+
29
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/rubocop ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path('../bundle', __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
+
29
+ load Gem.bin_path('rubocop', 'rubocop')
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/robopigeon ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'robopigeon'
4
+
5
+ def usage(bot)
6
+ bot.usage
7
+ exit 1
8
+ end
9
+
10
+ bot = RoboPigeon::Dsl::Root.new
11
+
12
+ unless ARGV[0]
13
+ puts 'Missing Job name'
14
+ usage(bot)
15
+ end
16
+
17
+ unless bot.job?(ARGV[0])
18
+ puts "Config does not have job named #{ARGV[0]}"
19
+ usage(bot)
20
+ end
21
+
22
+ bot.run(ARGV[0])
@@ -0,0 +1,39 @@
1
+ require 'json'
2
+
3
+ module RoboPigeon
4
+ module Documentarian
5
+ @@documents = {}
6
+
7
+ def self.add_block(name, **options)
8
+ block_desc = options[:desc]
9
+ helpers = options[:helpers] || false
10
+ document = get_document(block: options[:block], document: @@documents)
11
+ document[name] = {
12
+ block_desc: block_desc,
13
+ includes_helpers: helpers
14
+ }
15
+ document[name][:params] = options[:params] if options[:params]
16
+ end
17
+
18
+ def self.add_command(name, **options)
19
+ command_desc = options[:desc]
20
+ document = get_document(block: options[:block], document: @@documents)
21
+ document[name] = {
22
+ command_desc: command_desc
23
+ }
24
+ document[name][:params] = options[:params] if options[:params]
25
+ end
26
+
27
+ def self.generate_docs
28
+ JSON.pretty_generate(@@documents)
29
+ end
30
+
31
+ def self.get_document(**options)
32
+ block = options[:block]
33
+ document = options[:document]
34
+ return get_document(document: document[block.shift], block: block) unless block.empty?
35
+
36
+ document
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,17 @@
1
+ RoboPigeon::Documentarian.add_block('helpers', block: [], desc: 'A set of things available to all blocks')
2
+
3
+ module RoboPigeon::Dsl
4
+ module Helpers
5
+ RoboPigeon::Documentarian.add_command(
6
+ 'skip',
7
+ block: ['helpers'],
8
+ params: [
9
+ { name: 'reason', type: 'String', desc: 'reason you want to skip this job', example: 'not configured' }
10
+ ],
11
+ desc: 'abort a job that is incomplete, raise an exception with the reason'
12
+ )
13
+ def skip(reason)
14
+ raise SkippedJob, "Job is not complete: #{reason}"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,36 @@
1
+ module RoboPigeon::Dsl::InitialJobs
2
+ INITIAL_FILE = "#{File.dirname(__FILE__)}/../resources/initial_robopigeon.rb".freeze
3
+ # Used to pull in environment variables for things that are mostly set via dsl
4
+ def base
5
+ slack do
6
+ api_key ENV['SLACK_API_KEY']
7
+ end
8
+ gitlab do
9
+ api_url ENV['CI_API_V4_URL']
10
+ api_key ENV['GITLAB_API_KEY']
11
+ end
12
+ job 'version', '-v', 'Show version number' do
13
+ puts RoboPigeon::VERSION
14
+ end
15
+ end
16
+
17
+ def init_job
18
+ jobs['init'] = {
19
+ desc: 'Initialize a new robopigeon project',
20
+ action: proc do
21
+ FileUtils.cp(INITIAL_FILE, RoboPigeon::DEFAULT_FILE)
22
+ end
23
+ }
24
+ end
25
+
26
+ def init_help
27
+ this_job = {
28
+ desc: 'Show usage information',
29
+ action: proc do
30
+ usage
31
+ end
32
+ }
33
+ jobs['help'] = this_job
34
+ jobs['-h'] = this_job.merge(hidden: true)
35
+ end
36
+ end
@@ -0,0 +1,34 @@
1
+ RoboPigeon::Documentarian.add_block(
2
+ 'job',
3
+ params: [
4
+ { name: 'Name', type: 'String', desc: 'Name of the job', example: 'test_job' },
5
+ { name: 'Description', type: 'String', desc: 'String describing what the job does', example: 'This job tests out some stuff while notifying slack' }
6
+ ],
7
+ helpers: true,
8
+ block: [],
9
+ desc: 'A grouping of commands to run'
10
+ )
11
+
12
+ module RoboPigeon::Dsl
13
+ class Job
14
+ include RoboPigeon::Dsl::Helpers
15
+ end
16
+ end
17
+
18
+ module RoboPigeon::Dsl
19
+ class Root
20
+ def job(*args, &block)
21
+ this_job = {
22
+ desc: args.pop,
23
+ action: proc do
24
+ job = RoboPigeon::Dsl::Job.new
25
+ job.instance_eval(&block)
26
+ end
27
+ }
28
+ jobs[args.shift] = this_job
29
+ args.each do |arg|
30
+ jobs[arg] = this_job.merge(hidden: true)
31
+ end
32
+ end
33
+ end
34
+ end