mirror of
https://github.com/RGBCube/github2forgejo
synced 2026-01-13 08:41:03 +00:00
feat: add dry mode
This commit is contained in:
parent
18d6f21d6d
commit
e473d9db01
3 changed files with 27 additions and 2 deletions
|
|
@ -14,6 +14,10 @@ Migrates a GitHub users or organizations repositories to a Forgejo instance.
|
|||
|
||||
Accepted environment variables:
|
||||
|
||||
DRY:
|
||||
Only print the actions that will be taken, and don't execute.
|
||||
Defaults to false, and a lack of the variable will be interpreted as false.
|
||||
|
||||
GITHUB_USER:
|
||||
The user or organization to fetch the repositories from.
|
||||
Case sensitive.
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@
|
|||
File containing environment variables required by GitHub2Forgejo,
|
||||
in the format of an EnvironmentFile as described by {manpage}`systemd.exec(5)`.
|
||||
|
||||
You must set ALL of these environment variables:
|
||||
You must set ALL of these environment variables (and to leave
|
||||
one "unspecified" you will have to set it to an emtpy string):
|
||||
|
||||
GITHUB_USER:
|
||||
The user or organization to fetch the repositories from.
|
||||
|
|
@ -68,7 +69,11 @@
|
|||
Whether to delete a mirrored repo from the Forgejo instance if the
|
||||
source on GitHub doesn't exist anymore. Must be either "true" or "false".
|
||||
|
||||
You must set an environment variable to an empty string to leave it "unset".
|
||||
You can also set these, but they are not required:
|
||||
|
||||
DRY:
|
||||
Only print the actions that will be taken, and don't execute.
|
||||
Defaults to false, and a lack of the variable will be interpreted as false.
|
||||
'';
|
||||
|
||||
example = "/secrets/github2forgejo.env";
|
||||
|
|
|
|||
|
|
@ -12,6 +12,10 @@ def or-default [default: closure] {
|
|||
#
|
||||
# Accepted environment variables:
|
||||
#
|
||||
# DRY:
|
||||
# Only print the actions that will be taken, and don't execute.
|
||||
# Defaults to false, and a lack of the variable will be interpreted as false.
|
||||
#
|
||||
# GITHUB_USER:
|
||||
# The user or organization to fetch the repositories from.
|
||||
# Case sensitive.
|
||||
|
|
@ -39,6 +43,8 @@ def or-default [default: closure] {
|
|||
#
|
||||
# To leave an environment variable unspecified, set it to an empty string.
|
||||
def main [] {
|
||||
let dry = $env | get --optional DRY | into bool --relaxed
|
||||
|
||||
let github_user = $env | get --optional GITHUB_USER | or-default { input $"(ansi red)GitHub username: (ansi reset)" }
|
||||
let github_token = $env | get --optional GITHUB_TOKEN | or-default { input $"(ansi red)GitHub access token (ansi yellow)\((ansi blue)optional, only used for private repositories(ansi yellow))(ansi red): (ansi reset)" }
|
||||
let forgejo_url = $env | get --optional FORGEJO_URL | or-default { input $"(ansi green)Forgejo instance URL \(with https://): (ansi reset)" } | str trim --right --char "/"
|
||||
|
|
@ -97,6 +103,11 @@ def main [] {
|
|||
$forgejo_not_on_github | each {|forgejo_repo|
|
||||
print --no-newline $"(ansi red)Deleting (ansi yellow)($forgejo_url)/($forgejo_repo.full_name)(ansi red) because the mirror source doesn't exist on GitHub anymore...(ansi reset)"
|
||||
|
||||
if $dry {
|
||||
print $" (ansi yellow)Dry run, so can't know result as I'm not actually doing it.(ansi reset)"
|
||||
return
|
||||
}
|
||||
|
||||
(http delete $"($forgejo_url)/api/v1/repos/($forgejo_repo.full_name)"
|
||||
-H [ Authorization $"token ($forgejo_token)" ])
|
||||
|
||||
|
|
@ -115,6 +126,11 @@ def main [] {
|
|||
$"(ansi green)public(ansi blue)(char space)"
|
||||
}) repository (ansi purple)($github_repo.html_url)(ansi blue) to (ansi white_bold)($forgejo_url)/($forgejo_user)/($github_repo.name)(ansi blue)...(ansi reset)"
|
||||
|
||||
if $dry {
|
||||
print $" (ansi yellow)Dry run, so can't know result as I'm not actually doing it.(ansi reset)"
|
||||
return
|
||||
}
|
||||
|
||||
let response = (
|
||||
http post $"($forgejo_url)/api/v1/repos/migrate"
|
||||
--allow-errors
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue