Sha256: cb93f511f8ce3c9dbba2cfa829e2084500d30fc409b3fdbddd4724fb96d77927

Contents?: true

Size: 1.44 KB

Versions: 6

Compression:

Stored size: 1.44 KB

Contents

#!/usr/bin/env ruby

require "bundler/inline"
gemfile do
  source "https://rubygems.org"
  gem "multi_repo", require: "multi_repo/cli", path: File.expand_path("..", __dir__)
end

opts = Optimist.options do
  synopsis "Move a set of GitHub team members to an 'alumni' team."

  opt :users, "The users to make alumni.",     :type => :strings, :required => true
  opt :org,   "The org in which user belongs", :type => :string,  :required => true

  MultiRepo::CLI.common_options(self, :only => :dry_run)
end

class MultiRepo::MakeAlumni
  attr_reader :org, :dry_run, :github

  def initialize(org:, dry_run:, **_)
    @org     = org
    @dry_run = dry_run
    @github  = MultiRepo::Service::Github.new(dry_run: dry_run)
  end

  def run(user)
    progress = MultiRepo::CLI.progress_bar(teams.size + repos.size)

    github.add_team_membership(org, "alumni", user)
    progress.increment

    teams.each do |team|
      next if team == "alumni"

      github.remove_team_membership(org, team, user)
      progress.increment
    end

    repos.each do |repo|
      github.remove_collaborator(repo, user)
      progress.increment
    end

    progress.finish
  end

  private

  def teams
    @teams ||= github.team_names(org)
  end

  def repos
    @repos ||= github.client.org_repos(org).reject(&:archived?).map(&:full_name).sort
  end
end

make_alumni = MultiRepo::MakeAlumni.new(**opts)
opts[:users].each do |user|
  puts MultiRepo::CLI.header(user)
  make_alumni.run(user)
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
multi_repo-0.5.0 scripts/make_alumni
multi_repo-0.4.0 scripts/make_alumni
multi_repo-0.3.1 scripts/make_alumni
multi_repo-0.3.0 scripts/make_alumni
multi_repo-0.2.3 scripts/make_alumni
multi_repo-0.2.2 scripts/make_alumni