Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,20 @@ pub fn get_branch() -> Result<String, String> {
Err(String::from_utf8(output.stderr).unwrap())
}
}

pub fn create_branch(branch_name: String) -> Result<String, String> {
let output = std::process::Command::new("git")
.arg("checkout")
.arg("-b")
.arg(branch_name)
.output()
.map_err(|e| e.to_string())?;

if output.status.success() {
String::from_utf8(output.stdout)
.map(|s| s.trim().to_string())
.map_err(|e| e.to_string())
} else {
Err(String::from_utf8(output.stderr).unwrap())
}
}
9 changes: 6 additions & 3 deletions src/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ pub fn create(
state: State,
assignee_id: String,
priority: Priority,
) -> Result<String, String> {
) -> Result<(String, String), String> {
let priority = priority::priority_to_int(&priority);
let response = request::Gql::new(config, token, ISSUE_CREATE_DOC)
.put_string("title", title)
Expand All @@ -449,7 +449,7 @@ pub fn create(
url, branch_name, ..
} = issue_create_response(response)?;

Ok(format!("{url}\n{branch_name}"))
Ok((branch_name.clone(), format!("{url}\n{branch_name}")))
}

pub fn list(
Expand Down Expand Up @@ -702,7 +702,10 @@ mod tests {
);
assert_eq!(
result,
Ok("https://linear.app/vardy/issue/BE-3354/test\nbe-3354-test".to_string())
Ok((
"be-3354-test".to_string(),
"https://linear.app/vardy/issue/BE-3354/test\nbe-3354-test".to_string()
))
);
mock.assert();
}
Expand Down
13 changes: 13 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,19 @@ fn issue_create(cli: Cli, args: &IssueCreate) -> Result<String, String> {
viewer.id,
priority,
)
.map(|(branch_name, url)| {
match git::create_branch(branch_name.clone()) {
Ok(_) => {
let success_msg = format!("✓ Created git branch: {}", branch_name);
eprintln!("{}", success_msg.green());
}
Err(e) => {
let warning_msg = format!("⚠ Could not create git branch '{}': {}", branch_name, e);
eprintln!("{}", warning_msg.yellow());
}
}
url
})
}

fn issue_view(cli: Cli, args: &IssueView) -> Result<String, String> {
Expand Down