-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add source type regex Search through a webpage for the version string that fits a given regex. The first match of the regex is returned. --------- Co-authored-by: Adam Perkowski <[email protected]>
- Loading branch information
1 parent
a8a42fd
commit fa12ce9
Showing
8 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::{api, error}; | ||
use regex::Regex; | ||
|
||
/// get a version string from a webpage | ||
pub fn get_latest(args: api::ApiArgs) -> api::ReleaseFuture { | ||
Box::pin(async move { | ||
let url = args.args[0].clone(); | ||
let client = args.request_client; | ||
|
||
let result = client | ||
.get(&url) | ||
.headers(api::setup_headers()) | ||
.send() | ||
.await?; | ||
api::match_statuscode(&result.status(), args.package.clone())?; | ||
|
||
let body = result.text().await?; | ||
|
||
let re = Regex::new(&args.args[1]).unwrap(); | ||
if let Some(caps) = re.captures(&body) { | ||
Ok(api::Release { | ||
name: caps.get(1).unwrap().as_str().to_owned(), | ||
tag: None, | ||
url, | ||
}) | ||
} else { | ||
Err(error::Error::NoVersion(args.package)) | ||
} | ||
}) | ||
} | ||
|
||
#[tokio::test] | ||
async fn request_test() { | ||
let package = "rustrover".to_string(); | ||
let args = api::ApiArgs { | ||
request_client: reqwest::Client::new(), | ||
package: package.clone(), | ||
use_max_tag: None, | ||
args: vec![ | ||
"https://data.services.jetbrains.com/products?code=RR&release.type=release".to_string(), | ||
r"RustRover-([\d.]+).tar.gz".to_string(), | ||
], | ||
api_key: String::new(), | ||
}; | ||
|
||
assert!(crate::api::regex::get_latest(args).await.is_ok()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|