mirror of
https://codeberg.org/Cyborus/forgejo-cli.git
synced 2024-11-14 05:59:27 +01:00
Merge pull request 'pull request messages' (#72) from pr-message into main
Reviewed-on: https://codeberg.org/Cyborus/forgejo-cli/pulls/72
This commit is contained in:
commit
aee8b4b257
1 changed files with 52 additions and 9 deletions
61
src/prs.rs
61
src/prs.rs
|
@ -111,11 +111,17 @@ pub enum PrSubcommand {
|
||||||
/// The pull request to merge.
|
/// The pull request to merge.
|
||||||
pr: IssueId,
|
pr: IssueId,
|
||||||
/// The merge style to use.
|
/// The merge style to use.
|
||||||
#[clap(long, short)]
|
#[clap(long, short = 'M')]
|
||||||
method: Option<MergeMethod>,
|
method: Option<MergeMethod>,
|
||||||
/// Option to delete the corresponding branch afterwards.
|
/// Option to delete the corresponding branch afterwards.
|
||||||
#[clap(long, short)]
|
#[clap(long, short)]
|
||||||
delete: bool,
|
delete: bool,
|
||||||
|
/// The title of the merge or squash commit to be created
|
||||||
|
#[clap(long, short)]
|
||||||
|
title: Option<String>,
|
||||||
|
/// The body of the merge or squash commit to be created
|
||||||
|
#[clap(long, short)]
|
||||||
|
message: Option<Option<String>>,
|
||||||
},
|
},
|
||||||
/// Open a pull request in your browser
|
/// Open a pull request in your browser
|
||||||
Browse {
|
Browse {
|
||||||
|
@ -256,9 +262,13 @@ impl PrCommand {
|
||||||
body,
|
body,
|
||||||
repo: _,
|
repo: _,
|
||||||
} => create_pr(&repo, &api, title, base, head, body).await?,
|
} => create_pr(&repo, &api, title, base, head, body).await?,
|
||||||
Merge { pr, method, delete } => {
|
Merge {
|
||||||
merge_pr(&repo, &api, pr.number, method, delete).await?
|
pr,
|
||||||
}
|
method,
|
||||||
|
delete,
|
||||||
|
title,
|
||||||
|
message,
|
||||||
|
} => merge_pr(&repo, &api, pr.number, method, delete, title, message).await?,
|
||||||
View { id, command } => match command.unwrap_or(ViewCommand::Body) {
|
View { id, command } => match command.unwrap_or(ViewCommand::Body) {
|
||||||
ViewCommand::Body => view_pr(&repo, &api, id.number).await?,
|
ViewCommand::Body => view_pr(&repo, &api, id.number).await?,
|
||||||
ViewCommand::Comment { idx } => {
|
ViewCommand::Comment { idx } => {
|
||||||
|
@ -720,23 +730,56 @@ async fn merge_pr(
|
||||||
pr: u64,
|
pr: u64,
|
||||||
method: Option<MergeMethod>,
|
method: Option<MergeMethod>,
|
||||||
delete: bool,
|
delete: bool,
|
||||||
|
title: Option<String>,
|
||||||
|
message: Option<Option<String>>,
|
||||||
) -> eyre::Result<()> {
|
) -> eyre::Result<()> {
|
||||||
let repo_info = api.repo_get(repo.owner(), repo.name()).await?;
|
let repo_info = api.repo_get(repo.owner(), repo.name()).await?;
|
||||||
|
|
||||||
|
let pr_info = api
|
||||||
|
.repo_get_pull_request(repo.owner(), repo.name(), pr)
|
||||||
|
.await?;
|
||||||
|
let pr_html_url = pr_info
|
||||||
|
.html_url
|
||||||
|
.as_ref()
|
||||||
|
.ok_or_eyre("pr does not have url")?;
|
||||||
|
|
||||||
let default_merge = repo_info
|
let default_merge = repo_info
|
||||||
.default_merge_style
|
.default_merge_style
|
||||||
.map(|x| x.into())
|
.map(|x| x.into())
|
||||||
.unwrap_or(forgejo_api::structs::MergePullRequestOptionDo::Merge);
|
.unwrap_or(forgejo_api::structs::MergePullRequestOptionDo::Merge);
|
||||||
let body = MergePullRequestOption {
|
let merge_style = method.map(|x| x.into()).unwrap_or(default_merge);
|
||||||
r#do: method.map(|x| x.into()).unwrap_or(default_merge),
|
|
||||||
|
use forgejo_api::structs::MergePullRequestOptionDo::*;
|
||||||
|
if title.is_some() {
|
||||||
|
match merge_style {
|
||||||
|
Rebase => eyre::bail!("rebase does not support commit title"),
|
||||||
|
FastForwardOnly => eyre::bail!("ff-only does not support commit title"),
|
||||||
|
ManuallyMerged => eyre::bail!("manually merged does not support commit title"),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let default_message = || format!("Reviewed-on: {pr_html_url}");
|
||||||
|
let message = match message {
|
||||||
|
Some(Some(s)) => s,
|
||||||
|
Some(None) => {
|
||||||
|
let mut body = default_message();
|
||||||
|
crate::editor(&mut body, Some("md")).await?;
|
||||||
|
body
|
||||||
|
}
|
||||||
|
None => default_message(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let request = MergePullRequestOption {
|
||||||
|
r#do: merge_style,
|
||||||
merge_commit_id: None,
|
merge_commit_id: None,
|
||||||
merge_message_field: None,
|
merge_message_field: Some(message),
|
||||||
merge_title_field: None,
|
merge_title_field: title,
|
||||||
delete_branch_after_merge: Some(delete),
|
delete_branch_after_merge: Some(delete),
|
||||||
force_merge: None,
|
force_merge: None,
|
||||||
head_commit_id: None,
|
head_commit_id: None,
|
||||||
merge_when_checks_succeed: None,
|
merge_when_checks_succeed: None,
|
||||||
};
|
};
|
||||||
api.repo_merge_pull_request(repo.owner(), repo.name(), pr, body)
|
api.repo_merge_pull_request(repo.owner(), repo.name(), pr, request)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue