-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): Add CLI command to create a PR that conforms to clu config…
…uration (#56) * add wip to create PR * check for branch on remote and get PR body from user * some refactors, refactoring * enable selecting another branch than main * add changelog entry
- Loading branch information
1 parent
b277408
commit 6a10498
Showing
12 changed files
with
225 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
"categories": [ | ||
"all", | ||
"ci", | ||
"cli", | ||
"config", | ||
"crud", | ||
"docker", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use crate::{config, errors::CreateError, github, inputs}; | ||
use octocrab::params::repos::Reference::Branch; | ||
|
||
/// Runs the main logic to open a new PR for the current branch. | ||
pub async fn run() -> Result<(), CreateError> { | ||
let config = config::load()?; | ||
let git_info = github::get_git_info(&config)?; | ||
let client = github::get_authenticated_github_client()?; | ||
|
||
if client | ||
.repos(&git_info.owner, &git_info.repo) | ||
.get_ref(&Branch(git_info.branch.clone())) | ||
.await | ||
.is_err() | ||
{ | ||
// TODO: add option to push the branch? | ||
return Err(CreateError::BranchNotOnRemote(git_info.branch.clone())); | ||
}; | ||
|
||
if let Ok(pr_info) = github::get_open_pr(git_info.clone()).await { | ||
return Err(CreateError::ExistingPR(pr_info.number)); | ||
} | ||
|
||
let change_type = inputs::get_change_type(&config, 0)?; | ||
let cat = inputs::get_category(&config, 0)?; | ||
let desc = inputs::get_description("")?; | ||
let pr_body = inputs::get_pr_description()?; | ||
|
||
let branches = client | ||
.repos(&git_info.owner, &git_info.repo) | ||
.list_branches() | ||
.send() | ||
.await?; | ||
let target = inputs::get_target_branch(branches)?; | ||
|
||
let ct = config.change_types.get(&change_type).unwrap(); | ||
let title = format!("{ct}({cat}): {desc}"); | ||
|
||
let created_pr = client | ||
.pulls(&git_info.owner, &git_info.repo) | ||
.create(title, git_info.branch, target) | ||
.body(pr_body) | ||
.send() | ||
.await?; | ||
|
||
println!( | ||
"created pull request: {}", | ||
created_pr | ||
.html_url | ||
.expect("received no error creating the PR but html_url was None") | ||
); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.