github_streak_check 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/README.md +40 -0
- data/Rakefile +1 -0
- data/bin/github_streak_check +31 -0
- data/github_streak_check.gemspec +28 -0
- data/lib/github_streak_check/version.rb +3 -0
- data/lib/github_streak_check.rb +44 -0
- data/spec/github_streak_check_spec.rb +73 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3ad582344ff768d248778902ac303eb9128d2500
|
4
|
+
data.tar.gz: b892b48f3a5c2bb49835843e7660eeffbed5b348
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 777caa13d4a7825bee82c5f2942d7af0cbe91d01544e1273027008c415844f6eec6f4b1a4a75aca24c02b23a63314fb68035b696af80aac3ed032087a5f43c51
|
7
|
+
data.tar.gz: 3d338b36e18c921290ec0da6afa4c534c353865636edb2ddc6b2d69a5d2411aee2066a3c5692ec928359dc9a0fc94a26270c0c6708e721e546a17afc92a58c04
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# github_streak_check
|
2
|
+
|
3
|
+
GitHub's user page (eg. https://github.com/yhara) shows 'Longest Streak',
|
4
|
+
how many successive days the user is keep contributing.
|
5
|
+
|
6
|
+
This RubyGem provides a command to check if you have done today's
|
7
|
+
contribution and optionally send an email if not.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
$ gem i github_streak_check
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
$ github_streak_check GITHUB_USER_NAME
|
16
|
+
|
17
|
+
Exit with status 0 if already did contribution, with 1 otherwise.
|
18
|
+
|
19
|
+
### Sending alert mail
|
20
|
+
|
21
|
+
$ github_streak_check foo -m foo@example.com
|
22
|
+
|
23
|
+
This will send an notification to the given mail address.
|
24
|
+
github_streak_check uses [Pony](http://github.com/benprew/pony)'s default
|
25
|
+
way to send email; use /usr/sbin/sendmail if exists, then try to send with SMTP on localhost.
|
26
|
+
|
27
|
+
## Run test
|
28
|
+
|
29
|
+
$ bundle install
|
30
|
+
$ rspec
|
31
|
+
|
32
|
+
## Limitations
|
33
|
+
|
34
|
+
- Private repos are not supported
|
35
|
+
- Commits to forked repo are not counted [unless it is merged to main repo](https://help.github.com/articles/why-are-my-contributions-not-showing-up-on-my-profile), but github_streak_check returns OK for them, too
|
36
|
+
- Fetches only recent 300 events, so it may fail if you make over 300 commits a day.
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
MIT
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'github_streak_check'
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
opts = {}
|
6
|
+
option = OptionParser.new{|o|
|
7
|
+
o.banner = 'usage: github_streak_check USERNAME [options]'
|
8
|
+
|
9
|
+
o.on '-m', '--mail ADDRESS', 'Mail address to send notification(optional)' do |addr|
|
10
|
+
opts[:mail_to] = addr
|
11
|
+
end
|
12
|
+
o.on '-q', '--quiet', 'Supress message' do
|
13
|
+
$stdout = nil
|
14
|
+
$stderr = nil
|
15
|
+
end
|
16
|
+
o.on '-v', '--version', 'Show version' do
|
17
|
+
puts GithubStreakCheck::VERSION
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
o.on '-h', '--help', 'Show this message' do
|
21
|
+
puts o
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
}
|
25
|
+
rest = option.parse(ARGV)
|
26
|
+
unless (opts[:username] = rest[0])
|
27
|
+
puts option
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
|
31
|
+
GithubStreakCheck.new(opts).run
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'github_streak_check/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "github_streak_check"
|
8
|
+
spec.version = GithubStreakCheck::VERSION
|
9
|
+
spec.authors = ["Yutaka HARA"]
|
10
|
+
spec.email = ["yutaka.hara+github@gmail.com"]
|
11
|
+
spec.description = %q{Checks if you already done today's commit}
|
12
|
+
spec.summary = %q{Checks if you already done today's commit for GitHub's "Longest Streak" feature.}
|
13
|
+
spec.homepage = "https://github.com/yhara/github_streak_check"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_runtime_dependency "pony", "~> 1.5.1"
|
22
|
+
spec.add_runtime_dependency "activesupport", "~> 4.0.1"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec", "~> 2.14"
|
26
|
+
spec.add_development_dependency "fakeweb", "~> 1.3.0"
|
27
|
+
spec.add_development_dependency "timecop", "~> 0.6.3"
|
28
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "github_streak_check/version"
|
2
|
+
require 'open-uri'
|
3
|
+
require 'json'
|
4
|
+
require 'active_support/time'
|
5
|
+
require 'pony'
|
6
|
+
|
7
|
+
class GithubStreakCheck
|
8
|
+
def initialize(opts)
|
9
|
+
@opts = opts
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
if commited_today?
|
14
|
+
puts "Check OK: you've already done today(#{pst_today} PST)'s contribution."
|
15
|
+
exit 0
|
16
|
+
else
|
17
|
+
msg = "Check failed: You have not extended today(#{pst_today} PST)'s streak yet"
|
18
|
+
$stderr.puts msg
|
19
|
+
if (addr = @opts[:mail_to])
|
20
|
+
ret = Pony.mail(to: addr,
|
21
|
+
from: addr,
|
22
|
+
subject: "GithubStreakCheck",
|
23
|
+
body: msg)
|
24
|
+
puts "Sent mail: #{ret.inspect}"
|
25
|
+
end
|
26
|
+
exit 1
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def commited_today?
|
31
|
+
events = JSON.parse(open("https://api.github.com/users/#{@opts[:username]}/events?per_page=300").read)
|
32
|
+
return false if events.length == 0
|
33
|
+
|
34
|
+
return events.any?{|event|
|
35
|
+
Time.parse(event["created_at"]).to_date == pst_today
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def pst_today
|
42
|
+
@pst_today ||= ActiveSupport::TimeZone["Pacific Time (US & Canada)"].today
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'github_streak_check'
|
2
|
+
require 'fakeweb'
|
3
|
+
require 'timecop'
|
4
|
+
|
5
|
+
FakeWeb.allow_net_connect = false
|
6
|
+
|
7
|
+
describe GithubStreakCheck do
|
8
|
+
before do
|
9
|
+
@login = "taro"
|
10
|
+
@checker = GithubStreakCheck.new(username: @login)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#commited_today?" do
|
14
|
+
it "<no events> : false" do
|
15
|
+
FakeWeb.register_uri(:get,
|
16
|
+
"https://api.github.com/users/#{@login}/events?per_page=300",
|
17
|
+
body: "[]"
|
18
|
+
)
|
19
|
+
expect(@checker.commited_today?).to be_false
|
20
|
+
end
|
21
|
+
|
22
|
+
it "<yesterday's event> : false" do
|
23
|
+
FakeWeb.register_uri(:get,
|
24
|
+
"https://api.github.com/users/#{@login}/events?per_page=300",
|
25
|
+
body: '[{"created_at":"2013-11-04T10:47:16Z"}]'
|
26
|
+
# == "2013-11-04T02:47:16-08:00"
|
27
|
+
|
28
|
+
)
|
29
|
+
Timecop.freeze(Time.parse("2013-11-05T07:00:00-08:00")) do
|
30
|
+
expect(@checker.commited_today?).to be_false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "<today's event> : true" do
|
35
|
+
FakeWeb.register_uri(:get,
|
36
|
+
"https://api.github.com/users/#{@login}/events?per_page=300",
|
37
|
+
body: '[{"created_at":"2013-11-04T10:47:16Z"}]'
|
38
|
+
# == "2013-11-04T02:47:16-08:00"
|
39
|
+
|
40
|
+
)
|
41
|
+
Timecop.freeze(Time.parse("2013-11-04T07:00:00-08:00")) do
|
42
|
+
expect(@checker.commited_today?).to be_true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it "<today's event> <tomorrow's event> : true" do
|
47
|
+
FakeWeb.register_uri(:get,
|
48
|
+
"https://api.github.com/users/#{@login}/events?per_page=300",
|
49
|
+
body: '[{"created_at":"2013-11-05T10:47:16Z"},' +
|
50
|
+
# == "2013-11-05T02:47:16-08:00"
|
51
|
+
'{"created_at":"2013-11-04T10:47:16Z"}]'
|
52
|
+
# == "2013-11-04T02:47:16-08:00"
|
53
|
+
|
54
|
+
)
|
55
|
+
Timecop.freeze(Time.parse("2013-11-04T07:00:00-08:00")) do
|
56
|
+
expect(@checker.commited_today?).to be_true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Note: this happens when user is living in Tokyo, for example.
|
61
|
+
it "<tomorrow's event> : false" do
|
62
|
+
FakeWeb.register_uri(:get,
|
63
|
+
"https://api.github.com/users/#{@login}/events?per_page=300",
|
64
|
+
body: '[{"created_at":"2013-11-04T10:47:16Z"}]'
|
65
|
+
# == "2013-11-04T02:47:16-08:00"
|
66
|
+
|
67
|
+
)
|
68
|
+
Timecop.freeze(Time.parse("2013-11-03T07:00:00-08:00")) do
|
69
|
+
expect(@checker.commited_today?).to be_false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: github_streak_check
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yutaka HARA
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pony
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.5.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.5.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.0.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.0.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
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: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.14'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.14'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: fakeweb
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.3.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.3.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: timecop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.6.3
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.6.3
|
111
|
+
description: Checks if you already done today's commit
|
112
|
+
email:
|
113
|
+
- yutaka.hara+github@gmail.com
|
114
|
+
executables:
|
115
|
+
- github_streak_check
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- Gemfile
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- bin/github_streak_check
|
124
|
+
- github_streak_check.gemspec
|
125
|
+
- lib/github_streak_check.rb
|
126
|
+
- lib/github_streak_check/version.rb
|
127
|
+
- spec/github_streak_check_spec.rb
|
128
|
+
homepage: https://github.com/yhara/github_streak_check
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
metadata: {}
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - '>='
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 2.0.3
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: Checks if you already done today's commit for GitHub's "Longest Streak" feature.
|
152
|
+
test_files:
|
153
|
+
- spec/github_streak_check_spec.rb
|