Skip to content

Commit 843e695

Browse files
authored
Merge pull request #4 from wbbradley/phase-sync
feat: implement sync model
2 parents 20dbec1 + c9d32fb commit 843e695

4 files changed

Lines changed: 1001 additions & 117 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ features atop one another, keeping their history clean and rebasing as needed. I
55
relationships between branches, helps you re-stack and synchronize them, and visualizes your stack
66
tree.
77

8+
`git-stack` also allows for synchronization between Github and local state.
9+
810
## Key Features
911

1012
- Stacked Workflow: Track parent-child branch relationships ("stacks") in your repo.

src/github.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -436,52 +436,50 @@ pub fn get_repo_identifier(git_repo: &GitRepo) -> Result<RepoIdentifier> {
436436
/// Find GitHub token from various sources
437437
fn find_github_token(host: &str) -> Result<String, GitHubError> {
438438
// 1. Check GITHUB_TOKEN env var
439-
if let Ok(token) = std::env::var("GITHUB_TOKEN") {
440-
if !token.is_empty() {
441-
tracing::debug!("Using GitHub token from GITHUB_TOKEN env var");
442-
return Ok(token);
443-
}
439+
if let Ok(token) = std::env::var("GITHUB_TOKEN")
440+
&& !token.is_empty()
441+
{
442+
tracing::debug!("Using GitHub token from GITHUB_TOKEN env var");
443+
return Ok(token);
444444
}
445445

446446
// 2. Check GH_TOKEN env var (used by gh CLI)
447-
if let Ok(token) = std::env::var("GH_TOKEN") {
448-
if !token.is_empty() {
449-
tracing::debug!("Using GitHub token from GH_TOKEN env var");
450-
return Ok(token);
451-
}
447+
if let Ok(token) = std::env::var("GH_TOKEN")
448+
&& !token.is_empty()
449+
{
450+
tracing::debug!("Using GitHub token from GH_TOKEN env var");
451+
return Ok(token);
452452
}
453453

454454
// 3. Check git config github.token
455455
if let Ok(output) = Command::new("git")
456456
.args(["config", "--get", "github.token"])
457457
.output()
458+
&& output.status.success()
458459
{
459-
if output.status.success() {
460-
let token = String::from_utf8_lossy(&output.stdout).trim().to_string();
461-
if !token.is_empty() {
462-
tracing::debug!("Using GitHub token from git config");
463-
return Ok(token);
464-
}
460+
let token = String::from_utf8_lossy(&output.stdout).trim().to_string();
461+
if !token.is_empty() {
462+
tracing::debug!("Using GitHub token from git config");
463+
return Ok(token);
465464
}
466465
}
467466

468467
// 4. Check XDG config file
469-
if let Ok(config_path) = get_github_config_path() {
470-
if let Ok(contents) = fs::read_to_string(&config_path) {
471-
if let Ok(config) = serde_yaml::from_str::<GitHubConfigFile>(&contents) {
472-
// Check for host-specific token first
473-
if let Some(hosts) = &config.hosts {
474-
if let Some(token) = hosts.get(host) {
475-
tracing::debug!("Using GitHub token from config file (host-specific)");
476-
return Ok(token.clone());
477-
}
478-
}
479-
// Fall back to default token
480-
if let Some(token) = config.default_token {
481-
tracing::debug!("Using GitHub token from config file (default)");
482-
return Ok(token);
483-
}
484-
}
468+
if let Ok(config_path) = get_github_config_path()
469+
&& let Ok(contents) = fs::read_to_string(&config_path)
470+
&& let Ok(config) = serde_yaml::from_str::<GitHubConfigFile>(&contents)
471+
{
472+
// Check for host-specific token first
473+
if let Some(hosts) = &config.hosts
474+
&& let Some(token) = hosts.get(host)
475+
{
476+
tracing::debug!("Using GitHub token from config file (host-specific)");
477+
return Ok(token.clone());
478+
}
479+
// Fall back to default token
480+
if let Some(token) = config.default_token {
481+
tracing::debug!("Using GitHub token from config file (default)");
482+
return Ok(token);
485483
}
486484
}
487485

@@ -538,7 +536,9 @@ pub fn has_github_token(host: &str) -> bool {
538536

539537
/// Interactive token setup
540538
pub fn setup_github_token_interactive() -> Result<String> {
541-
println!("No GitHub token found. To manage PRs, git-stack needs a GitHub Personal Access Token.");
539+
println!(
540+
"No GitHub token found. To manage PRs, git-stack needs a GitHub Personal Access Token."
541+
);
542542
println!();
543543
println!("Steps to create a token:");
544544
println!("1. Go to: https://github.com/settings/tokens/new");

0 commit comments

Comments
 (0)