Class: Entitlements::Backend::GitHubOrg::Service

Inherits:
Service::GitHub show all
Includes:
Contracts::Core
Defined in:
lib/entitlements/backend/github_org/service.rb

Constant Summary collapse

C =
::Contracts

Constants inherited from Service::GitHub

Service::GitHub::MAX_GRAPHQL_RESULTS, Service::GitHub::MAX_GRAPHQL_RETRIES, Service::GitHub::WAIT_BETWEEN_GRAPHQL_RETRIES

Instance Attribute Summary

Attributes inherited from Service::GitHub

#addr, #ignore_not_found, #org, #ou, #token

Instance Method Summary collapse

Methods inherited from Service::GitHub

#enterprise?, #identifier, #initialize, #invalidate_org_members_predictive_cache, #org_members, #org_members_from_predictive_cache?, #pending_members

Constructor Details

This class inherits a constructor from Entitlements::Service::GitHub

Instance Method Details

#sync(implementation, role) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/entitlements/backend/github_org/service.rb', line 19

def sync(implementation, role)
  added_members = []
  removed_members = []

  implementation.each do |instruction|
    username = Entitlements::Util::Util.first_attr(instruction[:person]).downcase
    if instruction[:action] == :add
      added_members << username if add_user_to_organization(username, role)
    else
      removed_members << username if remove_user_from_organization(username)
    end
  end

  Entitlements.logger.debug "sync(#{role}): Added #{added_members.count}, removed #{removed_members.count}"
  added_members.any? || removed_members.any?
end