Skip to content

Commit

Permalink
ContributionChecker::InvalidCommitUrlError to the rescue
Browse files Browse the repository at this point in the history
  • Loading branch information
jdennes committed Jun 8, 2014
1 parent f090f88 commit 5514532
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/contribution-checker.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
require "contribution-checker/version"
require "contribution-checker/error"
require "contribution-checker/checker"
26 changes: 21 additions & 5 deletions lib/contribution-checker/checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ def initialize(options = {})
# }
# }
def check
parts = URI.parse(@commit_url).path.split("/")
@nwo = "#{parts[1]}/#{parts[2]}"
@sha = parts[4]
@user = @client.user
@nwo, @sha = parse_commit_url @commit_url
begin
@commit = @client.commit @nwo, @sha
rescue Octokit::NotFound
raise ContributionChecker::InvalidCommitUrlError
end
@repo = @client.repository @nwo
@commit = @client.commit @nwo, @sha
@user = @client.user

@commit_in_valid_branch = commit_in_valid_branch?
@commit_in_last_year = commit_in_last_year?
Expand Down Expand Up @@ -79,6 +81,20 @@ def check
}
end

# Parses the commit URL provided.
#
# @return [Array] URL parts: nwo, sha
def parse_commit_url(url)
begin
parts = URI.parse(@commit_url).path.split("/")
nwo = "#{parts[1]}/#{parts[2]}"
sha = parts[4]
return nwo, sha
rescue
raise ContributionChecker::InvalidCommitUrlError
end
end

# Checks whether the commit is in a valid branch. A valid branch is defined
# as either the default branch of the repository, or the gh-pages branch.
#
Expand Down
10 changes: 10 additions & 0 deletions lib/contribution-checker/error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module ContributionChecker

# Error class to help us rescue from invalid commit URL input.
class InvalidCommitUrlError < StandardError
def initialize
super "Invalid commit URL provided"
end
end

end

0 comments on commit 5514532

Please sign in to comment.