contribution-checker 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19182ad1d31baf01f0dc6d78e7d3ba7d3f992bcb
4
- data.tar.gz: a8f6d7d814d0637a965c93b43a98fe12465fecbe
3
+ metadata.gz: 861b8fcdc7200e4a0c0f2ac9a177a7cb5299e41d
4
+ data.tar.gz: 95cf9de9a6eb0f53e0060fa4740917d193349c96
5
5
  SHA512:
6
- metadata.gz: ecbddc0756b18773bb5be5ef195f2b96251b30bddd1b8c20b1291749a057a29fa23b9079bc0be43e0123974f2c552caec18432af88681f46a2a17be7fdbf3aee
7
- data.tar.gz: dcb17c150028c981d7939ecc53e9f8f1fc8c60512766387577f00aab4b53593b2f8f7486b668d33f5de3c6bb518348c67e8c3c8e99846c3ca237e9a60825b48a
6
+ metadata.gz: 92c9763dac3837ac574e7df2c3f9c3075d04f2934c437401f84dfe53c63c8ef597241d1ca47f0a5735e370df9a1bd5659ff82986fcdb892e9ef59b32b37814b0
7
+ data.tar.gz: 3115ca43d29d6a7b5ceb05db9c738a510a5529608df448d10858c9ad0c5c5df32135ef59a1c19be735950931d6f43cf7a385fb035c9bc6fb36415bf12eada2a6
data/README.md CHANGED
@@ -5,14 +5,15 @@ People :heart: GitHub Contributions. However, it's not always simple to tell why
5
5
  ## Usage
6
6
 
7
7
  ```ruby
8
+ require "contribution-checker"
9
+
8
10
  checker = ContributionChecker::Checker.new \
9
11
  :access_token => "<Your 40 char GitHub API token>",
10
12
  :commit_url => "https://github.com/user/repo/commit/sha"
11
- )
12
13
 
13
14
  checker.check
14
15
  => {
15
- :counted_as_contribution => true,
16
+ :contribution => true,
16
17
  :and_criteria => {
17
18
  :commit_in_valid_branch => true,
18
19
  :commit_in_last_year => true,
@@ -9,8 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["James Dennes"]
10
10
  spec.email = ["jdennes@gmail.com"]
11
11
  spec.summary = %q{Check whether a commit is counted as a contribution.}
12
- spec.description = %q{Check whether a GitHub commit is counted as a \
13
- contribution for a specific GitHub user.}
12
+ spec.description = %q{Check whether a GitHub commit is counted as a contribution for a specific GitHub user.}
14
13
  spec.homepage = ""
15
14
  spec.license = "MIT"
16
15
 
@@ -1,2 +1,3 @@
1
1
  require "contribution-checker/version"
2
+ require "contribution-checker/error"
2
3
  require "contribution-checker/checker"
@@ -31,7 +31,7 @@ module ContributionChecker
31
31
  #
32
32
  # @return [Hash] The return value takes the following form:
33
33
  # {
34
- # :counted_as_contribution => true,
34
+ # :contribution => true,
35
35
  # :and_criteria => {
36
36
  # :commit_in_valid_branch => true,
37
37
  # :commit_in_last_year => true,
@@ -46,12 +46,14 @@ module ContributionChecker
46
46
  # }
47
47
  # }
48
48
  def check
49
- parts = URI.parse(@commit_url).path.split("/")
50
- @nwo = "#{parts[1]}/#{parts[2]}"
51
- @sha = parts[4]
52
- @user = @client.user
49
+ @nwo, @sha = parse_commit_url @commit_url
50
+ begin
51
+ @commit = @client.commit @nwo, @sha
52
+ rescue Octokit::NotFound
53
+ raise ContributionChecker::InvalidCommitUrlError
54
+ end
53
55
  @repo = @client.repository @nwo
54
- @commit = @client.commit @nwo, @sha
56
+ @user = @client.user
55
57
 
56
58
  @commit_in_valid_branch = commit_in_valid_branch?
57
59
  @commit_in_last_year = commit_in_last_year?
@@ -79,6 +81,20 @@ module ContributionChecker
79
81
  }
80
82
  end
81
83
 
84
+ # Parses the commit URL provided.
85
+ #
86
+ # @return [Array] URL parts: nwo, sha
87
+ def parse_commit_url(url)
88
+ begin
89
+ parts = URI.parse(@commit_url).path.split("/")
90
+ nwo = "#{parts[1]}/#{parts[2]}"
91
+ sha = parts[4]
92
+ return nwo, sha
93
+ rescue
94
+ raise ContributionChecker::InvalidCommitUrlError
95
+ end
96
+ end
97
+
82
98
  # Checks whether the commit is in a valid branch. A valid branch is defined
83
99
  # as either the default branch of the repository, or the gh-pages branch.
84
100
  #
@@ -0,0 +1,10 @@
1
+ module ContributionChecker
2
+
3
+ # Error class to help us rescue from invalid commit URL input.
4
+ class InvalidCommitUrlError < StandardError
5
+ def initialize
6
+ super "Invalid commit URL provided"
7
+ end
8
+ end
9
+
10
+ end
@@ -1,3 +1,3 @@
1
1
  module ContributionChecker
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contribution-checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Dennes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-07 00:00:00.000000000 Z
11
+ date: 2014-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -52,9 +52,8 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: |-
56
- Check whether a GitHub commit is counted as a \
57
- contribution for a specific GitHub user.
55
+ description: Check whether a GitHub commit is counted as a contribution for a specific
56
+ GitHub user.
58
57
  email:
59
58
  - jdennes@gmail.com
60
59
  executables: []
@@ -69,6 +68,7 @@ files:
69
68
  - contribution-checker.gemspec
70
69
  - lib/contribution-checker.rb
71
70
  - lib/contribution-checker/checker.rb
71
+ - lib/contribution-checker/error.rb
72
72
  - lib/contribution-checker/version.rb
73
73
  homepage: ''
74
74
  licenses: