mirror of
https://codeberg.org/Cyborus/forgejo-cli.git
synced 2025-03-15 21:45:54 +01:00
Merge pull request 'add --web
flag on pr create
' (#129) from web-pr into main
Reviewed-on: https://codeberg.org/Cyborus/forgejo-cli/pulls/129
This commit is contained in:
commit
c3fe6d5991
1 changed files with 56 additions and 36 deletions
26
src/prs.rs
26
src/prs.rs
|
@ -53,7 +53,8 @@ pub enum PrSubcommand {
|
||||||
/// What to name the new pull request.
|
/// What to name the new pull request.
|
||||||
///
|
///
|
||||||
/// Prefix with "WIP: " to mark this PR as a draft.
|
/// Prefix with "WIP: " to mark this PR as a draft.
|
||||||
title: String,
|
#[clap(group = "web-or-cmd")]
|
||||||
|
title: Option<String>,
|
||||||
/// The text body of the pull request.
|
/// The text body of the pull request.
|
||||||
///
|
///
|
||||||
/// Leaving this out will open your editor.
|
/// Leaving this out will open your editor.
|
||||||
|
@ -62,6 +63,9 @@ pub enum PrSubcommand {
|
||||||
/// The repo to create this issue on
|
/// The repo to create this issue on
|
||||||
#[clap(long, short, id = "[HOST/]OWNER/REPO")]
|
#[clap(long, short, id = "[HOST/]OWNER/REPO")]
|
||||||
repo: Option<RepoArg>,
|
repo: Option<RepoArg>,
|
||||||
|
/// Open the PR creation menu in your web browser
|
||||||
|
#[clap(short, long, group = "web-or-cmd")]
|
||||||
|
web: bool,
|
||||||
},
|
},
|
||||||
/// View the contents of a pull request
|
/// View the contents of a pull request
|
||||||
View {
|
View {
|
||||||
|
@ -274,7 +278,8 @@ impl PrCommand {
|
||||||
head,
|
head,
|
||||||
body,
|
body,
|
||||||
repo: _,
|
repo: _,
|
||||||
} => create_pr(repo, &api, title, base, head, body).await?,
|
web,
|
||||||
|
} => create_pr(repo, &api, title, base, head, body, web).await?,
|
||||||
Merge {
|
Merge {
|
||||||
pr,
|
pr,
|
||||||
method,
|
method,
|
||||||
|
@ -805,10 +810,11 @@ async fn edit_pr_labels(
|
||||||
async fn create_pr(
|
async fn create_pr(
|
||||||
repo: &RepoName,
|
repo: &RepoName,
|
||||||
api: &Forgejo,
|
api: &Forgejo,
|
||||||
title: String,
|
title: Option<String>,
|
||||||
base: Option<String>,
|
base: Option<String>,
|
||||||
head: Option<String>,
|
head: Option<String>,
|
||||||
body: Option<String>,
|
body: Option<String>,
|
||||||
|
web: bool,
|
||||||
) -> eyre::Result<()> {
|
) -> eyre::Result<()> {
|
||||||
let mut repo_data = api.repo_get(repo.owner(), repo.name()).await?;
|
let mut repo_data = api.repo_get(repo.owner(), repo.name()).await?;
|
||||||
|
|
||||||
|
@ -915,6 +921,18 @@ async fn create_pr(
|
||||||
.to_owned(),
|
.to_owned(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if web {
|
||||||
|
let mut pr_create_url = base_repo
|
||||||
|
.html_url
|
||||||
|
.clone()
|
||||||
|
.ok_or_eyre("repo does not have html url")?;
|
||||||
|
pr_create_url
|
||||||
|
.path_segments_mut()
|
||||||
|
.expect("invalid url")
|
||||||
|
.extend(["compare", &format!("{base}...{head}")]);
|
||||||
|
open::that(pr_create_url.as_str())?;
|
||||||
|
} else {
|
||||||
|
let title = title.ok_or_eyre("title is required")?;
|
||||||
let body = match body {
|
let body = match body {
|
||||||
Some(body) => body,
|
Some(body) => body,
|
||||||
None => {
|
None => {
|
||||||
|
@ -948,6 +966,8 @@ async fn create_pr(
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.ok_or_else(|| eyre::eyre!("pr does not have title"))?;
|
.ok_or_else(|| eyre::eyre!("pr does not have title"))?;
|
||||||
println!("created pull request #{}: {}", number, title);
|
println!("created pull request #{}: {}", number, title);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue