fix(git_commit): remove unwraps (#2743)

This commit is contained in:
David Knaack 2021-05-19 19:08:48 +02:00 committed by GitHub
parent c58d127974
commit 78b84c9f34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 6 deletions

View File

@ -46,13 +46,18 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
if !config.tag_disabled { if !config.tag_disabled {
// Let's get repo tags names // Let's get repo tags names
let tag_names = git_repo.tag_names(None).ok()?; let tag_names = git_repo.tag_names(None).ok()?;
let tag_and_refs = tag_names.iter().flat_map(|name| { let tag_and_refs = tag_names.iter().flatten().flat_map(|name| {
let full_tag = format!("refs/tags/{}", name.unwrap()); let full_tag = format!("refs/tags/{}", name);
let tag_obj = git_repo.find_reference(&full_tag)?.peel_to_tag()?; let tag_obj = git_repo.find_reference(&full_tag)?.peel_to_tag()?;
let sig_obj = tag_obj.tagger().unwrap(); let sig_obj = tag_obj.tagger();
git_repo git_repo.find_reference(&full_tag).map(|reference| {
.find_reference(&full_tag) (
.map(|reference| (String::from(name.unwrap()), sig_obj.when(), reference)) String::from(name),
// fall back to oldest + 1s time if sig_obj is unavailable
sig_obj.map_or(git2::Time::new(1, 0), |s| s.when()),
reference,
)
})
}); });
let mut tag_name = String::new(); let mut tag_name = String::new();