entitlements-github-plugin 0.4.0 → 0.4.2

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: c768cc8f03a6eae9aaf1350173a59274b53d51cb38b7df20e798ea2e49b049e9
4
- data.tar.gz: 1d66f2116e098a02cd81ca0f9a50c98995cda306ff3aceba0e2f37fc705f3b93
3
+ metadata.gz: 3c6ee79046e0d905bacf0c96d8dde4065be86a0e0c38c03b0056c90e9be33d16
4
+ data.tar.gz: 6ea93769603533deb1fff5e5dc91f7664483c1c2021d1a3836679cbfab11512d
5
5
  SHA512:
6
- metadata.gz: 47b00156083eabe37d014eaccbca358c291e7c0ebd4d48f0da8225f347526fdd6cef79969ec152d14db258a8412dc4ab73b1aa35742cf904e135206c85cca51b
7
- data.tar.gz: c9f604456245070f5b6ff2dd89b63a16bd36f052f8b489aad4c72b0d85e06782789b5697099053e0f2176a90884c303b5c75e28c9d5c4fb2944267619fde5e25
6
+ metadata.gz: b9d1ea8afcd7139f51d85eee6286408fe98dbcd62913f79f944e9cb131c0b725774523ec08de86ad231f13e87c5f0371dfddcc72446c9648ac8907d97bf0ea29
7
+ data.tar.gz: 6b31074867e389095bc34c33bcfa94dc954f2e2bdcaef8230417f1dd64bec66a0acec7fc896d0a7464b2025cba1b2f8e8e6faab3a81f12be5e1b1feff7924a15
@@ -198,6 +198,23 @@ module Entitlements
198
198
  Entitlements.logger.info "CHANGE github_parent_team from #{existing_parent_team} to #{changed_parent_team} for #{existing_group.dn} in #{github.org}"
199
199
  end
200
200
  end
201
+
202
+ existing_maintainers = existing_group.metadata_fetch_if_exists("team_maintainers")
203
+ changed_maintainers = group.metadata_fetch_if_exists("team_maintainers")
204
+ if existing_maintainers != changed_maintainers
205
+ base_diff[:metadata] ||= {}
206
+ if existing_maintainers.nil? && !changed_maintainers.nil?
207
+ base_diff[:metadata][:team_maintainers] = "add"
208
+ Entitlements.logger.info "ADD github_team_maintainers #{changed_maintainers} to #{existing_group.dn} in #{github.org}"
209
+ elsif !existing_maintainers.nil? && changed_maintainers.nil?
210
+ base_diff[:metadata][:team_maintainers] = "remove"
211
+ Entitlements.logger.info "REMOVE (NOOP) github_team_maintainers #{existing_maintainers} from #{existing_group.dn} in #{github.org}"
212
+ else
213
+ base_diff[:metadata][:team_maintainers] = "change"
214
+ Entitlements.logger.info "CHANGE github_team_maintainers from #{existing_maintainers} to #{changed_maintainers} for #{existing_group.dn} in #{github.org}"
215
+ end
216
+ end
217
+
201
218
  base_diff
202
219
  end
203
220
 
@@ -104,6 +104,10 @@ module Entitlements
104
104
  end
105
105
  end
106
106
 
107
+ maintainers = teamdata[:members].select { |u| teamdata[:roles][u] == "maintainer" }
108
+ team_metadata = team_metadata || {}
109
+ team_metadata = team_metadata.merge({"team_maintainers" => maintainers.any? ? maintainers.join(",") : nil})
110
+
107
111
  team = Entitlements::Backend::GitHubTeam::Models::Team.new(
108
112
  team_id: teamdata[:team_id],
109
113
  team_name: team_identifier,
@@ -326,11 +330,12 @@ module Entitlements
326
330
  # team_slug - Identifier of the team to retrieve.
327
331
  #
328
332
  # Returns a data structure with team data.
329
- Contract String => { members: C::ArrayOf[String], team_id: Integer, parent_team_name: C::Or[String, nil] }
333
+ Contract String => { members: C::ArrayOf[String], team_id: Integer, parent_team_name: C::Or[String, nil], roles: C::HashOf[String => String] }
330
334
  def graphql_team_data(team_slug)
331
335
  cursor = nil
332
336
  team_id = nil
333
337
  result = []
338
+ roles = {}
334
339
  sanity_counter = 0
335
340
 
336
341
  while sanity_counter < 100
@@ -348,6 +353,7 @@ module Entitlements
348
353
  node {
349
354
  login
350
355
  }
356
+ role
351
357
  cursor
352
358
  }
353
359
  }
@@ -375,12 +381,17 @@ module Entitlements
375
381
  buffer = edges.map { |e| e.fetch("node").fetch("login").downcase }
376
382
  result.concat buffer
377
383
 
384
+ edges.each do |e|
385
+ role = e.fetch("role").downcase
386
+ roles[e.fetch("node").fetch("login").downcase] = role
387
+ end
388
+
378
389
  cursor = edges.last.fetch("cursor")
379
390
  next if cursor && buffer.size == max_graphql_results
380
391
  break
381
392
  end
382
393
 
383
- { members: result, team_id:, parent_team_name: }
394
+ { members: result, team_id:, parent_team_name:, roles: }
384
395
  end
385
396
 
386
397
  # Ensure that the given team ID actually matches up to the team slug on GitHub. This is in place
data/lib/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Entitlements
4
4
  module Version
5
- VERSION = "0.4.0"
5
+ VERSION = "0.4.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entitlements-github-plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub, Inc. Security Ops
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-29 00:00:00.000000000 Z
11
+ date: 2023-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: contracts