Class: Octorule::Services::Collaborators

Inherits:
Object
  • Object
show all
Defined in:
lib/octorule/services/collaborators.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Collaborators

Returns a new instance of Collaborators.



6
7
8
# File 'lib/octorule/services/collaborators.rb', line 6

def initialize(client)
  @client = client
end

Instance Method Details

#update(org, repo, desired_collaborators, dry_run: false) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/octorule/services/collaborators.rb', line 10

def update(org, repo, desired_collaborators, dry_run: false)
  current = fetch_collaborators(org, repo)
  current_usernames = current.map { |c| c[:username] }

  desired_collaborators.each do |collaborator|
    username = collaborator["username"]
    role = collaborator["role"]

    if current_usernames.include?(username)
      current_collab = current.find { |c| c[:username] == username }
      if current_collab[:role] != role
        update_role(org, repo, username, role, dry_run)
      end
    else
      add_collaborator(org, repo, username, role, dry_run)
    end
  end
end