github_daily_update 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDg5N2IyZWIzMzNkMzg4MDQyMzkzN2Q5NmQzYjJhN2E2MTJkNGRkOA==
5
+ data.tar.gz: !binary |-
6
+ NzMxODU1YzBjYmNkYzhiZmY0MGQ5MzAwYzcyYWUzZGMyNjNlNzczZQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZDA4N2IxNjY5MjA5ZmRmZGQ2OTc0OTBjNWFlYWM0N2E5NWNjMGM0N2RiZDVm
10
+ ZjQwNzc3Y2I4NTZkYjE0MmYxZTU0NmUyNDRjMjIzMjM3ZjkxMGZjZWJiMmYw
11
+ NTI5MmEwYmJmMjkxZTY0NDE4YjUyZDhkOTE0MDU1MTI3MGE3MDU=
12
+ data.tar.gz: !binary |-
13
+ ZDQ2ZDY2MDM3ZjJmOWIxNzE0ZGUxZDVmYmRmZjhjMjkxYjQwMTM2ZDcyYWY4
14
+ MjZlYzcwYmFiYWQ1ODI2MjYzYmI2Zjc1OWIyNjdiZjRjODc3MGE3ZGI0Mzdl
15
+ ODA1MWQ5OGYxNjliMWY2OGIwMWMxYzBiYzlmMGJhZWZmMWIzYjA=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ Encoding:
2
+ Enabled: false
3
+
4
+ LineLength:
5
+ Max: 80
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in github_daily_update.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jeremy Baker
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # GithubDailyUpdate
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'github_daily_update'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install github_daily_update
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/github_daily_update/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.pattern = "test/**/*test.rb"
7
+ end
8
+
9
+ task default: :test
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ def prompt(*args)
7
+ print(*args)
8
+ gets.chomp
9
+ end
10
+
11
+ if ENV['GITHUB_USERNAME'].nil?
12
+ ENV['GITHUB_USERNAME'] = prompt('GitHub Username: ')
13
+ end
14
+
15
+ if ENV['GITHUB_PASSWORD'].nil?
16
+ ENV['GITHUB_PASSWORD'] = prompt('GitHub Password: ')
17
+ end
18
+
19
+ if ENV['GITHUB_ORG'].nil?
20
+ ENV['GITHUB_ORG'] = prompt('GitHub Org: ')
21
+ end
22
+
23
+ require 'github_daily_update'
24
+
25
+ puts 'Generating Report...'
26
+ daily_update = GithubDailyUpdate::Report.new(org: ENV['GITHUB_ORG'])
27
+ puts daily_update.generate.join("\n")
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'github_daily_update/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'github_daily_update'
8
+ spec.version = GithubDailyUpdate::VERSION
9
+ spec.authors = ['Jeremy Baker']
10
+ spec.email = ['jhubert@gmail.com']
11
+ spec.summary = %q{Generates a daily report from the GitHub API}
12
+ spec.homepage = ''
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'octokit', '~> 2.0'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.5'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'minitest'
25
+ spec.add_development_dependency 'mocha'
26
+ end
@@ -0,0 +1,16 @@
1
+ # The main report generation class
2
+ class GithubDailyUpdate::Report
3
+ attr_accessor :reporters
4
+
5
+ def initialize(options = {})
6
+ client = ::Octokit::Client.new
7
+ @reporters = [
8
+ GithubDailyUpdate::Reporter::Merged.new(client, options),
9
+ GithubDailyUpdate::Reporter::OpenPulls.new(client, options)
10
+ ]
11
+ end
12
+
13
+ def generate
14
+ @reporters.map { |r| r.generate }
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ # A reporter is a class that generates a report
2
+ # based on the github api and some additional logic
3
+ module GithubDailyUpdate::Reporter
4
+ # The base class is the class that reporters extend. All common
5
+ # functionality should go here.
6
+ class Base
7
+ attr_reader :options
8
+
9
+ def initialize(client, options = {})
10
+ @client = client
11
+ @options = options
12
+ end
13
+
14
+ def generate
15
+ throw 'Generate method needs to be defined in the reporter'
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ # This reporter generates a list of all the pull-requests that have been
2
+ # merged in the last 24 hours.
3
+ class GithubDailyUpdate::Reporter::Merged < GithubDailyUpdate::Reporter::Base
4
+ def generate
5
+ output = "## Merge Report\n\n"
6
+ output += events(merged_pull_requests).join("\n")
7
+ output
8
+ end
9
+
10
+ private
11
+
12
+ def template
13
+ '- %s#%d: %s'
14
+ end
15
+
16
+ def events(pulls)
17
+ pulls.map do |p|
18
+ template % [p.repo.name, p.payload.number, p.payload.pull_request.title]
19
+ end
20
+ end
21
+
22
+ def merged_pull_requests
23
+ Octokit.organization_events(options[:org]).select do |e|
24
+ e.created_at > (Time.now - (60 * 60 * 24)) &&
25
+ e.type == 'PullRequestEvent' &&
26
+ e.payload.action == 'closed' &&
27
+ e.payload.pull_request.merged
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,32 @@
1
+ # This reporter generates a list of all the open pull-requests for an Org
2
+ class GithubDailyUpdate::Reporter::OpenPulls < GithubDailyUpdate::Reporter::Base
3
+ def generate
4
+ output = "## Open Pulls\n\n"
5
+ output += open_pull_requests.map { |pull| template % pull }.join("\n")
6
+ output
7
+ end
8
+
9
+ private
10
+
11
+ def template
12
+ '- %s#%d: %s'
13
+ end
14
+
15
+ def open_pull_requests
16
+ org_repositories.map do |repo|
17
+ open_pulls_in_repo(repo).map { |pull| extract_values(repo, pull) }
18
+ end.flatten(1)
19
+ end
20
+
21
+ def org_repositories
22
+ Octokit.organization_repositories(options[:org])
23
+ end
24
+
25
+ def open_pulls_in_repo(repo)
26
+ repo.rels[:pulls].get(state: 'open').data
27
+ end
28
+
29
+ def extract_values(repo, pull)
30
+ [repo.full_name, pull.number, pull.title]
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ require 'github_daily_update/reporters/base'
2
+ require 'github_daily_update/reporters/merged'
3
+ require 'github_daily_update/reporters/open_pulls'
@@ -0,0 +1,4 @@
1
+ # Use Semantic versioning
2
+ module GithubDailyUpdate
3
+ VERSION = '0.1.0'
4
+ end
@@ -0,0 +1,13 @@
1
+ require 'octokit'
2
+ require 'github_daily_update/version'
3
+ require 'github_daily_update/reporters'
4
+ require 'github_daily_update/report'
5
+
6
+ Octokit.auto_paginate = true
7
+ Octokit.configure do |c|
8
+ c.login = ENV['GITHUB_USERNAME']
9
+ c.password = ENV['GITHUB_PASSWORD']
10
+ end
11
+
12
+ module GithubDailyUpdate
13
+ end
data/test/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ Documentation:
2
+ Enabled: false
3
+
4
+ Encoding:
5
+ Enabled: false
6
+
7
+ LineLength:
8
+ Max: 120
@@ -0,0 +1,7 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ require 'minitest/autorun'
5
+ require 'mocha/mini_test'
6
+
7
+ Dir['lib/*rb'].each { |file| require_relative "../#{file}" }
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ class GithubDailyUpdate::ReportTest < Minitest::Test
4
+ def test_should_have_generate_method
5
+ reporter = GithubDailyUpdate::Report.new
6
+ assert reporter.respond_to? :generate
7
+ end
8
+
9
+ def test_includes_the_merged_reporter_by_default
10
+ klass = GithubDailyUpdate::Reporter::Merged
11
+ rep = GithubDailyUpdate::Report.new
12
+ assert rep.reporters.find { |r| r.class == klass }, 'Missing Reporter'
13
+ end
14
+
15
+ def test_includes_the_open_pulls_reporter_by_default
16
+ klass = GithubDailyUpdate::Reporter::OpenPulls
17
+ rep = GithubDailyUpdate::Report.new
18
+ assert rep.reporters.find { |r| r.class == klass }, 'Missing Reporter'
19
+ end
20
+
21
+ def test_generate_returns_output_of_all_reporters
22
+ GithubDailyUpdate::Reporter::Merged.any_instance.stubs(:generate).returns('1')
23
+ GithubDailyUpdate::Reporter::OpenPulls.any_instance.stubs(:generate).returns('2')
24
+ rep = GithubDailyUpdate::Report.new
25
+ assert_equal %w(1 2), rep.generate
26
+ end
27
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class GithubDailyUpdate::Reporter::BaseTest < Minitest::Test
4
+ def test_should_have_generate_method
5
+ reporter = GithubDailyUpdate::Reporter::Base.new('client')
6
+ assert reporter.respond_to? :generate
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github_daily_update
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Baker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - jhubert@gmail.com
86
+ executables:
87
+ - github-daily-update
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rubocop.yml
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/github-daily-update
98
+ - github_daily_update.gemspec
99
+ - lib/github_daily_update.rb
100
+ - lib/github_daily_update/report.rb
101
+ - lib/github_daily_update/reporters.rb
102
+ - lib/github_daily_update/reporters/base.rb
103
+ - lib/github_daily_update/reporters/merged.rb
104
+ - lib/github_daily_update/reporters/open_pulls.rb
105
+ - lib/github_daily_update/version.rb
106
+ - test/.rubocop.yml
107
+ - test/test_helper.rb
108
+ - test/unit/report_test.rb
109
+ - test/unit/reporter_test.rb
110
+ homepage: ''
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.1.11
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Generates a daily report from the GitHub API
134
+ test_files:
135
+ - test/.rubocop.yml
136
+ - test/test_helper.rb
137
+ - test/unit/report_test.rb
138
+ - test/unit/reporter_test.rb
139
+ has_rdoc: