Skip to content

Commit 4b16c23

Browse files
committed
Delete branch endpoint
1 parent 1be5e67 commit 4b16c23

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

fplus-http-server/src/router/application.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use fplus_lib::core::{
33
application::file::VerifierInput, ApplicationQueryParams,
44
CompleteNewApplicationProposalInfo, CreateApplicationInfo, DcReachedInfo,
55
GithubQueryParams, LDNApplication, RefillInfo, ValidationPullRequestData,
6-
VerifierActionsQueryParams,
6+
VerifierActionsQueryParams, BranchDeleteInfo,
77
};
88

99
#[post("/application")]
@@ -296,6 +296,15 @@ pub async fn validate_application_merge(
296296
}
297297
}
298298

299+
#[post("/application/branch/delete")]
300+
pub async fn delete_branch(data: web::Json<BranchDeleteInfo>) -> actix_web::Result<impl Responder> {
301+
let info = data.into_inner();
302+
match LDNApplication::delete_merged_branch(info.owner, info.repo, info.branch_name).await {
303+
Ok(result) => Ok(HttpResponse::Ok().json(result)),
304+
Err(e) => Ok(HttpResponse::BadRequest().body(e.to_string())),
305+
}
306+
}
307+
299308
#[post("application/cache/renewal")]
300309
pub async fn cache_renewal(info: web::Json<GithubQueryParams>) -> impl Responder {
301310
let GithubQueryParams { owner, repo } = info.into_inner();

fplus-lib/src/core/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ pub struct CreateApplicationInfo {
4747
pub repo: String,
4848
}
4949

50+
#[derive(Deserialize)]
51+
pub struct BranchDeleteInfo {
52+
pub owner: String,
53+
pub repo: String,
54+
pub branch_name: String,
55+
}
56+
5057
#[derive(Deserialize, Serialize, Debug)]
5158
pub struct VerifierList(pub Vec<String>);
5259

@@ -1788,6 +1795,22 @@ impl LDNApplication {
17881795
}
17891796
}
17901797

1798+
pub async fn delete_merged_branch(owner: String, repo: String, branch_name: String) -> Result<bool, LDNError> {
1799+
let gh = github_async_new(owner, repo).await;
1800+
let request = gh.build_remove_ref_request(branch_name.clone()).unwrap();
1801+
1802+
gh.remove_branch(request)
1803+
.await
1804+
.map_err(|e| {
1805+
return LDNError::New(format!(
1806+
"Error deleting branch {} /// {}",
1807+
branch_name, e
1808+
));
1809+
})?;
1810+
1811+
Ok(true)
1812+
}
1813+
17911814
async fn issue_waiting_for_gov_review(
17921815
issue_number: String,
17931816
owner: String,

0 commit comments

Comments
 (0)