├── .gitignore ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── bin └── github_scouter ├── github_scouter.gemspec └── lib ├── github_scouter.rb └── github_scouter └── version.rb /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io 2 | 3 | ### Ruby ### 4 | *.gem 5 | *.rbc 6 | /.config 7 | /coverage/ 8 | /InstalledFiles 9 | /pkg/ 10 | /spec/reports/ 11 | /test/tmp/ 12 | /test/version_tmp/ 13 | /tmp/ 14 | 15 | ## Specific to RubyMotion: 16 | .dat* 17 | .repl_history 18 | build/ 19 | 20 | ## Documentation cache and generated files: 21 | /.yardoc/ 22 | /_yardoc/ 23 | /doc/ 24 | /rdoc/ 25 | 26 | ## Environment normalisation: 27 | /.bundle/ 28 | /lib/bundler/man/ 29 | 30 | # for a library or gem, you might want to ignore these files since the code is 31 | # intended to run in multiple environments; otherwise, check them in: 32 | # Gemfile.lock 33 | # .ruby-version 34 | # .ruby-gemset 35 | 36 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: 37 | .rvmrc 38 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in github_scouter.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Tomohiko Himura 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GithubScouter 2 | 3 | あなたのGitHub戦闘力を計測します。 4 | 5 | ## Installation 6 | 7 | Add this line to your application's Gemfile: 8 | 9 | ```ruby 10 | gem 'github_scouter' 11 | ``` 12 | 13 | And then execute: 14 | 15 | $ bundle 16 | 17 | Or install it yourself as: 18 | 19 | $ gem install github_scouter 20 | 21 | ## Usage 22 | 23 | $ github_scouter [github ID] 24 | 25 | ## Contributing 26 | 27 | 1. Fork it ( https://github.com/eiel/github_scouter/fork ) 28 | 2. Create your feature branch (`git checkout -b my-new-feature`) 29 | 3. Commit your changes (`git commit -am 'Add some feature'`) 30 | 4. Push to the branch (`git push origin my-new-feature`) 31 | 5. Create a new Pull Request 32 | 33 | ## Link 34 | 35 | * [解説記事](http://blog.eiel.info/blog/2014/09/13/github-scouter/) 36 | * [eiel/github_scouter](https://github.com/eiel/github_scouter) 37 | * [戦闘力 - 座駆動LT大会](https://speakerdeck.com/eiel/zhan-dou-li) 38 | * [座駆動LT大会](http://gbdaitokai.doorkeeper.jp/events/12940) 39 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | 3 | -------------------------------------------------------------------------------- /bin/github_scouter: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'github_scouter' 3 | 4 | name = ARGV[0] 5 | sc = GithubScouter::Scouter.new(name) 6 | GithubScouter::Printer.new(sc).put 7 | -------------------------------------------------------------------------------- /github_scouter.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'github_scouter/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "github_scouter" 8 | spec.version = GithubScouter::VERSION 9 | spec.authors = ["Tomohiko Himura"] 10 | spec.email = ["eiel.hal@gmail.com"] 11 | spec.summary = %q{calculate fighting power} 12 | spec.description = %q{calculate fighting power} 13 | spec.homepage = "https://github.com/eiel/github_scouter" 14 | spec.license = "MIT" 15 | 16 | spec.files = `git ls-files -z`.split("\x0") 17 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 18 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 19 | spec.require_paths = ["lib"] 20 | 21 | spec.add_dependency "octokit" 22 | 23 | spec.add_development_dependency "bundler", "~> 1.6" 24 | spec.add_development_dependency "rake", "~> 10.0" 25 | end 26 | -------------------------------------------------------------------------------- /lib/github_scouter.rb: -------------------------------------------------------------------------------- 1 | require "github_scouter/version" 2 | require 'octokit' 3 | 4 | class Array 5 | def sum 6 | reduce(0) { |a,n| a + n } 7 | end 8 | end 9 | 10 | module GithubScouter 11 | class Scouter 12 | def self.atk_base(repo) 13 | return 0 if repo.private 14 | fork = repo.forks_count 15 | start = repo.stargazers_count 16 | 17 | if repo.fork 18 | (fork + start).to_f / 10 19 | else 20 | 1 + (fork + 2) * + start 21 | end 22 | end 23 | 24 | def self.language_rank(repos) 25 | repos 26 | .map(&:language) 27 | .delete_if(&:nil?) 28 | .reduce(Hash.new(0)) { |a,lang| 29 | a[lang] += 1 30 | a 31 | }.sort_by { |key,value| 32 | -value 33 | } 34 | end 35 | 36 | def initialize(name) 37 | @name = name 38 | end 39 | 40 | def client 41 | options = { 42 | auto_paginate: true, 43 | access_token: ENV['GITHUB_ACCESS_TOKEN'], 44 | } 45 | @client ||= Octokit::Client.new(options) 46 | end 47 | 48 | def repos 49 | @repos ||= client.repositories(@name) 50 | end 51 | 52 | def starred 53 | @starred ||= client.starred(@name) 54 | end 55 | 56 | def orgs 57 | @args ||= client.organizations(@name) 58 | end 59 | 60 | def atk 61 | repos.map { |repo| Scouter.atk_base(repo) }.sum 62 | end 63 | 64 | def int 65 | rank = Scouter.language_rank(repos) 66 | lang = rank.size 67 | sum = 0 68 | rank.each_with_index do |h,i| 69 | value = h[1] 70 | sum += value / (lang - i) 71 | end 72 | lang * sum 73 | end 74 | 75 | def agi 76 | orgs.map do |org_id| 77 | org = client.organization(org_id.login) 78 | repo = org.public_repos 79 | members = client.organization_members(org.login).count 80 | (repo.to_f + members) 81 | end.sum 82 | end 83 | end 84 | 85 | class Printer 86 | def initialize(scouter) 87 | @scouter = scouter 88 | end 89 | 90 | def put 91 | power 92 | puts "" 93 | repos_rank 94 | puts "" 95 | starred_rank 96 | end 97 | 98 | def power 99 | atk = @scouter.atk 100 | int = @scouter.int 101 | agi = @scouter.agi 102 | params = [atk,int,agi] 103 | puts "戦闘力: %d" % params.sum 104 | puts 105 | puts "攻撃力: %d 知力: %d すばやさ: %d" % params 106 | end 107 | 108 | def repos_rank 109 | rank(@scouter.repos, "repositories") 110 | end 111 | 112 | def starred_rank 113 | rank(@scouter.starred, "starred") 114 | end 115 | 116 | def rank(repos,label) 117 | rank = Scouter.language_rank(repos) 118 | puts "# #{label} (#{repos.count})" 119 | puts "" 120 | rank[0..9].each_with_index do |(key,value),i| 121 | puts "#{i+1}. ".ljust(4) + key.ljust(20) + value.to_s 122 | end 123 | end 124 | end 125 | end 126 | -------------------------------------------------------------------------------- /lib/github_scouter/version.rb: -------------------------------------------------------------------------------- 1 | module GithubScouter 2 | VERSION = "0.0.1" 3 | end 4 | --------------------------------------------------------------------------------