diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2023-12-01 00:00:00 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2023-12-01 00:00:00 +0000 |
| commit | 06be0bc44011411b78217459f505ed12281b32c4 (patch) | |
| tree | 36cab80e309d33f20fedcc97258700a379aa348e /src/sub_commands/prs/create.rs | |
| parent | 492cc67887855cecb3fb501c4b61af50bf645b73 (diff) | |
feat(prs-list) list and pull selected as branch
- fetch prs and present as a selectable list
- create and / or checkout branch for selected pr
- apply latest patches as commits
Diffstat (limited to 'src/sub_commands/prs/create.rs')
| -rw-r--r-- | src/sub_commands/prs/create.rs | 90 |
1 files changed, 56 insertions, 34 deletions
diff --git a/src/sub_commands/prs/create.rs b/src/sub_commands/prs/create.rs index ce30c12..5c4e578 100644 --- a/src/sub_commands/prs/create.rs +++ b/src/sub_commands/prs/create.rs | |||
| @@ -301,9 +301,9 @@ mod tests_unique_and_duplicate { | |||
| 301 | pub static PR_KIND: u64 = 318; | 301 | pub static PR_KIND: u64 = 318; |
| 302 | pub static PATCH_KIND: u64 = 317; | 302 | pub static PATCH_KIND: u64 = 317; |
| 303 | 303 | ||
| 304 | fn generate_pr_and_patch_events( | 304 | pub fn generate_pr_and_patch_events( |
| 305 | title: &String, | 305 | title: &str, |
| 306 | description: &String, | 306 | description: &str, |
| 307 | to_branch: &str, | 307 | to_branch: &str, |
| 308 | git_repo: &Repo, | 308 | git_repo: &Repo, |
| 309 | commits: &Vec<Sha1Hash>, | 309 | commits: &Vec<Sha1Hash>, |
| @@ -314,6 +314,7 @@ fn generate_pr_and_patch_events( | |||
| 314 | .context("failed to get root commit of the repository")?; | 314 | .context("failed to get root commit of the repository")?; |
| 315 | 315 | ||
| 316 | let mut pr_tags = vec![ | 316 | let mut pr_tags = vec![ |
| 317 | Tag::Identifier(root_commit.to_string()), | ||
| 317 | Tag::Reference(format!("r-{root_commit}")), | 318 | Tag::Reference(format!("r-{root_commit}")), |
| 318 | Tag::Name(title.to_string()), | 319 | Tag::Name(title.to_string()), |
| 319 | Tag::Description(description.to_string()), | 320 | Tag::Description(description.to_string()), |
| @@ -341,42 +342,63 @@ fn generate_pr_and_patch_events( | |||
| 341 | 342 | ||
| 342 | let mut events = vec![pr_event]; | 343 | let mut events = vec![pr_event]; |
| 343 | for commit in commits { | 344 | for commit in commits { |
| 344 | let commit_parent = git_repo | ||
| 345 | .get_commit_parent(commit) | ||
| 346 | .context("failed to create patch event")?; | ||
| 347 | events.push( | 345 | events.push( |
| 348 | EventBuilder::new( | 346 | generate_patch_event(git_repo, &root_commit, commit, pr_event_id, keys) |
| 349 | nostr::event::Kind::Custom(PATCH_KIND), | 347 | .context("failed to generate patch event")?, |
| 350 | git_repo | ||
| 351 | .make_patch_from_commit(commit) | ||
| 352 | .context(format!("cannot make patch for commit {commit}"))?, | ||
| 353 | &[ | ||
| 354 | Tag::Reference(format!("r-{root_commit}")), | ||
| 355 | Tag::Reference(commit.to_string()), | ||
| 356 | Tag::Reference(commit_parent.to_string()), | ||
| 357 | Tag::Event( | ||
| 358 | pr_event_id, | ||
| 359 | None, // TODO: add relay | ||
| 360 | Some(Marker::Root), | ||
| 361 | ), | ||
| 362 | Tag::Generic( | ||
| 363 | TagKind::Custom("commit".to_string()), | ||
| 364 | vec![commit.to_string()], | ||
| 365 | ), | ||
| 366 | Tag::Generic( | ||
| 367 | TagKind::Custom("parent-commit".to_string()), | ||
| 368 | vec![commit_parent.to_string()], | ||
| 369 | ), | ||
| 370 | // TODO: add Repo event tags | ||
| 371 | // TODO: people tag maintainers | ||
| 372 | // TODO: add relay tags | ||
| 373 | ], | ||
| 374 | ) | ||
| 375 | .to_event(keys)?, | ||
| 376 | ); | 348 | ); |
| 377 | } | 349 | } |
| 378 | Ok(events) | 350 | Ok(events) |
| 379 | } | 351 | } |
| 352 | |||
| 353 | pub fn generate_patch_event( | ||
| 354 | git_repo: &Repo, | ||
| 355 | root_commit: &Sha1Hash, | ||
| 356 | commit: &Sha1Hash, | ||
| 357 | pr_event_id: nostr::EventId, | ||
| 358 | keys: &nostr::Keys, | ||
| 359 | ) -> Result<nostr::Event> { | ||
| 360 | let commit_parent = git_repo | ||
| 361 | .get_commit_parent(commit) | ||
| 362 | .context("failed to get parent commit")?; | ||
| 363 | EventBuilder::new( | ||
| 364 | nostr::event::Kind::Custom(PATCH_KIND), | ||
| 365 | git_repo | ||
| 366 | .make_patch_from_commit(commit) | ||
| 367 | .context(format!("cannot make patch for commit {commit}"))?, | ||
| 368 | &[ | ||
| 369 | Tag::Reference(format!("r-{root_commit}")), | ||
| 370 | Tag::Reference(commit.to_string()), | ||
| 371 | Tag::Reference(commit_parent.to_string()), | ||
| 372 | Tag::Event( | ||
| 373 | pr_event_id, | ||
| 374 | None, // TODO: add relay | ||
| 375 | Some(Marker::Root), | ||
| 376 | ), | ||
| 377 | Tag::Generic( | ||
| 378 | TagKind::Custom("commit".to_string()), | ||
| 379 | vec![commit.to_string()], | ||
| 380 | ), | ||
| 381 | Tag::Generic( | ||
| 382 | TagKind::Custom("parent-commit".to_string()), | ||
| 383 | vec![commit_parent.to_string()], | ||
| 384 | ), | ||
| 385 | Tag::Description(git_repo.get_commit_message(commit)?.to_string()), | ||
| 386 | Tag::Generic( | ||
| 387 | TagKind::Custom("author".to_string()), | ||
| 388 | git_repo.get_commit_author(commit)?, | ||
| 389 | ), | ||
| 390 | Tag::Generic( | ||
| 391 | TagKind::Custom("committer".to_string()), | ||
| 392 | git_repo.get_commit_comitter(commit)?, | ||
| 393 | ), | ||
| 394 | // TODO: add Repo event tags | ||
| 395 | // TODO: people tag maintainers | ||
| 396 | // TODO: add relay tags | ||
| 397 | ], | ||
| 398 | ) | ||
| 399 | .to_event(keys) | ||
| 400 | .context("failed to sign event") | ||
| 401 | } | ||
| 380 | // TODO | 402 | // TODO |
| 381 | // - find profile | 403 | // - find profile |
| 382 | // - file relays | 404 | // - file relays |