pivotoolz 2.0.0 → 2.1.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: 3bb165619a9f870e9bddf016cc7f848b0e4540469afa55815b73ecd72ec120b3
4
- data.tar.gz: ac122af7c59ba532b2db9c1c10b962a95c8c4f8f5ca5f9553544aff1099ad3a5
3
+ metadata.gz: bddb4abca5fa5bef9084bf7a5d9697109103262bf7546c9ae02791e534461d78
4
+ data.tar.gz: d430ec30c3256892dbb9161dc162f77ea9bc39baaa35d436a9b343dc27e790e2
5
5
  SHA512:
6
- metadata.gz: f62d291e64171cc4648046fd35fb5dbb45ed2a7959f2427adaceba71b92661b6890a81ae132fd9200ae73b21d434a1ad8ee36187d54ed78b8dfa30dd6095243c
7
- data.tar.gz: 6b776e7f9be4954b3fbab03c2d74cd3e97bb0e9809268815d7c591750d4e24832a6f99f9a92251a24afb5aa6024f048f384fab83b53aace6d9994652a27bc791
6
+ metadata.gz: a02757405371e02ef0a6fb4422f9031ac557af8e88ebeeb882c3b2fc233f481caff3ab0c5ba98ccc03f8fe8dbeb28e4fc54ebc24a7937d00b47a4ea56177c0b6
7
+ data.tar.gz: 79fa6a39627f7facc44923206742fa58f9294820d6247508d3f4e632957a82949f26ee8c2b689a1da64fc2ca0d89255976c994606fadddd0dbdc5296de0e816c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pivotoolz (1.3.0)
4
+ pivotoolz (2.1.0)
5
5
  rest-client (~> 2.0.2)
6
6
 
7
7
  GEM
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'open-uri'
4
+ require 'json'
5
+
6
+ BASE_URL = "https://stessa.atlassian.net/rest/api/2/issue/"
7
+
8
+ def get_story_info(story_id, flags = [])
9
+ return nil if story_id.empty?
10
+
11
+ begin
12
+ include_owner_names = flags.any? { |f| f == '--owners' || f == '-O' }
13
+ url = BASE_URL + "#{story_id}" + "/#{include_owner_names ? '?fields=:default,owners' : ''}"
14
+ open(
15
+ url,
16
+ 'Authorization' => "Basic #{ENV['JIRA_API_BASIC_AUTH_BASE64_ENCODED']}"
17
+ ).read
18
+ rescue StandardError => e
19
+ story_link = "https://stessa.atlassian.net/browse/#{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
+ })
25
+ end
26
+ end
27
+
28
+ flags = ARGV.reduce([]) do |reduced, a|
29
+ reduced << a if a.include?('--') || a.include?('-')
30
+ reduced
31
+ end
32
+
33
+ flags.each { |f| ARGV.delete f }
34
+
35
+ stream = ARGV.any? ? ARGV : ARGF
36
+
37
+ if stream == ARGF && $stdin.tty?
38
+ puts "Usage:\nget-story-info-from-jira-id STORY_ID\n"
39
+ puts " OR\n"
40
+ puts "echo STORY_ID | get-story-info-from-id"
41
+ puts " OR\n"
42
+ exit 1
43
+ end
44
+
45
+ infos = stream.reduce([]) do |reduced, story_id|
46
+ next reduced unless story_id && story_id =~ /\d+/
47
+ reduced << get_story_info(story_id.strip, flags)
48
+ end
49
+
50
+ puts infos.join("\n")
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'json'
4
+ require 'ostruct'
5
+
6
+ environment_tag = ARGV[0]&.strip
7
+ if environment_tag.nil? || environment_tag.empty?
8
+ puts "Usage: stories-deployed ENVIRONMENT"
9
+ exit 1
10
+ end
11
+
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
+
20
+ deployed_story_infos = `jira-story-ids-deployed #{environment_tag} | get-story-info-from-jira-id #{flags.join(' ')}`
21
+
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
29
+
30
+ json = {
31
+ title: story.fields['summary']&.strip,
32
+ title_link: "https://stessa.atlassian.net/browse/#{story.key}",
33
+ mrkdwn_in: ["text", "pretext", "footer"]
34
+ }
35
+
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
47
+
48
+ json.to_json
49
+ end
50
+
51
+ def story_owner_names(story, flags)
52
+ owners = story
53
+ .owners
54
+ .compact
55
+ .map { |o| OpenStruct.new(o).name }
56
+
57
+ if flags.include? '--bold-owners'
58
+ return to_sentence(owners.map { |o| "*#{o}*" })
59
+ end
60
+
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 ')
68
+ end
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
+
93
+ puts stories_deployed
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ environment_tag = ARGV[0]&.strip
4
+
5
+ if environment_tag.nil? || environment_tag.empty?
6
+ puts "Usage: story-ids-deployed ENVIRONMENT"
7
+ exit 1
8
+ end
9
+
10
+ commit_range = `git tag -l #{environment_tag}* | tail -n 2 | tr '\n' ' ' | sed -e 's/ /../'`.strip
11
+
12
+ if commit_range.nil? || commit_range.empty?
13
+ puts "Empty commit range! Are there any commits tagged with #{environment_tag}?"
14
+ exit 1
15
+ end
16
+
17
+ commit_message_bodies = `git log --pretty="%h %s" #{commit_range}`.strip
18
+ story_ids = commit_message_bodies.
19
+ # TODO: Make this configurable
20
+ scan(/(DI-\d+|ST-\d+)/).
21
+ flatten.
22
+ compact.
23
+ uniq
24
+
25
+ puts story_ids.join("\n")
@@ -1,3 +1,3 @@
1
1
  module Pivotoolz
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.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: 2.0.0
4
+ version: 2.1.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: 2019-11-28 00:00:00.000000000 Z
11
+ date: 2019-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -75,6 +75,9 @@ executables:
75
75
  - deliver-deployed-stories
76
76
  - deliver-story
77
77
  - get-story-info-from-id
78
+ - get-story-info-from-jira-id
79
+ - jira-stories-deployed
80
+ - jira-story-ids-deployed
78
81
  - merge
79
82
  - post-slack-message
80
83
  - pv-git-branch
@@ -104,6 +107,9 @@ files:
104
107
  - exe/deliver-deployed-stories
105
108
  - exe/deliver-story
106
109
  - exe/get-story-info-from-id
110
+ - exe/get-story-info-from-jira-id
111
+ - exe/jira-stories-deployed
112
+ - exe/jira-story-ids-deployed
107
113
  - exe/merge
108
114
  - exe/post-slack-message
109
115
  - exe/pv-git-branch