travis_dedup 0.3.0 → 0.4.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
  SHA1:
3
- metadata.gz: 14a0b42455ff794f353c282be857cd4cfe122656
4
- data.tar.gz: 57bbe0650d1551bcac0304bc2cb3084c167af4b0
3
+ metadata.gz: 04603ba6cc68114fb41abe32e6a7f13d17891d1e
4
+ data.tar.gz: 7efca7ec8c3752a5ed4db4801c8c0508cfbf740e
5
5
  SHA512:
6
- metadata.gz: 8de894c16503ccb38b9f7cc5aa3e3301f6734851ac5dbaa392fe4555b598c30608eb8a6b80b2bac2c6f3f10dd486075a09cc0c27af5b7bb808ffd30e7f9dd883
7
- data.tar.gz: 77dacb5de7e21bd0c52c2dda124d3ba45a30ab903d292d41262bd35b368ff78d7213fea5c1aadf331dfd7be297993c3b4f7b0f82ec3201936d6d78879d560417
6
+ metadata.gz: 5860acfa91d3c46a7e44bf7b5b97fda4a096cfc87991c57e019c51f22c389c0d004df4f0d4484d5ef7026a93bd7ed30bf53c15c1a76470810e069c61ba6a71bb
7
+ data.tar.gz: efef33df8b0cc3c3ebbd8f00dca972cd9941de7b240210a6e2579e64a504ad2326a469adb38043f4f24fa4013c5a00fd19b0a2628cabb41f642fae7ce76ce529
data/lib/travis_dedup.rb CHANGED
@@ -6,7 +6,7 @@ module TravisDedup
6
6
  ACTIVE = %w[created started queued]
7
7
 
8
8
  class << self
9
- attr_accessor :pro, :verbose
9
+ attr_accessor :pro, :verbose, :branches
10
10
 
11
11
  def cli(argv)
12
12
  parser = OptionParser.new do |opts|
@@ -19,6 +19,7 @@ module TravisDedup
19
19
  Options:
20
20
  BANNER
21
21
  opts.on("--pro", "travis pro") { self.pro = true }
22
+ opts.on("--branches", "dedup builds on branches too") { self.branches = true }
22
23
  opts.on("-h", "--help","Show this") { puts opts; exit }
23
24
  opts.on('-v', '--version','Show Version'){ require 'travis_dedup/version'; puts TravisDedup::VERSION; exit}
24
25
  end
@@ -63,19 +64,26 @@ module TravisDedup
63
64
  def duplicate_builds(builds)
64
65
  seen = []
65
66
  builds.select do |build|
66
- next unless pr = build.fetch("pull_request_number")
67
- if seen.include?(pr)
67
+ pr = build.fetch "pull_request_number"
68
+ branch = build.fetch "branch"
69
+
70
+ next if !pr && !branches
71
+
72
+ id = pr || branch
73
+ if seen.include?(id)
68
74
  true
69
75
  else
70
- seen << pr
76
+ seen << id
71
77
  false
72
78
  end
73
79
  end
74
80
  end
75
81
 
82
+ # see http://docs.travis-ci.com/api/#builds
76
83
  def active_builds(repo, access_token)
77
- request(:get, "repos/#{repo}/builds", {}, headers(access_token)).fetch("builds")
78
- .select { |b| ACTIVE.include?(b.fetch("state")) }
84
+ response = request(:get, "repos/#{repo}/builds", {}, headers(access_token))
85
+ builds = response.fetch("builds").select { |b| ACTIVE.include?(b.fetch("state")) }
86
+ builds.each { |build| build["branch"] = response.fetch("commits").detect { |c| c["id"] == build["commit_id"] }.fetch("branch") }
79
87
  end
80
88
 
81
89
  def headers(access_token)
@@ -1,3 +1,3 @@
1
1
  module TravisDedup
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: travis_dedup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-14 00:00:00.000000000 Z
11
+ date: 2015-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday