git tag checking
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Cadey Ratio 2020-05-31 13:45:35 -04:00
parent ab775befb1
commit c960a07ec2
6 changed files with 76 additions and 0 deletions

9
.drone.yml Normal file
View File

@ -0,0 +1,9 @@
kind: pipeline
name: tools
steps:
- name: rust tests
image: "rust:1"
pull: always
commands:
- cargo test

1
Cargo.lock generated
View File

@ -339,6 +339,7 @@ dependencies = [
"serde",
"serde_json",
"structopt",
"tempfile",
"tokio",
]

View File

@ -20,5 +20,8 @@ serde = { version = "1.0", features = ["derive"] }
structopt = { version = "0.3", default-features = false }
tokio = { version = "0.2", features = ["macros"] }
[dev-dependencies]
tempfile = "3"
[profile.release]
lto = true

View File

@ -1,5 +1,8 @@
# gitea-release
[![built with nix](https://builtwithnix.org/badge.svg)](https://builtwithnix.org)
[![Build Status](https://drone.tulpa.dev/api/badges/cadey/gitea-release/status.svg)](https://drone.tulpa.dev/cadey/gitea-release)
A small command line tool to automate releases for [Gitea](https://gitea.io)
repositories that reads from CHANGELOG and VERSION files. This is a clone of
[github-release](https://github.com/github-release/github-release), but more

59
src/git.rs Normal file
View File

@ -0,0 +1,59 @@
use anyhow::Result;
use git2::Repository;
use std::path::PathBuf;
pub(crate) fn has_tag(repo_path: PathBuf, tag: String) -> Result<bool> {
let repo = Repository::init(repo_path)?;
let tags = repo.tag_names(Some(&tag))?;
for tag_obj in tags.iter() {
if tag_obj.is_none() {
continue;
}
let tag_name = tag_obj.unwrap();
if tag == tag_name.to_string() {
return Ok(true);
}
}
Ok(false)
}
#[cfg(test)]
mod tests {
use anyhow::Result;
use git2::*;
use std::{fs::File, io::Write, path::Path};
use tempfile::tempdir;
#[test]
fn has_tag() -> Result<()> {
const TAG: &'static str = "0.1.0";
let dir = tempdir()?;
let repo = Repository::init(&dir)?;
let mut fout = File::create(&dir.path().join("VERSION"))?;
write!(fout, "{}", TAG)?;
drop(fout);
let mut index = repo.index()?;
index.add_path(Path::new("VERSION"))?;
let oid = index.write_tree()?;
let tree = repo.find_tree(oid)?;
let sig = Signature::now("Testificate", "test@ifica.te")?;
repo.commit(
Some("HEAD"),
&sig,
&sig,
"test commit please ignore",
&tree,
&[],
)?;
let obj = repo.revparse_single("HEAD")?;
repo.tag(TAG, &obj, &sig, &format!("version {}", TAG), false)?;
assert!(super::has_tag(dir.path().into(), TAG.into())?);
Ok(())
}
}

View File

@ -5,6 +5,7 @@ use structopt::StructOpt;
mod changelog;
mod cmd;
mod git;
mod gitea;
mod version;