2020-05-31 19:35:23 +00:00
|
|
|
use crate::cmd::*;
|
|
|
|
use anyhow::Result;
|
|
|
|
use git2::Repository;
|
|
|
|
use url::Url;
|
|
|
|
|
|
|
|
pub(crate) async fn run(env: DroneEnv) -> Result<()> {
|
2020-06-12 11:18:13 +00:00
|
|
|
let common: Common = env.clone().into();
|
|
|
|
|
2020-07-08 21:36:53 +00:00
|
|
|
let default_branch = {
|
|
|
|
let common = common.clone();
|
|
|
|
match &env.default_branch {
|
|
|
|
None => {
|
|
|
|
let cli =
|
|
|
|
gitea::Client::new(common.server, common.token, crate::APP_USER_AGENT.into())?;
|
|
|
|
let repo = cli.get_repo(common.owner, common.repo).await?;
|
|
|
|
repo.default_branch
|
|
|
|
}
|
|
|
|
Some(branch) => branch.to_string(),
|
2020-06-12 11:18:13 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if env.branch != default_branch {
|
2020-05-31 19:35:23 +00:00
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
|
|
|
let repo = Repository::open(".")?;
|
|
|
|
let mut u = Url::parse(&env.push_url)?;
|
|
|
|
u.set_username(&env.auth_user).unwrap();
|
|
|
|
u.set_password(Some(&env.token)).unwrap();
|
|
|
|
repo.remote_delete("origin")?;
|
2020-06-12 12:17:04 +00:00
|
|
|
let mut origin = repo.remote("origin", u.as_str())?;
|
|
|
|
origin.connect(git2::Direction::Fetch)?;
|
|
|
|
origin.fetch(&["refs/tags/*:refs/tags/*"], None, None)?;
|
2020-05-31 19:35:23 +00:00
|
|
|
|
|
|
|
release::run(
|
|
|
|
common,
|
|
|
|
env.changelog_path,
|
|
|
|
None,
|
|
|
|
ReleaseMeta {
|
|
|
|
name: None,
|
|
|
|
draft: false,
|
|
|
|
pre_release: false,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
}
|