pivotoolz 1.1.1 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f01995a201c6863ea0092e1fb8e90180f052c37bf67f05e7af34219b49ba2a4
4
- data.tar.gz: 100679935679704c04051681210eee3af2993ff32855b749fa28d0bb46bcc7c3
3
+ metadata.gz: f675f23dd5b2e83db378e9088dc7c9d5f711d753eae8fd7f2676f9e003931b32
4
+ data.tar.gz: dfafce21e5efb57a2cb23ad0f459fcf82ab9e06ceec68e4af635ee09d7ddb63a
5
5
  SHA512:
6
- metadata.gz: 23980000eb71ad760bb81db5dfd2709a83ac4715b195306673468d4f723168ca5ba86a8ce9d662d7df3276dd2d4ed97a7f4d2ef36fd76148de13c515da563163
7
- data.tar.gz: fa6c9065e62ca7a240f05d55a3cadab5917b2700e9871ed54f1c61073cd3b821b0c2710e83b626ceaaa2075c16c492021805245f78548079680b0ec5d2ca1f87
6
+ metadata.gz: '09eaf5353a2232e96ff74158bb11459e6f3442814e85a7ca673c68b4085d37d471da0d2619657b6fc599a54219b131d4b8d9a1b55b0b836e00aae65561816026'
7
+ data.tar.gz: b5fdf1e1f8d610e9c52939db099687d8ecd275ba74e006ebde7d71881fd0f4bb0ca69905c2f19cfb3323c41fbfdbad4f06419b99c34e38312f5299028c270bc0
@@ -16,7 +16,12 @@ def get_story_info(story_id, flags = [])
16
16
  'X-TrackerToken' => ENV['PIVOTAL_TRACKER_API_TOKEN']
17
17
  ).read
18
18
  rescue StandardError => e
19
- JSON.generate({error: "could not get story info for story #{story_id}: #{e.message}\nstory info may be available at https://www.pivotaltracker.com/story/show/#{story_id}"})
19
+ story_link = "https://www.pivotaltracker.com/story/show/#{story_id}"
20
+
21
+ JSON.generate({
22
+ error: "Could not get story info for story #{story_id}: #{e.message}\n\nStory info may be available at #{story_link}",
23
+ story_link: story_link
24
+ })
20
25
  end
21
26
  end
22
27
 
@@ -9,6 +9,30 @@ channel = ARGV.shift
9
9
  content = ARGV.empty? ? ARGF.read : StringIO.new(ARGV.join("\n")).read
10
10
  exit 0 if content.empty?
11
11
 
12
+ begin
13
+ if attachments = JSON.parse(
14
+ "[#{content.split("\n").slice(1..-1).join(",")}]"
15
+ )
16
+ begin
17
+ RestClient.post(
18
+ URL,
19
+ payload: {
20
+ username: ENV['SLACKBOT_USERNAME'] || 'slackbot',
21
+ channel: channel,
22
+ text: content.split("\n")&.first || '',
23
+ attachments: attachments,
24
+ icon_emoji: ":ghost:"
25
+ }.to_json
26
+ )
27
+ rescue RestClient::Exceptions => e
28
+ puts "Error posting to slack #{e.message}:\n#{e.backtrace}"
29
+ end
30
+
31
+ exit 0
32
+ end
33
+ rescue JSON::ParserError => e
34
+ end
35
+
12
36
  begin
13
37
  RestClient.post(
14
38
  URL,
data/exe/stories-deployed CHANGED
@@ -10,30 +10,84 @@ if environment_tag.nil? || environment_tag.empty?
10
10
  end
11
11
 
12
12
  flags = ARGV.select { |a| a.include?('--') || a.include?('-') }
13
+
14
+ include_owners = flags
15
+ .any? { |f| f == '--owners' || f == '-O' }
16
+
17
+ format_as_json = flags
18
+ .any? { |f| f == '--json' || f == '-j' }
19
+
13
20
  deployed_story_infos = `story-ids-deployed #{environment_tag} | get-story-info-from-id #{flags.join(' ')}`
14
21
 
15
- stories_deployed = deployed_story_infos.split("\n").compact.reduce([]) do |reduced, story_info|
16
- story = OpenStruct.new(JSON.parse(story_info))
22
+ def as_json(story, include_owners, flags)
23
+ if story.error
24
+ return {
25
+ title: story.error,
26
+ title_link: story.story_link
27
+ }.to_json
28
+ end
17
29
 
18
- include_owner_names = flags.any? { |f| f == '--owners' || f == '-O' }
30
+ json = {
31
+ title: story.name&.strip,
32
+ title_link: story.url,
33
+ mrkdwn_in: ["text", "pretext", "footer"]
34
+ }
19
35
 
20
- reduced << "#{story.error}"
21
- reduced << "#{story.name&.strip}:\n#{story.url}"
36
+ if include_owners
37
+ if flags.include? '--owners-footer'
38
+ json.merge!(
39
+ footer: "\n\nBrought to you by: #{story_owner_names(story, flags)}"
40
+ )
41
+ else
42
+ json.merge!(
43
+ text: "\n\nBrought to you by: #{story_owner_names(story, flags)}"
44
+ )
45
+ end
46
+ end
22
47
 
23
- if include_owner_names
24
- owners = story
25
- .owners
26
- .compact
27
- .map { |o| OpenStruct.new(o).name }
48
+ json.to_json
49
+ end
28
50
 
29
- names_joined = owners.size > 2 ?
30
- "#{owners[0..-2].join(', ')} and #{owners.last}" :
31
- owners.join(' and ')
51
+ def story_owner_names(story, flags)
52
+ owners = story
53
+ .owners
54
+ .compact
55
+ .map { |o| OpenStruct.new(o).name }
32
56
 
33
- reduced << "\nBrought to you by: #{names_joined}"
57
+ if flags.include? '--bold-owners'
58
+ return to_sentence(owners.map { |o| "*#{o}*" })
34
59
  end
35
60
 
36
- reduced
61
+ to_sentence(owners)
62
+ end
63
+
64
+ def to_sentence(array)
65
+ array.size > 2 ?
66
+ "#{array[0..-2].join(', ')} and #{array.last}" :
67
+ array.join(' and ')
37
68
  end
38
69
 
70
+ stories_deployed = deployed_story_infos
71
+ .split("\n")
72
+ .compact
73
+ .reduce([]) do |reduced, story_info|
74
+ story = OpenStruct.new(JSON.parse(story_info))
75
+
76
+ if format_as_json
77
+ reduced << as_json(story, include_owners, flags)
78
+ next reduced
79
+ end
80
+
81
+ reduced << "#{story.error}"
82
+ next reduced if story.error
83
+
84
+ reduced << "#{story.name&.strip}:\n#{story.url}"
85
+
86
+ if include_owners
87
+ reduced << "\nBrought to you by: #{story_owner_names(story, flags)}"
88
+ end
89
+
90
+ reduced
91
+ end
92
+
39
93
  puts stories_deployed
@@ -1,3 +1,3 @@
1
1
  module Pivotoolz
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pivotoolz
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sufyan Adam
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-12 00:00:00.000000000 Z
11
+ date: 2018-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client