buildkite_watcher 0.1.2 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92f00810d0e3273b6d330c28a75f3ece4b22fdcdd0870e53193a1f92578fb3be
4
- data.tar.gz: 47aeb03350b54192c6444e8ca480a3a7fbf1ce5c2110a73826c464442912a4d3
3
+ metadata.gz: 49e5ace8442bf5043f816ad8983b04dafdc2a67e513ee35d9703385dad3f942b
4
+ data.tar.gz: eeee2053038d3617b4a82ed59d26f9ae5da24ca87da6177decfdacb4b7a93877
5
5
  SHA512:
6
- metadata.gz: 36664edc82f91e7a5f3513c6b94c0d430779077fcda0925167b3f049990640e5dabebb39b3a9b268eacfb4d7e54e1e3e795491a420f85817fa27df8efd2681ca
7
- data.tar.gz: 20e64a2459e523d00b75e7f96fbc9c54d58b5a1b3ab761edf9563db55d75c08de48616eb1e8e4ed041361872f6a27d3a92f4dcf5f71d50e40fc4c4a6af0cf198
6
+ metadata.gz: c179d2c001aac24e272a48096f15a3879ee492281e9c4214ae918bf0697bb443a79ad8f49ed993bcfefb78d19f01ddb5acfc53a44b3b862c9b73163b823357ae
7
+ data.tar.gz: e8088ebfe9dbd715b7e0dec3af9f0a74febba99398a44c8f32d086c933951fb23161142dd37accfd709d693db81113c059ee5d06a1f1652048276d4173ad513b
@@ -1,16 +1,22 @@
1
- name: Ruby
1
+ name: CI
2
2
 
3
3
  on: [push,pull_request]
4
4
 
5
5
  jobs:
6
- build:
7
- runs-on: ubuntu-latest
6
+ buildtest:
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ os: [ubuntu-latest, macos-latest]
11
+ # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
12
+ ruby: [2.7, '3.0']
13
+ runs-on: ${{ matrix.os }}
8
14
  steps:
9
15
  - uses: actions/checkout@v2
10
16
  - name: Set up Ruby
11
17
  uses: ruby/setup-ruby@v1
12
18
  with:
13
- ruby-version: 3.0
19
+ ruby-version: ${{ matrix.ruby }}
14
20
  bundler-cache: true
15
21
  - name: Run the default task
16
22
  run: bundle exec rake
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.1.1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2021-07-20
4
+
5
+ - Changed notification title to use name of this gem
6
+
7
+ ## [0.2.0] - 2021-07-17
8
+
9
+ - Uses config files to store buildkite token and buildkite pipeline slug
10
+ - Prompts the user for token and buildkite slug when running for the first time
11
+ - Properly prints errors that are caught
12
+
3
13
  ## [0.1.0] - 2021-06-04
4
14
 
5
15
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,8 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- buildkite_watcher (0.1.2)
5
- rest-client (~> 2.1.0)
4
+ buildkite_watcher (0.3.1)
5
+ rest-client (~> 2.0)
6
+ tty-config (~> 0.5)
7
+ tty-link (~> 0.1)
8
+ tty-prompt (~> 0.23)
6
9
 
7
10
  GEM
8
11
  remote: https://rubygems.org/
@@ -14,16 +17,18 @@ GEM
14
17
  domain_name (0.5.20190701)
15
18
  unf (>= 0.0.5, < 1.0.0)
16
19
  http-accept (1.7.0)
17
- http-cookie (1.0.3)
20
+ http-cookie (1.0.4)
18
21
  domain_name (~> 0.5)
19
22
  method_source (1.0.0)
20
- mime-types (3.3.1)
23
+ mime-types (3.4.1)
21
24
  mime-types-data (~> 3.2015)
22
- mime-types-data (3.2021.0225)
25
+ mime-types-data (3.2022.0105)
23
26
  netrc (0.11.0)
24
27
  parallel (1.20.1)
25
28
  parser (3.0.1.1)
26
29
  ast (~> 2.4.1)
30
+ pastel (0.8.0)
31
+ tty-color (~> 0.5)
27
32
  pry (0.13.1)
28
33
  coderay (~> 1.1)
29
34
  method_source (~> 1.0)
@@ -69,10 +74,23 @@ GEM
69
74
  rubocop (~> 1.0)
70
75
  rubocop-ast (>= 1.1.0)
71
76
  ruby-progressbar (1.11.0)
77
+ tty-color (0.6.0)
78
+ tty-config (0.5.0)
79
+ tty-cursor (0.7.1)
80
+ tty-link (0.1.1)
81
+ tty-prompt (0.23.1)
82
+ pastel (~> 0.8)
83
+ tty-reader (~> 0.8)
84
+ tty-reader (0.9.0)
85
+ tty-cursor (~> 0.7)
86
+ tty-screen (~> 0.8)
87
+ wisper (~> 2.0)
88
+ tty-screen (0.8.1)
72
89
  unf (0.1.4)
73
90
  unf_ext
74
- unf_ext (0.0.7.7)
91
+ unf_ext (0.0.8.1)
75
92
  unicode-display_width (2.0.0)
93
+ wisper (2.0.1)
76
94
 
77
95
  PLATFORMS
78
96
  x86_64-darwin-19
@@ -89,4 +107,4 @@ DEPENDENCIES
89
107
  rubocop-rspec (~> 2.3.0)
90
108
 
91
109
  BUNDLED WITH
92
- 2.2.17
110
+ 2.2.22
data/README.md CHANGED
@@ -1,24 +1,37 @@
1
1
  # Buildkite Watcher
2
2
 
3
- Command line utility that continuously watches for the buildkite job running current git HEAD and notifies on build status changes.
3
+ [![Gem Version](https://badge.fury.io/rb/buildkite_watcher.svg)](https://badge.fury.io/rb/buildkite_watcher)
4
+ [![CI Status](https://github.com/nulogy/buildkite_watcher/workflows/CI/badge.svg?branch=main)](https://github.com/nulogy/buildkite_watcher/actions?query=workflow%3ACI)
5
+
6
+ It continuously watches the most recent buildkite job running the current git branch and notifies on build status changes.
7
+
8
+ ![Notification Screenshot](docs/notification_screenshot.png)
4
9
 
5
10
  ## Installation
6
11
 
7
12
  Run this command:
8
13
 
9
- $ gem install buildkite_watcher
14
+ gem install buildkite_watcher
10
15
 
11
16
  ## Usage
12
17
 
13
- From a directory in your project, run.
18
+ From your project's root directory, run:
14
19
 
15
- `$ bw `
20
+ bw
16
21
 
17
22
  ## Development
18
23
 
19
- 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.
24
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
25
+
26
+ To install this gem onto your local machine, run `bundle exec rake install`.
27
+
28
+ ### To release a new version
20
29
 
21
- 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+ 1. Update `CHANGELOG.md`
31
+ 1. Update the version number in `version.rb`
32
+ 1. Run `bundle install`
33
+ 1. Commit the changes
34
+ 1. Run `bundle exec rake release`
22
35
 
23
36
  ## Contributing
24
37
 
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  notifies on build status changes.
15
15
  MSG
16
16
 
17
- spec.required_ruby_version = ">= 2.7", "< 3.1"
17
+ spec.required_ruby_version = ">= 2.7"
18
18
 
19
19
  spec.metadata["source_code_uri"] = "https://github.com/nulogy/buildkite_watcher"
20
20
  spec.metadata["changelog_uri"] = "https://github.com/nulogy/buildkite_watcher/blob/main/CHANGELOG.md"
@@ -29,5 +29,8 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ["lib"]
31
31
 
32
- spec.add_dependency "rest-client", "~> 2.1.0"
32
+ spec.add_dependency "rest-client", "~> 2.0"
33
+ spec.add_dependency "tty-config", "~> 0.5"
34
+ spec.add_dependency "tty-link", "~> 0.1"
35
+ spec.add_dependency "tty-prompt", "~> 0.23"
33
36
  end
@@ -0,0 +1,12 @@
1
+ # How to create the API Access Token in Buildkite
2
+
3
+ 1. Go to [the New API Access Token page](https://buildkite.com/user/api-access-tokens/new) in Buildkite
4
+ 1. Add a description (e.g. buildkite_watcher)
5
+ 1. In "Organization Access", check the organization the pipeline is in.
6
+ 1. Check "Enable GraphQL API Access"
7
+ 1. Click "Create New API Access Token"
8
+ 1. Copy the new token
9
+
10
+ Example:
11
+
12
+ ![New API Access Token page](new_api_access_token_page.png)
Binary file
Binary file
@@ -0,0 +1,7 @@
1
+ # How to find the Buildkite Pipeline Slug
2
+
3
+ 1. Go to https://buildkite.com/ and log in
4
+ 1. On the home page, find the pipeline you want to watch
5
+ 1. The URL in the browser will give you the pipeline slug.
6
+
7
+ For Example, if you see https://buildkite.com/foo-corp/bar-pipeline, the pipeline slug is `foo-corp/bar-pipeline`
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BuildkiteWatcher
4
+ class Config
5
+ attr_reader :pipeline_slug, :buildkite_token
6
+
7
+ def initialize(config, secrets)
8
+ @pipeline_slug = config.fetch(:pipeline_slug)
9
+ @buildkite_token = secrets.fetch(:buildkite_token)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tty-config"
4
+ require "tty-link"
5
+ require "tty-prompt"
6
+ require "buildkite_watcher/config"
7
+
8
+ module BuildkiteWatcher
9
+ class ConfigLoader
10
+ CONFIG_FILE_NAME = ".buildkite_watcher"
11
+ SECRETS_FILE_NAME = ".buildkite_watcher_secrets"
12
+ EXTENSION = ".yml"
13
+
14
+ def self.load(config = TTY::Config.new, secrets = TTY::Config.new, prompt = TTY::Prompt.new)
15
+ new(config, secrets, prompt).load
16
+ end
17
+
18
+ def load
19
+ config.filename = CONFIG_FILE_NAME
20
+ config.extname = EXTENSION
21
+ config.append_path Dir.pwd
22
+ config.exist? ? config.read : generate_config_file
23
+
24
+ secrets.filename = SECRETS_FILE_NAME
25
+ config.extname = EXTENSION
26
+ secrets.append_path Dir.home
27
+
28
+ secrets.exist? ? secrets.read : generate_secrets_file
29
+
30
+ Config.new(config, secrets)
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :config, :secrets, :prompt
36
+
37
+ def initialize(config, secrets, prompt)
38
+ @config = config
39
+ @secrets = secrets
40
+ @prompt = prompt
41
+ end
42
+
43
+ def generate_config_file
44
+ prompt.ok("Welcome to Buildkite Watcher!")
45
+ prompt.say("I can't find the configuration file, so I'll generate one for you now.")
46
+ link_to_instructions =
47
+ TTY::Link.link_to("instructions", "https://github.com/nulogy/buildkite_watcher/blob/main/docs/pipeline_slug.md")
48
+ pipeline_slug = prompt.ask(<<~MSG)
49
+ What's the pipeline slug of the pipeline you want to watch? See #{link_to_instructions} if you don't know how to find the pipeline slug.
50
+ MSG
51
+ config.set(:pipeline_slug, value: pipeline_slug)
52
+ config.write(create: true)
53
+ end
54
+
55
+ def generate_secrets_file
56
+ link_to_instructions =
57
+ TTY::Link.link_to("here", "https://github.com/nulogy/buildkite_watcher/blob/main/docs/buildkite_token.md")
58
+ link_to_new_token =
59
+ TTY::Link.link_to("New API Access token in Buildkite", "https://buildkite.com/user/api-access-tokens/new")
60
+
61
+ # We use #chop as a work around for a defect in TTY::Prompt that reprints prompt on every character
62
+ # entered
63
+ buildkite_token = prompt.mask(<<~MSG.chop)
64
+ Create a #{link_to_new_token}.
65
+ Make sure it has Organization and GraphQL API Access (more detailed instructions #{link_to_instructions}), and paste the token here:
66
+ MSG
67
+ secrets.set(:buildkite_token, value: buildkite_token)
68
+ secrets.write(create: true)
69
+ end
70
+ end
71
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BuildkiteWatcher
4
- VERSION = "0.1.2"
4
+ VERSION = "0.3.1"
5
5
  end
@@ -4,6 +4,7 @@ require "rainbow"
4
4
  require "rest-client"
5
5
  require "json"
6
6
  require "buildkite_watcher/version"
7
+ require "buildkite_watcher/config_loader"
7
8
 
8
9
  # Command line utility that continuously watches for the buildkite job running current git HEAD and
9
10
  # notifies on build status changes.
@@ -72,6 +73,8 @@ module BuildkiteWatcher
72
73
  BUILD_UNKNOWN_STATUS = "UNKNOWN"
73
74
 
74
75
  def result_watch
76
+ config = ConfigLoader.load
77
+
75
78
  Signal.trap("SIGINT") do
76
79
  puts
77
80
  puts Rainbow("Program interrupt received. Exiting.").red
@@ -81,7 +84,7 @@ module BuildkiteWatcher
81
84
  previous_result = BUILD_UNKNOWN_STATUS
82
85
  loop do
83
86
  system("clear")
84
- new_result = result
87
+ new_result = result(config)
85
88
 
86
89
  maybe_notify(previous_result, new_result)
87
90
  previous_result = new_result
@@ -98,7 +101,7 @@ module BuildkiteWatcher
98
101
  # - current commit has a build, has passed
99
102
  # - current commit has a build, has failed
100
103
 
101
- def result
104
+ def result(config)
102
105
  puts Rainbow("Branch: ").bright + Rainbow(branch_name)
103
106
  puts Rainbow("HEAD ➜ ").bright + Rainbow(commit_hash)
104
107
  puts
@@ -106,13 +109,13 @@ module BuildkiteWatcher
106
109
  buildkite_query = {
107
110
  query: GRAPHQL_QUERY,
108
111
  variables: {
109
- pipelineSlug: pipeline_slug,
112
+ pipelineSlug: config.pipeline_slug,
110
113
  commitHash: commit_hash,
111
114
  branch: branch_name,
112
115
  },
113
116
  }
114
117
 
115
- builds = fetch_build_data(buildkite_query)
118
+ builds = fetch_build_data(buildkite_query, config)
116
119
  commit_hash_builds = simplify_builds_response_data(builds.commit_hash_builds)
117
120
  branch_builds = simplify_builds_response_data(builds.branch_builds)
118
121
 
@@ -152,7 +155,7 @@ module BuildkiteWatcher
152
155
  build.state
153
156
  rescue StandardError => e
154
157
  puts
155
- puts Rainbow("ERROR: #{e.message}\n#{e.backtrace}").red
158
+ puts Rainbow("ERROR: \n#{e.backtrace.reverse.join("\n")}\n#{e.message}").red
156
159
  end
157
160
 
158
161
  private
@@ -160,11 +163,12 @@ module BuildkiteWatcher
160
163
  def maybe_notify(previous_result, new_result)
161
164
  return if new_result == previous_result || previous_result == BUILD_UNKNOWN_STATUS
162
165
 
166
+ # You can find available sounds here: '/System/Library/Sounds'
163
167
  case new_result
164
168
  when BUILD_PASSED, BUILD_BLOCKED
165
- system('osascript -e \'display notification "CI PASSED" with title "CI Result Watch" sound name "Glass"\'')
169
+ system('osascript -e \'display notification "CI PASSED" with title "Buildkite Watcher" sound name "Glass"\'')
166
170
  when BUILD_FAILED
167
- system('osascript -e \'display notification "CI FAILED" with title "CI Result Watch" sound name "Basso"\'')
171
+ system('osascript -e \'display notification "CI FAILED" with title "Buildkite Watcher" sound name "Funk"\'')
168
172
  end
169
173
  end
170
174
 
@@ -172,13 +176,13 @@ module BuildkiteWatcher
172
176
  [BUILD_PASSED, BUILD_BLOCKED].include?(state)
173
177
  end
174
178
 
175
- def fetch_build_data(buildkite_query)
179
+ def fetch_build_data(buildkite_query, config)
176
180
  response =
177
181
  JSON.parse(
178
182
  RestClient.post(
179
183
  "https://graphql.buildkite.com/v1",
180
184
  buildkite_query.to_json,
181
- { Authorization: "Bearer #{buildkite_token}", content_type: :json },
185
+ { Authorization: "Bearer #{config.buildkite_token}", content_type: :json },
182
186
  ),
183
187
  object_class: OpenStruct,
184
188
  )
@@ -257,24 +261,26 @@ module BuildkiteWatcher
257
261
  puts
258
262
  puts Rainbow("#{failures.count} failures from these specs:").yellow
259
263
  puts
260
- failures.map(&:name).map { |name| /\[(\w+)\] (.*): .*/.match(name).captures }.group_by(&:first)
264
+ failures
265
+ .map(&:name)
266
+ .map { |name| /\[(\w+)\] (.*): .*/.match(name).captures }
267
+ .group_by(&:first)
261
268
  .each do |key, values|
262
- puts key
263
- values.map { |e| e[1] }.uniq.each do |failure_file|
264
- failure_file
265
- puts Rainbow(failure_file).red
269
+ puts key
270
+ values
271
+ .map { |e| e[1] }
272
+ .uniq
273
+ .each do |failure_file|
274
+ failure_file
275
+ puts Rainbow(failure_file).red
276
+ end
266
277
  end
267
- end
268
278
  end
269
279
 
270
280
  def fetch_failures(download_url)
271
281
  JSON.parse(RestClient.get(download_url), object_class: OpenStruct)
272
282
  end
273
283
 
274
- def pipeline_slug
275
- ENV.fetch("PIPELINE_SLUG")
276
- end
277
-
278
284
  def branch_name
279
285
  ENV.fetch("BRANCH_NAME", `git symbolic-ref --short HEAD`.strip)
280
286
  end
@@ -282,9 +288,5 @@ module BuildkiteWatcher
282
288
  def commit_hash
283
289
  ENV.fetch("COMMIT_HASH", `git rev-parse HEAD`.strip)
284
290
  end
285
-
286
- def buildkite_token
287
- @_buildkite_token ||= `cat ~/.buildkite_token`
288
- end
289
291
  end
290
292
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buildkite_watcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arturo Pie
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-07 00:00:00.000000000 Z
11
+ date: 2022-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -16,14 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.0
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.0
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tty-config
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tty-link
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: tty-prompt
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.23'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.23'
27
69
  description: |
28
70
  Command line utility that continuously watches for the buildkite job running current git HEAD and
29
71
  notifies on build status changes.
@@ -39,6 +81,7 @@ files:
39
81
  - ".rspec"
40
82
  - ".rubocop.yml"
41
83
  - ".rubocop_todo.yml"
84
+ - ".tool-versions"
42
85
  - CHANGELOG.md
43
86
  - Gemfile
44
87
  - Gemfile.lock
@@ -47,8 +90,14 @@ files:
47
90
  - bin/console
48
91
  - bin/setup
49
92
  - buildkite_watcher.gemspec
93
+ - docs/buildkite_token.md
94
+ - docs/new_api_access_token_page.png
95
+ - docs/notification_screenshot.png
96
+ - docs/pipeline_slug.md
50
97
  - exe/bw
51
98
  - lib/buildkite_watcher.rb
99
+ - lib/buildkite_watcher/config.rb
100
+ - lib/buildkite_watcher/config_loader.rb
52
101
  - lib/buildkite_watcher/version.rb
53
102
  homepage:
54
103
  licenses: []
@@ -64,16 +113,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
113
  - - ">="
65
114
  - !ruby/object:Gem::Version
66
115
  version: '2.7'
67
- - - "<"
68
- - !ruby/object:Gem::Version
69
- version: '3.1'
70
116
  required_rubygems_version: !ruby/object:Gem::Requirement
71
117
  requirements:
72
118
  - - ">="
73
119
  - !ruby/object:Gem::Version
74
120
  version: '0'
75
121
  requirements: []
76
- rubygems_version: 3.2.16
122
+ rubygems_version: 3.3.7
77
123
  signing_key:
78
124
  specification_version: 4
79
125
  summary: CLI utility that watches buildkite and notify on build status changes