pr_status 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 +10 -0
- data/.rspec +3 -0
- data/.travis.yml +8 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +21 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/pr_status.rb +3 -0
- data/lib/pr_status/auth.rb +54 -0
- data/lib/pr_status/client.rb +47 -0
- data/lib/pr_status/version.rb +3 -0
- data/pr_status.gemspec +23 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 507a82a813a008b5862fd9e7ba2d48aea1c8c28b
|
4
|
+
data.tar.gz: 2b92fd361e794466b50a3d19533af3958efc16c9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aac8a7a953f376acac9f11343baf4d9a966435f7d033199ee671cbce3dc6c927f9124b4d93d1cbbe37278c340fb5211dcbe971986693eb9edcef5a9f84320a84
|
7
|
+
data.tar.gz: 2654d631c2bad6b77f333095ff8c631570ab4b1dab3da8d418e8ba6b043859703a7c30971dc82f48492669cf69e3d36a3d86259874bcb4212ca79d10f27a933f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at zsyed91@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in pr_status.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem 'rake', '~> 10.1'
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem 'pry'
|
10
|
+
end
|
11
|
+
|
12
|
+
group :development do
|
13
|
+
gem 'rubocop'
|
14
|
+
end
|
15
|
+
|
16
|
+
group :test do
|
17
|
+
gem 'rspec'
|
18
|
+
gem 'rspec-mocks'
|
19
|
+
gem 'factory_girl'
|
20
|
+
gem 'faker'
|
21
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Zshawn Syed
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Zshawn Syed
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# PrStatus
|
2
|
+
|
3
|
+
Simple ruby class to get the count of pull requests open. Internally uses the `Octokit` wrapper.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'pr_status'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install pr_status
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Authentication
|
24
|
+
Pass in `access_token` or `login` and `password`.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
# Access token (generated from github.com)
|
28
|
+
client = PrStatus::Auth.new(access_token: '<40 char access token>').authenticate
|
29
|
+
|
30
|
+
# Username/Password
|
31
|
+
client = PrStatus::Auth.new(login: 'github_username', password: 'password').authenticate
|
32
|
+
```
|
33
|
+
|
34
|
+
### Getting pull request count
|
35
|
+
Returns the count of open and closed pull requests that have been opened by the authenticated user.
|
36
|
+
Defaults to searching from the first of the current month until today.
|
37
|
+
```ruby
|
38
|
+
client.pull_requests
|
39
|
+
```
|
40
|
+
|
41
|
+
#### Filters
|
42
|
+
You can filter the range that the client will search for pull requests by `created_at` date.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
client.pull_requests(range: 'monthly')
|
46
|
+
```
|
47
|
+
|
48
|
+
## Development
|
49
|
+
|
50
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
51
|
+
|
52
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/zsyed91/pr_status. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
57
|
+
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
62
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pr_status"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/pr_status.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module PrStatus
|
2
|
+
# Class to create the client wrapper around octokit
|
3
|
+
class Auth
|
4
|
+
# Credentials hash follows the octokit Client.new params:
|
5
|
+
# For username/password:
|
6
|
+
# login: username, password: password
|
7
|
+
#
|
8
|
+
# For api_token (recommended) since username/password is not even sent
|
9
|
+
# auth_token: <github auth token 40 chars>
|
10
|
+
def initialize(credentials)
|
11
|
+
unless credentials.is_a?(Hash)
|
12
|
+
fail ArgumentError, 'Need to pass in credentials hash'
|
13
|
+
end
|
14
|
+
@credentials = credentials
|
15
|
+
|
16
|
+
validate_credentials if username? || password?
|
17
|
+
if credentials[:access_token]
|
18
|
+
validate_access_token(credentials[:access_token])
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def authenticate
|
24
|
+
PrStatus::Client.new(@credentials)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def validate_access_token(token)
|
30
|
+
fail ArgumentError, 'Invalid Auth Token' unless token.length == 40
|
31
|
+
end
|
32
|
+
|
33
|
+
def validate_credentials
|
34
|
+
fail ArgumentError, 'Password missing' if !password?
|
35
|
+
fail ArgumentError, 'Username (:login) missing' if !username?
|
36
|
+
end
|
37
|
+
|
38
|
+
def username?
|
39
|
+
@credentials[:login] && !@credentials[:login].empty?
|
40
|
+
end
|
41
|
+
|
42
|
+
def password?
|
43
|
+
@credentials[:password] && !@credentials[:password].empty?
|
44
|
+
end
|
45
|
+
|
46
|
+
def credentials
|
47
|
+
if @credentials[:auth_token]
|
48
|
+
{ auth_token: @credentials[:auth_token] }
|
49
|
+
else
|
50
|
+
{ login: @credentials[:login], password: @credentials[:password] }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'octokit'
|
2
|
+
module PrStatus
|
3
|
+
# Client class for Octokit
|
4
|
+
# Holds an internal reference to Octokit::Client
|
5
|
+
# and other related methods for interacting with octokit's api wrapper
|
6
|
+
class Client
|
7
|
+
attr_accessor :user
|
8
|
+
def initialize(credentials)
|
9
|
+
@octokit = Octokit::Client.new(credentials)
|
10
|
+
# Cache the user info so we don't have to make another request
|
11
|
+
@user = @octokit.user
|
12
|
+
end
|
13
|
+
|
14
|
+
def pull_requests(filters = {})
|
15
|
+
filters = default_filters.merge(filters)
|
16
|
+
@octokit.search_issues(build_query(filters))[:total_count]
|
17
|
+
end
|
18
|
+
|
19
|
+
def repos
|
20
|
+
@repos ||= @octokit.repos
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def build_query(filters)
|
26
|
+
["author:#{@user[:login]}",
|
27
|
+
'type:pr',
|
28
|
+
"created:>=#{filter_date(filters)}"].join(' ')
|
29
|
+
end
|
30
|
+
|
31
|
+
def filter_date(filters)
|
32
|
+
time = Time.now
|
33
|
+
case filters[:range]
|
34
|
+
when 'monthly'
|
35
|
+
if time.month < 10
|
36
|
+
"#{time.year}-0#{time.month}-01"
|
37
|
+
else
|
38
|
+
"#{time.year}-#{time.month}-01"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def default_filters
|
44
|
+
{ range: 'monthly' }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/pr_status.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pr_status/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'pr_status'
|
8
|
+
spec.version = PrStatus::VERSION
|
9
|
+
spec.authors = ['Zshawn Syed']
|
10
|
+
spec.email = ['zsyed91@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Get the count of pull requests opened'
|
13
|
+
spec.description = 'Get the count of pull requests opened from the first of the month'
|
14
|
+
spec.homepage = 'https://github.com/zsyed91/pr_status'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_runtime_dependency('octokit', '~> 4.0')
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pr_status
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zshawn Syed
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-01 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: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
description: Get the count of pull requests opened from the first of the month
|
28
|
+
email:
|
29
|
+
- zsyed91@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".travis.yml"
|
37
|
+
- CODE_OF_CONDUCT.md
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- bin/console
|
44
|
+
- bin/setup
|
45
|
+
- lib/pr_status.rb
|
46
|
+
- lib/pr_status/auth.rb
|
47
|
+
- lib/pr_status/client.rb
|
48
|
+
- lib/pr_status/version.rb
|
49
|
+
- pr_status.gemspec
|
50
|
+
homepage: https://github.com/zsyed91/pr_status
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata: {}
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 2.4.5
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: Get the count of pull requests opened
|
74
|
+
test_files: []
|
75
|
+
has_rdoc:
|