50 lines
1.4 KiB
Rust
50 lines
1.4 KiB
Rust
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),
|
|
}
|
|
}
|
|
|
|
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),
|
|
}
|
|
}
|