code_review_notifier 0.1.2 → 0.1.3

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: e426f5dccd98b195d1c7293883395783661f4d2f7415bbef49dec86366c359ed
4
- data.tar.gz: 1bc90b0595fef06e71915280ae60abccb4b4f0210e5f5989b108f00c531f1d09
3
+ metadata.gz: d6de431ed11fa0855c6ed44e294a4b8a76bd69ad845c1ea9bfacdd9a326e0b66
4
+ data.tar.gz: 0b084e6c55eda7ee644232ad770ad2bde38b43f12c1bea6f209d2ebce816b6dd
5
5
  SHA512:
6
- metadata.gz: 3d04f2041ece20693f1111669c23d995173a7f463bbe40663de23542285c3610243aa099ad65a8f1dd9d14b45e930f332a74de89e25ec5dbb85a0cd6d644f05a
7
- data.tar.gz: 4b7f3b4e1193931f975f350d51f18b14e57094ca82991a9ebd1f759901d6fc1cfd23b3d46b4f86e6402b3183c6aaaef737673f7c7c3f4827829b65b54bc7133c
6
+ metadata.gz: 28eae7ef98c923678e89c54d3a23c73dd4ff649ce55fcb7ee9f51a80ea0e74e331aae31f878c432fdb6657e27f275afffce16001ffd5bdeb341f095235207f0c
7
+ data.tar.gz: b586a847bca12814d570e2f73ace4d5860cf144e0024ea503994cdc5846e489f88416f3b0847731a6feb6f40cc90714fa96aca2afb6f3c1ac17782ac44f9e175
@@ -2,7 +2,7 @@ require "io/console"
2
2
  require_relative "./api.rb"
3
3
  require_relative "./notifier.rb"
4
4
 
5
- SECONDS_BETWEEN_RUNS = 120
5
+ SECONDS_BETWEEN_RUNS = 90
6
6
  SECONDS_BETWEEN_NOTIFICATIONS = 5
7
7
 
8
8
  class CodeReviewNotifier
@@ -10,7 +10,7 @@ class CodeReviewNotifier
10
10
  system("mkdir -p ~/.code_review_notifier")
11
11
  system("brew bundle --file #{File.expand_path(File.dirname(__FILE__) + "/..")}/Brewfile")
12
12
 
13
- if args[0] == "--setup" || !Api.current_api.is_setup?
13
+ if args[0] == "--setup"
14
14
  print("What's the base URL? (i.e. https://gerrit.google.com) ")
15
15
  DB.save_setting("base_api_url", STDIN.gets.chomp, is_secret: false)
16
16
 
@@ -25,6 +25,18 @@ class CodeReviewNotifier
25
25
  DB.save_setting("account_id", STDIN.gets.chomp, is_secret: false)
26
26
 
27
27
  puts("All setup!")
28
+ puts
29
+ puts("It's recommended that you set this up as a system service with serviceman. Check it out here: https://git.rootprojects.org/root/serviceman")
30
+ puts("Set code_review_notifier to run on startup with `serviceman add --name code_review_notifier code_review_notifier`")
31
+ exit
32
+ end
33
+
34
+ if !Api.current_api.is_setup?
35
+ Notifier.notify("Missing Setup Info", "Run `code_review_notifier --setup` to setup.")
36
+ puts
37
+ puts("You must finish setup first by running with the `--setup` option.")
38
+ puts("`code_review_notifier --setup`")
39
+ exit
28
40
  end
29
41
  end
30
42
 
@@ -48,11 +60,11 @@ class CodeReviewNotifier
48
60
  code_change_activity.notified
49
61
  unless is_first_run
50
62
  puts("Notifying of change!")
51
- Notifier.notify(code_change_activity)
52
- sleep SECONDS_BETWEEN_NOTIFICATIONS
63
+ Notifier.notify_about_code_change(code_change_activity)
64
+ sleep(SECONDS_BETWEEN_NOTIFICATIONS)
53
65
  end
54
66
  end
55
- sleep SECONDS_BETWEEN_RUNS
67
+ sleep(SECONDS_BETWEEN_RUNS)
56
68
  end
57
69
  end
58
70
 
@@ -11,8 +11,13 @@ class GerritApi < BaseApi
11
11
  },
12
12
  follow_redirects: false
13
13
  })
14
- @token = res.headers["set-cookie"].match("GerritAccount=(.*?);")[1]
15
- raise "Your username or password is incorrect. Trying running `code_review_notifier --setup` again." if @token.nil?
14
+ set_cookie_header = res.headers["set-cookie"] || ""
15
+ @token = set_cookie_header.match("GerritAccount=(.*?);")&.to_a&.fetch(1)
16
+ if @token.nil?
17
+ Notifier.notify("Incorrect Credentials", "Trying running `code_review_notifier --setup` again.")
18
+ sleep(120)
19
+ exit
20
+ end
16
21
  end
17
22
 
18
23
  def self.all_code_changes
@@ -1,7 +1,7 @@
1
1
  require_relative './api.rb'
2
2
 
3
3
  class Notifier
4
- def self.notify(code_change_activity)
4
+ def self.notify_about_code_change(code_change_activity)
5
5
  code_change = code_change_activity.code_change
6
6
  id = code_change.id
7
7
  owner = code_change.owner
@@ -9,6 +9,23 @@ class Notifier
9
9
 
10
10
  message = code_change_activity.message
11
11
  author = code_change_activity.author
12
- system("/usr/local/bin/terminal-notifier -title '#{author}' -subtitle '#{owner}: #{subject}' -message '#{message}' -appIcon #{Api.current_api.favicon} -open '#{Api.current_api.code_change_url(code_change)}'")
12
+ notify(author, message, "#{owner}: #{subject}", Api.current_api.favicon, Api.current_api.code_change_url(code_change))
13
+ end
14
+
15
+ def self.notify(title, message, subtitle = nil, icon = nil, url = nil)
16
+ args = {
17
+ "title" => title,
18
+ "message" => message,
19
+ "subtitle" => subtitle,
20
+ "appIcon" => icon,
21
+ "open" => url
22
+ }
23
+ all_args = args.keys.reduce("") do |arg_string, key|
24
+ if args[key]
25
+ arg_string += " -#{key} '#{args[key]}'"
26
+ end
27
+ arg_string
28
+ end
29
+ system("/usr/local/bin/terminal-notifier #{all_args}")
13
30
  end
14
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_review_notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Grinstead
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-07 00:00:00.000000000 Z
11
+ date: 2020-07-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: kyleag@hey.com