From bfeff90a91b668ca6669fcfca9c1b6c789139d65 Mon Sep 17 00:00:00 2001 From: InFinite Date: Tue, 29 Apr 2014 06:38:36 +0400 Subject: [PATCH] 1 task --- Gemfile.lock | 4 ++- bin/github-team-remover | 2 +- github-team-remover.gemspec | 1 + lib/remover.rb | 2 +- lib/remover/cli.rb | 7 ++++- lib/remover/configuration.rb | 2 +- lib/remover/out.rb | 46 ++++++++++++++++++++++++++++++ lib/remover/team.rb | 16 +++++++++++ spec/remover/cli_spec.rb | 33 +++++++++++++++++++++ spec/remover/configuration_spec.rb | 4 ++- spec/remover/team_spec.rb | 40 ++++++++++++++++++++++++++ 11 files changed, 151 insertions(+), 6 deletions(-) create mode 100644 lib/remover/out.rb create mode 100644 spec/remover/cli_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index e23a66f..ae5f841 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,6 +2,7 @@ PATH remote: . specs: github-team-remover (0.0.2) + colored octokit (~> 3.0) thor @@ -10,12 +11,13 @@ GEM specs: addressable (2.3.6) ast (1.1.0) + colored (1.2) diff-lcs (1.2.5) faraday (0.9.0) multipart-post (>= 1.2, < 3) json (1.8.1) multipart-post (2.0.0) - octokit (3.0.0) + octokit (3.1.0) sawyer (~> 0.5.3) parser (2.1.7) ast (~> 1.1) diff --git a/bin/github-team-remover b/bin/github-team-remover index 4cd975d..8a72482 100755 --- a/bin/github-team-remover +++ b/bin/github-team-remover @@ -1,5 +1,5 @@ #!/usr/bin/env ruby - +require 'bundler/setup' require 'rubygems' require 'remover' diff --git a/github-team-remover.gemspec b/github-team-remover.gemspec index 90f5aaa..27a96df 100644 --- a/github-team-remover.gemspec +++ b/github-team-remover.gemspec @@ -21,6 +21,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'octokit', '~> 3.0' spec.add_dependency 'thor' + spec.add_dependency 'colored' spec.add_development_dependency 'rubocop' spec.add_development_dependency 'rspec', '~> 3.0.0.beta2' diff --git a/lib/remover.rb b/lib/remover.rb index 01155dc..253b9f0 100644 --- a/lib/remover.rb +++ b/lib/remover.rb @@ -1,10 +1,10 @@ require 'bundler/setup' - require 'remover/github' require 'remover/team' require 'remover/list' require 'remover/cli' require 'remover/configuration' +require 'remover/out' module Remover def self.configuration diff --git a/lib/remover/cli.rb b/lib/remover/cli.rb index 4d2a35c..ec6aa30 100644 --- a/lib/remover/cli.rb +++ b/lib/remover/cli.rb @@ -5,6 +5,7 @@ class CLI < Thor method_option :organization, required: true method_option :login, required: true method_option :password, required: true + method_option :verbose, desc: 'Information about repositories and members' desc('list', 'List unused teams') @@ -12,7 +13,7 @@ def list Remover.configuration.load_from_options!(options) Remover::List.new(github).unused_teams.each do |team| - puts team.name + Remover::Out.new(team, verbose?).out_list end end @@ -30,5 +31,9 @@ def octokit password: Remover.configuration.password ) end + + def verbose? + true if options[:verbose] + end end end diff --git a/lib/remover/configuration.rb b/lib/remover/configuration.rb index 4495f6d..3df1693 100644 --- a/lib/remover/configuration.rb +++ b/lib/remover/configuration.rb @@ -1,6 +1,6 @@ module Remover class Configuration - OPTIONS = %i(organization login password) + OPTIONS = %i(organization login password verbose) attr_accessor(*OPTIONS) diff --git a/lib/remover/out.rb b/lib/remover/out.rb new file mode 100644 index 0000000..f8601bd --- /dev/null +++ b/lib/remover/out.rb @@ -0,0 +1,46 @@ +require 'colored' + +module Remover + class Out + attr_accessor :team, :verbose + + def initialize(team, verbose) + @team, @verbose = team, verbose + end + + def team_name + puts "Team name: #{team.name}".yellow + end + + def out_members_v + team.out_mem_v.each do |member| + puts "| | #{member.html_url}".cyan + end + end + + def out_members + puts "| Members: #{team.amt_mem}".blue + end + + def out_rep_v + team.out_rep_v.each do |repos| + puts "| | #{repos.html_url}".green + end + end + + def out_rep + puts "| Repositories: #{team.amt_rep}".red + end + + def out_list + puts '===========* *** *============' + team_name + out_members + out_members_v if verbose + out_rep + out_rep_v if verbose + puts '===========* *** *============' + puts '' + end + end +end diff --git a/lib/remover/team.rb b/lib/remover/team.rb index f8b8ac8..1010ef2 100644 --- a/lib/remover/team.rb +++ b/lib/remover/team.rb @@ -14,6 +14,22 @@ def name github_team.name end + def amt_mem + github_client.team_members(github_team.id).size + end + + def amt_rep + github_client.team_repositories(github_team.id).size + end + + def out_mem_v + github_client.team_members(github_team.id) + end + + def out_rep_v + github_client.team_repositories(github_team.id) + end + private def with_members? diff --git a/spec/remover/cli_spec.rb b/spec/remover/cli_spec.rb new file mode 100644 index 0000000..a63d0ca --- /dev/null +++ b/spec/remover/cli_spec.rb @@ -0,0 +1,33 @@ +describe Remover::CLI do + let(:options) do + { + 'organization' => 'MANasyrov2', + 'login' => 'InFinite', + 'password' => '000000', + 'verbose' => 'true' + } + end + + let(:configuration) { Remover::Configuration.new } + + describe '#verbose' do + before do + configuration.load_from_options!(options) + end + + context 'verbose not entered' do + let(:options) do { + 'verbose' => 'false' + } + end + + it 'returns false' do + expect(configuration.verbose).not_to eq('true') + end + end + + it 'returns true' do + expect(configuration.verbose).to eq('true') + end + end +end diff --git a/spec/remover/configuration_spec.rb b/spec/remover/configuration_spec.rb index b656109..6224887 100644 --- a/spec/remover/configuration_spec.rb +++ b/spec/remover/configuration_spec.rb @@ -3,7 +3,8 @@ { 'organization' => 'FlatSchool', 'login' => 'fs-school', - 'password' => '123456' + 'password' => '123456', + 'verbose' => 'true' } end @@ -18,6 +19,7 @@ expect(configuration.organization).to eq('FlatSchool') expect(configuration.login).to eq('fs-school') expect(configuration.password).to eq('123456') + expect(configuration.verbose).to eq('true') end end end diff --git a/spec/remover/team_spec.rb b/spec/remover/team_spec.rb index f666388..f4f738c 100644 --- a/spec/remover/team_spec.rb +++ b/spec/remover/team_spec.rb @@ -49,4 +49,44 @@ end end end + + describe '#amt_rep' do + before do + allow(github_client).to receive(:team_repositories) { [] } + end + + it 'returns repository amount' do + expect(team.amt_rep).to eq(github_client.team_repositories(github_team.id).size) + end + end + + describe '#out_rep_v' do + before do + allow(github_client).to receive(:team_repositories) { [] } + end + + it 'returns array (info about repositories)' do + expect(team.out_rep_v).to be_an(Array) + end + end + + describe '#amt_mem' do + before do + allow(github_client).to receive(:team_members) { [] } + end + + it 'returns members amount' do + expect(team.amt_mem).to eq(github_client.team_members(github_team.id).size) + end + end + + describe '#out_mem_v' do + before do + allow(github_client).to receive(:team_members) { [] } + end + + it 'returns array (info about members)' do + expect(team.out_mem_v).to be_an(Array) + end + end end