File tree 3 files changed +32
-5
lines changed
3 files changed +32
-5
lines changed Original file line number Diff line number Diff line change 1
1
require "contribution-checker/version"
2
+ require "contribution-checker/error"
2
3
require "contribution-checker/checker"
Original file line number Diff line number Diff line change @@ -46,12 +46,14 @@ def initialize(options = {})
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 @@ def check
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
#
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments