2023-04-07 15:25:02 +02:00
|
|
|
use crate::gitea;
|
|
|
|
|
2023-04-07 02:19:01 +02:00
|
|
|
pub async fn validate_pr(
|
|
|
|
owner: &str,
|
|
|
|
repo: &str,
|
|
|
|
pull_request_id: u32,
|
|
|
|
current_version: &str,
|
|
|
|
) -> eyre::Result<Option<String>> {
|
|
|
|
let base_url = &std::env::var("GITEA_BASE_URL").unwrap();
|
|
|
|
let token = &std::env::var("GITEA_ACCESS_TOKEN").unwrap();
|
|
|
|
|
|
|
|
let commit_titles =
|
|
|
|
crate::gitea::get_pull_request_commits(base_url, owner, repo, pull_request_id, token)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
match crate::semantic::get_most_significant_bump(&commit_titles) {
|
|
|
|
Some(bump) => Ok(Some(crate::semantic::bump_semver(current_version, bump)?)),
|
|
|
|
None => Ok(None),
|
|
|
|
}
|
|
|
|
}
|
2023-04-07 15:25:02 +02:00
|
|
|
|
|
|
|
pub(crate) async fn validate_commits(
|
|
|
|
owner: &str,
|
|
|
|
repo: &str,
|
|
|
|
start_commit: &str,
|
|
|
|
branch: &str,
|
|
|
|
current_version: &str,
|
|
|
|
) -> eyre::Result<Option<String>> {
|
|
|
|
let base_url = &std::env::var("GITEA_BASE_URL").unwrap();
|
|
|
|
let token = &std::env::var("GITEA_ACCESS_TOKEN").unwrap();
|
|
|
|
|
|
|
|
let commits = crate::gitea::get_commits_from_commit_to_newest(
|
|
|
|
base_url,
|
|
|
|
owner,
|
|
|
|
repo,
|
|
|
|
token,
|
|
|
|
branch,
|
|
|
|
start_commit,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
let commit_titles = commits
|
|
|
|
.into_iter()
|
|
|
|
.map(|c| c.commit.message)
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
match crate::semantic::get_most_significant_bump(&commit_titles) {
|
|
|
|
Some(bump) => Ok(Some(crate::semantic::bump_semver(current_version, bump)?)),
|
|
|
|
None => Ok(None),
|
|
|
|
}
|
|
|
|
}
|