@@ -62,7 +62,7 @@ def self.generate_input_values(url)
6262 match = url . delete_suffix ( ".git" ) . match ( GithubReleases ::URL_MATCH_REGEX )
6363 return values if match . blank?
6464
65- values [ :url ] = "https://api.github.com /repos/#{ match [ :username ] } /#{ match [ :repository ] } /releases/latest"
65+ values [ :url ] = "#{ GitHub :: API_URL } /repos/#{ match [ :username ] } /#{ match [ :repository ] } /releases/latest"
6666 values [ :username ] = match [ :username ]
6767 values [ :repository ] = match [ :repository ]
6868
@@ -73,27 +73,36 @@ def self.generate_input_values(url)
7373 # and identifies the version from the JSON response.
7474 #
7575 # @param url [String] the URL of the content to check
76- # @param regex [Regexp] a regex used for matching versions in content
76+ # @param regex [Regexp] a regex for matching versions in content
77+ # @param content [Hash, nil] content to check instead of fetching
7778 # @param options [Options] options to modify behavior
7879 # @return [Hash]
7980 sig {
80- override ( allow_incompatible : true ) . params (
81+ override . params (
8182 url : String ,
82- regex : Regexp ,
83+ regex : T . nilable ( Regexp ) ,
84+ content : T . nilable ( String ) ,
8385 options : Options ,
8486 block : T . nilable ( Proc ) ,
8587 ) . returns ( T ::Hash [ Symbol , T . anything ] )
8688 }
87- def self . find_versions ( url :, regex : GithubReleases ::DEFAULT_REGEX , options : Options . new , &block )
89+ def self . find_versions ( url :, regex : nil , content : nil , options : Options . new , &block )
90+ regex ||= GithubReleases ::DEFAULT_REGEX
8891 match_data = { matches : { } , regex :, url : }
92+ match_data [ :cached ] = true if content
8993
9094 generated = generate_input_values ( url )
9195 return match_data if generated . blank?
9296
9397 match_data [ :url ] = generated [ :url ]
9498
95- release = GitHub . get_latest_release ( generated [ :username ] , generated [ :repository ] )
96- GithubReleases . versions_from_content ( release , regex , &block ) . each do |match_text |
99+ unless match_data [ :cached ]
100+ match_data [ :content ] = GitHub ::API . open_rest ( generated [ :url ] , parse_json : false )
101+ content = match_data [ :content ]
102+ end
103+ return match_data if content . blank?
104+
105+ GithubReleases . versions_from_content ( content , regex , &block ) . each do |match_text |
97106 match_data [ :matches ] [ match_text ] = Version . new ( match_text )
98107 end
99108
0 commit comments