saddler-reporter-support-git 1.0.0 → 2.0.0

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
  SHA1:
3
- metadata.gz: 891a763e94e162a7a2e3473568f9a533940a11fd
4
- data.tar.gz: cdb847f5f0492954885e83572ef9e89a94990684
3
+ metadata.gz: c7ba3ee6e561109454cbb6c3950b6d47765185c3
4
+ data.tar.gz: 7ec693a4ed2a65272a062ffa89fc9b6c35374a06
5
5
  SHA512:
6
- metadata.gz: fc0f7b5de524e134706b0e06982dd8f50b765649c7002fcc0c119c043fb5f01ae7a17346da61840076a135a8f413b6fa812cf4adcf69e98e895eb619f5ea26ad
7
- data.tar.gz: 114b78f556477601e19415ff869aa511eff1bd6556dbaf1dda6261e691f6228640cf57065935dc49ee474d0e568877408d9ec54410ea993ad628f7fa82f434d5
6
+ metadata.gz: 118874bdf3f7559dc161b7e3bdd61355d24f38e7fd078be7db146b2e8f1047cf420dd1e2cc3804dab6006edf1bde329b66c257192aaa49a16f3139f0ed8368ae
7
+ data.tar.gz: 0f9fbc34acce66de0be4396a34071a366418748317e3d8f9a96573992d7c41d307dafd7de2eb278fd046f6a436052872168dec78367f45714b1da28e9b7239a5
@@ -1,3 +1,20 @@
1
+ <a name="2.0.0"></a>
2
+ # [2.0.0](https://github.com/packsaddle/ruby-saddler-reporter-support-git/compare/v1.0.0...v2.0.0) (2016-05-14)
3
+
4
+ * Support GitHub pull request builder plugin for Jenkins users!
5
+
6
+
7
+ ### Bug Fixes
8
+
9
+ * **repository:** consider invalid object name([d96c1a9](https://github.com/packsaddle/ruby-saddler-reporter-support-git/commit/d96c1a9)), closes [#39](https://github.com/packsaddle/ruby-saddler-reporter-support-git/issues/39)
10
+
11
+
12
+ ### Features
13
+
14
+ * **repository:** add env_tracking_branch_name([9d0ba44](https://github.com/packsaddle/ruby-saddler-reporter-support-git/commit/9d0ba44))
15
+
16
+
17
+
1
18
  <a name="1.0.0"></a>
2
19
  # [1.0.0](https://github.com/packsaddle/ruby-saddler-reporter-support-git/compare/v0.3.0...v1.0.0) (2016-05-01)
3
20
 
data/README.md CHANGED
@@ -21,6 +21,14 @@
21
21
 
22
22
  `bundle exec yard server -r` and `open http://localhost:8808`.
23
23
 
24
+ ## Confirmed
25
+
26
+ We confirm this gem on
27
+
28
+ * Travis-ci
29
+ * Circle CI
30
+ * GitHub pull request builder plugin (Jenkins)
31
+
24
32
 
25
33
  ## Changelog
26
34
 
@@ -4,8 +4,11 @@ require 'env_branch'
4
4
  require 'saddler/reporter/support/git/version'
5
5
  require 'saddler/reporter/support/git/repository'
6
6
 
7
+ # saddler
7
8
  module Saddler
9
+ # saddler reporter
8
10
  module Reporter
11
+ # saddler reporter support
9
12
  module Support
10
13
  # Git support utility for saddler-reporter
11
14
  module Git
@@ -2,6 +2,9 @@ module Saddler
2
2
  module Reporter
3
3
  module Support
4
4
  module Git
5
+ # No tracking branch name
6
+ class NoTrackingBranchNameError < ArgumentError; end
7
+
5
8
  # Git repository support utility for saddler-reporter
6
9
  class Repository
7
10
  attr_reader :git
@@ -61,20 +64,38 @@ module Saddler
61
64
  def merging_object
62
65
  return head unless merge_commit?(head)
63
66
  commit = head.parents.select do |parent|
64
- ![tracking.sha, origin_tracking.sha].include?(parent.sha)
67
+ ![dig_sha(tracking), dig_sha(origin_tracking)].compact.include?(parent.sha)
65
68
  end
66
69
  return commit.last if commit.count == 1
67
70
  head # fallback
68
71
  end
69
72
 
70
- # @return [::Git::Object] git object for `tracking_branch_name`
73
+ # @return [::Git::Branches] git branches
74
+ def git_branches
75
+ @git_branches ||= @git.branches
76
+ end
77
+
78
+ # @return [::Git::Object, nil] git object for `tracking_branch_name`
71
79
  def tracking
72
- @git.object(tracking_branch_name)
80
+ target = tracking_branch_name
81
+ return unless git_branches[target]
82
+
83
+ @git.object(target)
73
84
  end
74
85
 
75
- # @return [::Git::Object] git object for `origin/tracking_branch_name`
86
+ # @param target [#sha]
87
+ #
88
+ # @return [String, nil] object's sha
89
+ def dig_sha(target)
90
+ target && target.sha
91
+ end
92
+
93
+ # @return [::Git::Object, nil] git object for `origin/tracking_branch_name`
76
94
  def origin_tracking
77
- @git.object("origin/#{tracking_branch_name}")
95
+ target = "origin/#{tracking_branch_name}"
96
+ return unless git_branches[target]
97
+
98
+ @git.object(target)
78
99
  end
79
100
 
80
101
  # @return [::Git::Config] git config instance
@@ -84,15 +105,34 @@ module Saddler
84
105
  @git.config
85
106
  end
86
107
 
108
+ # @return [String] tracking branch name
109
+ #
110
+ # @raise [NoTrackingBranchNameError] if there is no tracking branch name
111
+ def tracking_branch_name
112
+ @tracking_branch_name ||= begin
113
+ name = env_tracking_branch_name || git_tracking_branch_name
114
+ raise NoTrackingBranchNameError if !name || name.empty?
115
+ name
116
+ end
117
+ end
118
+
119
+ # @return [String, nil] tracking branch name from env
120
+ def env_tracking_branch_name
121
+ # GitHub pull request builder plugin (for Jenkins)
122
+ if ENV['ghprbTargetBranch'] && !ENV['ghprbTargetBranch'].empty?
123
+ ENV['ghprbTargetBranch']
124
+ end
125
+ end
126
+
87
127
  # @example tracking branch
88
128
  # # from git config
89
129
  # { "branch.spike/no-valid-master.merge" => "refs/heads/develop" }
90
130
  # => "develop"
91
131
  #
92
- # @return [String] tracking branch name
132
+ # @return [String, nil] tracking branch name
93
133
  #
94
134
  # @see http://stackoverflow.com/questions/4950725/how-do-i-get-git-to-show-me-which-branches-are-tracking-what
95
- def tracking_branch_name
135
+ def git_tracking_branch_name
96
136
  config
97
137
  .select { |k, _| /\Abranch.*merge\Z/ =~ k }
98
138
  .values
@@ -2,7 +2,8 @@ module Saddler
2
2
  module Reporter
3
3
  module Support
4
4
  module Git
5
- VERSION = '1.0.0'.freeze
5
+ # version
6
+ VERSION = '2.0.0'.freeze
6
7
  end
7
8
  end
8
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saddler-reporter-support-git
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sanemat
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-01 00:00:00.000000000 Z
11
+ date: 2016-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git