From b7b60faedb44dad2b49ad080c131c21935d1334a Mon Sep 17 00:00:00 2001 From: RGBCube Date: Wed, 7 Feb 2024 16:35:46 +0300 Subject: [PATCH] Allow specifiying specific repos --- README.md | 8 ++++++++ migrate.nu | 23 ++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d84e71d..257605e 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,14 @@ This works on any Gitea or Forgejo instance. This is good for when you are migrating off GitHub permanently and will never come back. +### Can I migrate specific repositories? + +Sure, just pass the URLs to them as arguments: + +```nu +./migrate.nu https://github.com/RGBCube/Foo https://github.com/RGBCube/Bar +``` + ## License ``` diff --git a/migrate.nu b/migrate.nu index e66b0e7..8ce8907 100755 --- a/migrate.nu +++ b/migrate.nu @@ -13,9 +13,10 @@ def main [ --github-user: string = "" # The user to migrate from. --github-token: string = "" # An access token for fetching private repositories. Optional. --gitea-url: string = "" # The URL to the Gitea or Forgejo instance - --gitea-user: string = "" # The user to mirror or clone the repositories to. + --gitea-user: string = "" # The user to migrate the repositories to. --gitea-token: string = "" # An access token for the user to actually insert repositories to. --strategy: string = "" # The strategy. Valid options are "Mirrored" or "Cloned" (case sensitive). + ...repo_urls: string # The GitHub repo URLs to migrate to Gitea or Forgejo. If not given, all will be fetched. ] { let github_user = $github_user | str-or { input $"(ansi red)GitHub username: (ansi reset)" } let github_token = $github_token | str-or { input $"(ansi red)GitHub access token (ansi yellow)\((ansi blue)optional, only used for private repositories(ansi yellow))(ansi red): (ansi reset)" } @@ -46,15 +47,19 @@ def main [ let strategy = $strategy | str-or { [ Mirrored Cloned ] | input list $"(ansi cyan)Should the repos be mirrored, or just cloned once? (ansi reset)" } - let repo_urls = if $github_token != "" { - ( - http get $"https://api.github.com/users/($github_user)/repos?per_page=100" - -H [ Authorization $"token ($github_token)" ] - ) - | get html_url + let repo_urls = if ($repo_urls | length) != 0 { + $repo_urls } else { - http get $"https://api.github.com/users/($github_user)/repos?per_page=100" - | get html_url + if $github_token != "" { + ( + http get $"https://api.github.com/users/($github_user)/repos?per_page=100" + -H [ Authorization $"token ($github_token)" ] + ) + | get html_url + } else { + http get $"https://api.github.com/users/($github_user)/repos?per_page=100" + | get html_url + } } $repo_urls | each {|url|