diff --git a/go.mod b/go.mod index 66a9905..6c5458d 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,40 @@ module git.watzon.tech/watzon/gittogiteamigrator -go 1.16 +go 1.19 require ( - gitea.com/gitea/go-sdk v0.16.0 // indirect - github.com/c-bata/go-prompt v0.2.5 + code.gitea.io/sdk/gitea v0.16.0 github.com/cqroot/prompt v0.9.2 - github.com/go-git/go-git/v5 v5.4.2 - github.com/google/go-github v17.0.0+incompatible // indirect - github.com/google/go-querystring v1.1.0 // indirect - github.com/manifoldco/promptui v0.9.0 + github.com/google/go-github v17.0.0+incompatible + golang.org/x/exp v0.0.0-20231006140011-7918f672742d ) + +require ( + github.com/atotto/clipboard v0.1.4 // indirect + github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect + github.com/charmbracelet/bubbles v0.16.1 // indirect + github.com/charmbracelet/bubbletea v0.24.2 // indirect + github.com/charmbracelet/lipgloss v0.8.0 // indirect + github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect + github.com/cqroot/multichoose v0.1.0 // indirect + github.com/davidmz/go-pageant v1.0.2 // indirect + github.com/go-fed/httpsig v1.1.0 // indirect + github.com/google/go-querystring v1.1.0 // indirect + github.com/hashicorp/go-version v1.5.0 // indirect + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/mattn/go-isatty v0.0.18 // indirect + github.com/mattn/go-localereader v0.0.1 // indirect + github.com/mattn/go-runewidth v0.0.14 // indirect + github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect + github.com/muesli/cancelreader v0.2.2 // indirect + github.com/muesli/reflow v0.3.0 // indirect + github.com/muesli/termenv v0.15.2 // indirect + github.com/rivo/uniseg v0.2.0 // indirect + golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect + golang.org/x/sync v0.1.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/term v0.6.0 // indirect + golang.org/x/text v0.3.8 // indirect +) + +replace github.com/cqroot/multichoose => github.com/watzon/multichoose v0.0.0-20231015011001-4dd5b66c067c diff --git a/go.sum b/go.sum index a1d5189..5c854d6 100644 --- a/go.sum +++ b/go.sum @@ -1,183 +1,91 @@ -gitea.com/gitea/go-sdk v0.16.0 h1:+RMe47IkCPVtlzfGjfpEt/XeECl5mjuwvP8bPsMrMHc= -gitea.com/gitea/go-sdk v0.16.0/go.mod h1:r9S7LXuEumOEDhkZ9qHLhHSnTO6XNnKiBEbunPJJY+8= -github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= -github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= -github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo= -github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= -github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= -github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= +code.gitea.io/sdk/gitea v0.16.0 h1:gAfssETO1Hv9QbE+/nhWu7EjoFQYKt6kPoyDytQgw00= +code.gitea.io/sdk/gitea v0.16.0/go.mod h1:ndkDk99BnfiUCCYEUhpNzi0lpmApXlwRFqClBlOlEBg= github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= -github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw= github.com/charmbracelet/bubbles v0.16.1 h1:6uzpAAaT9ZqKssntbvZMlksWHruQLNxg49H5WdeuYSY= github.com/charmbracelet/bubbles v0.16.1/go.mod h1:2QCp9LFlEsBQMvIYERr7Ww2H2bA7xen1idUDIzm/+Xc= -github.com/charmbracelet/bubbletea v0.24.1/go.mod h1:rK3g/2+T8vOSEkNHvtq40umJpeVYDn6bLaqbgzhL/hg= github.com/charmbracelet/bubbletea v0.24.2 h1:uaQIKx9Ai6Gdh5zpTbGiWpytMU+CfsPp06RaW2cx/SY= github.com/charmbracelet/bubbletea v0.24.2/go.mod h1:XdrNrV4J8GiyshTtx3DNuYkR1FDaJmO3l2nejekbsgg= -github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao= -github.com/charmbracelet/lipgloss v0.7.1/go.mod h1:yG0k3giv8Qj8edTCbbg6AlQ5e8KNWpFujkNawKNhE2c= github.com/charmbracelet/lipgloss v0.8.0 h1:IS00fk4XAHcf8uZKc3eHeMUTCxUH6NkaTrdyCQk84RU= github.com/charmbracelet/lipgloss v0.8.0/go.mod h1:p4eYUZZJ/0oXTuCQKFF8mqyKCz0ja6y+7DniDDw5KKU= -github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= -github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= -github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY= github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk= -github.com/cqroot/multichoose v0.1.0 h1:525pYO4VrdVH17JJdNAV2bacygF0jJ+BfM0HM6XqjDg= -github.com/cqroot/multichoose v0.1.0/go.mod h1:BJzIGqbQZNADPDuA3IzhmTMpRc2F3fZKysMRYP+Ydw8= github.com/cqroot/prompt v0.9.2 h1:v0NLgJuX9rV0cA1a2vtQeUxGYncArPczGW1KE53k+1w= github.com/cqroot/prompt v0.9.2/go.mod h1:nfbg6JiJ/pbe3JVBKuSDeQfkZqnYYBOMG2PAIc94Nsk= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= -github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= -github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= -github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= -github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E= -github.com/go-git/go-billy/v5 v5.2.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0= -github.com/go-git/go-billy/v5 v5.3.1/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0= -github.com/go-git/go-git-fixtures/v4 v4.2.1/go.mod h1:K8zd3kDUAykwTdDCr+I0per6Y6vMiRR/nnVTBtavnB0= -github.com/go-git/go-git/v5 v5.4.2/go.mod h1:gQ1kArt6d+n+BGd+/B/I74HwRTLhth2+zti4ihgckDc= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0= +github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE= +github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI= +github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= -github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= -github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= -github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= -github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/hashicorp/go-version v1.5.0 h1:O293SZ2Eg+AAYijkVK3jR786Am1bhDEh2GHT0tIVE5E= +github.com/hashicorp/go-version v1.5.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= -github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA= -github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= -github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98= github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= -github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= -github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34= github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho= github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= -github.com/muesli/termenv v0.15.1/go.mod h1:HeAQPTzpfs016yGtA4g00CsdYnVLJvxsS4ANqrZs2sQ= github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo= github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= -github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= -github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/watzon/multichoose v0.0.0-20231015011001-4dd5b66c067c h1:JraadlhhJIO5VbUtst+Z+9JiLwP0VaHXr0QakESz5nY= +github.com/watzon/multichoose v0.0.0-20231015011001-4dd5b66c067c/go.mod h1:BJzIGqbQZNADPDuA3IzhmTMpRc2F3fZKysMRYP+Ydw8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= +golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e h1:T8NU3HyQ8ClP4SEE+KbFlg6n0NhuTsN4MyznaarGsZM= +golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79 h1:RX8C8PRZc2hTIod4ds8ij+/4RQX3AqhYj3uOHmyaz4E= -golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= -golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/main.go b/main.go index 3c82aac..ca12637 100644 --- a/main.go +++ b/main.go @@ -1,77 +1,51 @@ package main import ( - "context" "errors" "fmt" "os" + "regexp" + "strings" + "code.gitea.io/sdk/gitea" "github.com/cqroot/prompt" "github.com/cqroot/prompt/input" "github.com/cqroot/prompt/multichoose" "github.com/google/go-github/github" + "golang.org/x/exp/slices" ) -func CheckErr(err error) { - if err != nil { - if errors.Is(err, prompt.ErrUserQuit) { - fmt.Fprintln(os.Stderr, "Error:", err) - os.Exit(1) - } else { - panic(err) - } - } -} - -// authenticateGithub authenticates the user with Github using their username -// and password. -// A Github client is returned. -func authenticateGithub(username string, password string, otp string) *github.Client { - ctx := context.Background() - ts := github.BasicAuthTransport{ - Username: username, - Password: password, - OTP: otp, - } - client := github.NewClient(ts.Client()) - _, _, err := client.Users.Get(ctx, "") - if err != nil { - fmt.Println("Error", err) - } - return client -} - // getGithubUsername prompts the user for their Github username. // The username is returned as a string. func getGithubUsername() string { result, err := prompt.New().Ask("Github username").Input("johndoe69") - CheckErr(err) + checkErr(err) return result } -// getGithubPassword prompts the user for their Github password. -// The password is returned as a string. -func getGithubPassword() string { - result, err := prompt.New().Ask("Github password or token"). +// getGithubToken prompts the user for their Github token. +// The token is returned as a string. +func getGithubToken() string { + result, err := prompt.New().Ask("Github personal access token"). Input("", input.WithEchoMode(input.EchoPassword)) - CheckErr(err) + checkErr(err) return result } -// getGithubOTP prompts the user for their Github OTP. -// The OTP is returned as a string. -func getGithubOTP() string { - result, err := prompt.New().Ask("Github OTP (if you used a token, leave blank)"). - Input("", input.WithEchoMode(input.EchoPassword)) - CheckErr(err) +// getGiteaHost prompts the user for the host of their Gitea instance. +// The host is returned as a string. +func getGiteaHost() string { + result, err := prompt.New().Ask("Gitea host").Input("https://gitea.com") + checkErr(err) return result } -// getGiteaUsername prompts the user for their Gitea username. +// getGiteaUser prompts the user for their Gitea username. This is where the +// repositories will be migrated to. // The username is returned as a string. -func getGiteaUsername() string { +func getGiteaUser() string { result, err := prompt.New().Ask("Gitea username").Input("johndoe69") - CheckErr(err) + checkErr(err) return result } @@ -80,7 +54,7 @@ func getGiteaUsername() string { func getGiteaToken() string { result, err := prompt.New().Ask("Gitea application token"). Input("", input.WithEchoMode(input.EchoPassword)) - CheckErr(err) + checkErr(err) return result } @@ -92,61 +66,31 @@ func getGiteaToken() string { // Once the user has selected how they want to select repositories, they will be // prompted to select repositories based on their chosen method. // The selected repositories are returned as a list of strings. -func getRepos(client *github.Client) []string { +func getRepos(client *github.Client, user string, organization bool) []string { result, err := prompt.New().Ask("How do you want to select repositories?"). Choose([]string{"Fetch from Github", "Enter manually", "File path", "Filters"}) - CheckErr(err) + checkErr(err) + var repos []string switch result { case "Fetch from Github": - return getReposFromGithub(client) - // case "Enter manually": - // return getReposManually() - // case "File path": - // return getReposFromFile() - // case "Filters": - // return getReposFromFilters(client) + repos = getReposFromGithub(client) + case "Enter manually": + repos = getReposManually() + case "File path": + repos = getReposFromFile() + case "Filters": + repos = getReposByType(client, user, organization) } - return nil -} -// fetchReposForUser fetches a list of all repositories from github for the given user -// or organization. Github by default only returns 30 repositories at a time, so this -// function will make multiple requests to github to fetch all repositories. -// The list of repositories is returned as a list of strings. -func fetchReposForUser(client *github.Client, user string, organization bool) []string { - var repos []string - var page int = 1 - var per_page int = 30 - for { - var repo_list []*github.Repository - var err error - if organization { - repo_list, _, err = client.Repositories.ListByOrg(context.Background(), user, &github.RepositoryListByOrgOptions{ - ListOptions: github.ListOptions{ - Page: page, - PerPage: per_page, - }, - }) - } else { - repo_list, _, err = client.Repositories.List(context.Background(), user, &github.RepositoryListOptions{ - ListOptions: github.ListOptions{ - Page: page, - PerPage: per_page, - }, - }) - } - if err != nil { - fmt.Println("Error", err) - } - if len(repo_list) == 0 { - break - } - for _, repo := range repo_list { - repos = append(repos, fmt.Sprintf("%s/%s", user, repo.GetName())) - } - page++ + should_continue, err := prompt.New().Ask(fmt.Sprintf("You have selected %d repositories. Continue?", len(repos))). + Choose([]string{"Yes", "No"}) + checkErr(err) + + if should_continue == "No" { + os.Exit(0) } + return repos } @@ -158,29 +102,214 @@ func fetchReposForUser(client *github.Client, user string, organization bool) [] func getReposFromGithub(client *github.Client) []string { result, err := prompt.New().Ask("Select repositories from:"). Choose([]string{"Organization", "User"}) - CheckErr(err) + checkErr(err) var repo_names []string switch result { case "Organization": result, err := prompt.New().Ask("Organization name").Input("acme") - CheckErr(err) + checkErr(err) repos := fetchReposForUser(client, result, true) repo_names = append(repo_names, repos...) case "User": result, err := prompt.New().Ask("User name").Input("johndoe69") - CheckErr(err) + checkErr(err) repos := fetchReposForUser(client, result, false) repo_names = append(repo_names, repos...) } selected, err := prompt.New().Ask("Select repositories:"). MultiChoose(repo_names, multichoose.WithTheme(ThemeScroll)) - CheckErr(err) + checkErr(err) return selected } +// getReposManually prompts the user to enter a list of repositories manually. +// The list of repositories is returned as a list of strings. +func getReposManually() []string { + result, err := prompt.New().Ask("Enter repositories manually"). + Input("acme/repo1, acme/repo2, johndoe69/repo3") + checkErr(err) + + repos := regexp.MustCompile(`\s*,\s*`).Split(result, -1) + for i, repo := range repos { + repos[i] = regexp.MustCompile(`^https?://(www.)?github.com/`).ReplaceAllString(repo, "") + } + return repos +} + +// getReposFromFile prompts the user to enter a path to a file containing a repository +// on each line. It then reads the file and returns the list of repositories as a list +// of strings. +func getReposFromFile() []string { + result, err := prompt.New().Ask("Enter path to file containing repositories (one on each line)"). + Input("./repos.txt") + checkErr(err) + + data, err := os.ReadFile(result) + checkErr(err) + + // Convert the bytes into a string + str := string(data) + repos := regexp.MustCompile(`\s*\n\s*`).Split(str, -1) + + for i, repo := range repos { + repos[i] = regexp.MustCompile(`^https?://(www.)?github.com/`).ReplaceAllString(repo, "") + } + return repos +} + +// getReposByType prompts the user to select the types of repositories they want to migrate. +// The selected repositories are returned as a list of strings. +func getReposByType(client *github.Client, user string, organization bool) []string { + types, err := prompt.New().Ask("Select visibility:"). + MultiChoose([]string{"All", "Public", "Private", "Forks", "Sources", "Member"}) + checkErr(err) + + repos := fetchReposByType(client, user, organization, types) + return repos +} + +// getRepoVisibility prompts the user to select the visibility of the migrated repositories. +// The selected visibility is returned as a string. +func getRepoVisibility() string { + result, err := prompt.New().Ask("Select visibility:"). + Choose([]string{"Maintain", "Public", "Private"}) + checkErr(err) + + return result +} + +// getShouldMirror prompts the user to select whether they want to mirror the +// repositories, or migrate them as a one-time copy. +// The user's selection is returned as a boolean. +func getShouldMirror() bool { + result, err := prompt.New().Ask("Mirror repositories"). + Choose([]string{"Yes", "No"}) + checkErr(err) + + if result == "Yes" { + return true + } + return false +} + +// getItemsToMigrate prompts the user to select which items they want to migrate. +// The user's selection is returned as a list of strings. +func getItemsToMigrate() []string { + result, err := prompt.New().Ask("Select items to migrate:"). + MultiChoose([]string{"Issues", "Wiki", "Labels", "Pull Requests", "Milestones", "Releases"}) + checkErr(err) + + return result +} + +// getPushMirrorToGithub prompts the user to select whether they want to push +// changes to the mirror on Gitea to the original repository on Github. +// The user's selection is returned as a boolean. +func getPushMirrorToGithub() bool { + result, err := prompt.New().Ask("Would you like to mirror pushes to github?"). + Choose([]string{"Yes", "No"}) + checkErr(err) + + if result == "Yes" { + return true + } + return false +} + +// getUseGithubIssueTracker prompts the user to select whether they want to use +// the github issue tracker, or migrate issues. This option is only available if +// issues are not being migrated. +// The user's selection is returned as a boolean. +func getUseGithubIssueTracker() bool { + result, err := prompt.New().Ask("Use Github issue tracker"). + Choose([]string{"Yes", "No"}) + checkErr(err) + + if result == "Yes" { + return true + } + return false +} + +type MigrationOptions struct { + github_client *github.Client + gitea_client *gitea.Client + github_user string + github_token string + gitea_user string + repos []string + visibility_map map[string]string + visibility string + should_mirror bool + use_github_issue_tracker bool + push_mirror_to_github bool + items_to_migrate []string +} + +// executeMigration executes the migration process. +// The migration process is executed with the given options. +// If an error occurs during the migration process, it is returned. +func executeMigration(options *MigrationOptions) error { + repos := options.repos + gitea_client := options.gitea_client + var errs error + + for _, repo := range repos { + fmt.Printf("Migrating %s...\n", repo) + repo_address := fmt.Sprintf("https://github.com/%s", repo) + repo_parts := strings.Split(repo, "/") + repo_name := repo_parts[1] + visibility := "public" + if options.visibility == "Maintain" { + visibility = options.visibility_map[repo] + } + + new_repo, _, err := gitea_client.MigrateRepo(gitea.MigrateRepoOption{ + RepoOwner: options.gitea_user, + RepoName: repo_name, + CloneAddr: repo_address, + Service: gitea.GitServiceGithub, + AuthUsername: options.github_user, + AuthToken: options.github_token, + Mirror: options.should_mirror, + Private: visibility == "private", + Wiki: slices.Contains(options.items_to_migrate, "Wiki"), + Milestones: slices.Contains(options.items_to_migrate, "Milestones"), + Labels: slices.Contains(options.items_to_migrate, "Labels"), + PullRequests: slices.Contains(options.items_to_migrate, "Pull Requests"), + Releases: slices.Contains(options.items_to_migrate, "Releases"), + Issues: slices.Contains(options.items_to_migrate, "Issues"), + }) + + if err != nil { + errs = errors.Join(errs, err) + continue + } + + if options.use_github_issue_tracker { + hasIssues := true + _, _, err := gitea_client.EditRepo(new_repo.Owner.UserName, new_repo.Name, gitea.EditRepoOption{ + HasIssues: &hasIssues, + ExternalTracker: &gitea.ExternalTracker{ + ExternalTrackerURL: repo_address + "/issues", + ExternalTrackerFormat: "https://github.com/{user}/{repo}/issues/{index}", + ExternalTrackerStyle: "numeric", + }, + }) + + if err != nil { + errs = errors.Join(errs, err) + continue + } + } + } + + return errs +} + // Github to Gitea migration tool. // This tool will migrate selected repositories from Github to Gitea, // based on user input. This process is entirely interactive. @@ -197,49 +326,55 @@ func getReposFromGithub(client *github.Client) []string { func main() { fmt.Println("Welcome to the Github to Gitea migration tool!") - // githubUsername := getGithubUsername() - // githubPassword := getGithubPassword() - // githubOTP := getGithubOTP() - githubClient := authenticateGithub("watzon", "password", "") + githubUsername := getGithubUsername() + githubToken := getGithubToken() + githubClient := authenticateGithub(githubUsername, githubToken) - // giteaUsername := getGiteaUsername() - // giteaToken := getGiteaToken() - // giteaClient = authenticateGitea(giteaUsername, giteaToken) + giteaHost := getGiteaHost() + giteaUser := getGiteaUser() + giteaToken := getGiteaToken() + giteaClient := authenticateGitea(giteaHost, giteaUser, giteaToken) - repos := getRepos(githubClient) + repos := getRepos(githubClient, "watzon", false) + repo_visibility := getRepoVisibility() - fmt.Println(repos) + var visibility_map map[string]string + if repo_visibility == "Maintain" { + visibility_map = buildRepoVisibilityMap(githubClient, repos) + } - // should_mirror := getMirror() + should_mirror := getShouldMirror() + to_migrate := getItemsToMigrate() - // should_migrate_issues, use_github_issue_tracker := getIssues() - // repos_by_visibility := getVisibility(repos) - // should_migrate_wiki := getWiki() - // should_migrate_labels := getLabels() - // should_migrate_pull_requests := getPullRequests() - // should_migrate_milestones := getMilestones() - // should_migrate_releases := getReleases() - - // res, err = execute_migration(&MigrationOptions{ - // githubUsername: githubUsername, - // githubPassword: githubPassword, - // giteaUsername: giteaUsername, - // giteaToken: giteaToken, - // repos: repos, - // should_mirror: should_mirror, - // should_migrate_issues: should_migrate_issues, - // use_github_issue_tracker: use_github_issue_tracker, - // repos_by_visibility: repos_by_visibility, - // should_migrate_wiki: should_migrate_wiki, - // should_migrate_labels: should_migrate_labels, - // should_migrate_pull_requests: should_migrate_pull_requests, - // should_migrate_milestones: should_migrate_milestones, - // should_migrate_releases: should_migrate_releases, - // }) - - // if err != nil { - // fmt.Println("Error", err) - // } else { - // fmt.Println("Migration completed successfully!") + push_mirror_to_github := false + // TODO: Waiting on https://gitea.com/gitea/go-sdk/issues/635 + // if !should_mirror { + // push_mirror_to_github = getPushMirrorToGithub() // } + + use_github_issue_tracker := false + if !slices.Contains(to_migrate, "Issues") { + use_github_issue_tracker = getUseGithubIssueTracker() + } + + err := executeMigration(&MigrationOptions{ + github_client: githubClient, + gitea_client: giteaClient, + github_user: githubUsername, + github_token: githubToken, + gitea_user: giteaUser, + repos: repos, + visibility_map: visibility_map, + visibility: repo_visibility, + should_mirror: should_mirror, + use_github_issue_tracker: use_github_issue_tracker, + items_to_migrate: to_migrate, + push_mirror_to_github: push_mirror_to_github, + }) + + if err != nil { + fmt.Println("Error", err) + } else { + fmt.Println("Migration completed successfully!") + } } diff --git a/run.sh b/run.sh deleted file mode 100644 index 16cab07..0000000 --- a/run.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -go run main.go auth.go repo.go migrate.go error.go diff --git a/utils.go b/utils.go new file mode 100644 index 0000000..4750be1 --- /dev/null +++ b/utils.go @@ -0,0 +1,150 @@ +package main + +import ( + "context" + "errors" + "fmt" + "os" + "strings" + + "code.gitea.io/sdk/gitea" + "github.com/cqroot/prompt" + "github.com/google/go-github/github" +) + +// fetchReposForUser fetches a list of all repositories from github for the given user +// or organization. Github by default only returns 30 repositories at a time, so this +// function will make multiple requests to github to fetch all repositories. +// The list of repositories is returned as a list of strings. +func fetchReposForUser(client *github.Client, user string, organization bool) []string { + var repos []string + var page int = 1 + var per_page int = 30 + for { + var repo_list []*github.Repository + var err error + if organization { + repo_list, _, err = client.Repositories.ListByOrg(context.Background(), user, &github.RepositoryListByOrgOptions{ + ListOptions: github.ListOptions{ + Page: page, + PerPage: per_page, + }, + }) + } else { + repo_list, _, err = client.Repositories.List(context.Background(), user, &github.RepositoryListOptions{ + ListOptions: github.ListOptions{ + Page: page, + PerPage: per_page, + }, + }) + } + checkErr(err) + if len(repo_list) == 0 { + break + } + for _, repo := range repo_list { + repos = append(repos, fmt.Sprintf("%s/%s", user, repo.GetName())) + } + page++ + } + return repos +} + +// fetchReposByType fetches a list of repositories from github for the given user based on the +// type of repository (public, private, all, etc.). +// The list of repositories is returned as a list of strings. +func fetchReposByType(client *github.Client, user string, organization bool, types []string) []string { + var repos []string + var page int = 1 + var per_page int = 30 + for { + repo_mega_list := make([]*github.Repository, 0) + for _, repo_type := range types { + var repo_list []*github.Repository + var err error + if organization { + repo_list, _, err = client.Repositories.ListByOrg(context.Background(), user, &github.RepositoryListByOrgOptions{ + Type: repo_type, + ListOptions: github.ListOptions{ + Page: page, + PerPage: per_page, + }, + }) + } else { + repo_list, _, err = client.Repositories.List(context.Background(), user, &github.RepositoryListOptions{ + Type: repo_type, + ListOptions: github.ListOptions{ + Page: page, + PerPage: per_page, + }, + }) + } + checkErr(err) + repo_mega_list = append(repo_mega_list, repo_list...) + } + if len(repo_mega_list) == 0 { + break + } + for _, repo := range repo_mega_list { + repos = append(repos, fmt.Sprintf("%s/%s", user, repo.GetName())) + } + page++ + } + return repos +} + +// buildRepoVisibilityMap builds a map of repository names to their visibility (public or private). +// The list of pairs is returned as a list of strings. +func buildRepoVisibilityMap(client *github.Client, repos []string) map[string]string { + var repo_visibility_list = make(map[string]string) + for _, repo_name := range repos { + parts := strings.Split(repo_name, "/") + + repo, _, err := client.Repositories.Get(context.Background(), parts[0], parts[1]) + checkErr(err) + + visibility := "public" + if *repo.Private { + visibility = "private" + } + + repo_visibility_list[repo_name] = visibility + } + return repo_visibility_list +} + +func checkErr(err error) { + if err != nil { + if errors.Is(err, prompt.ErrUserQuit) { + fmt.Fprintln(os.Stderr, "Error:", err) + os.Exit(1) + } else { + panic(err) + } + } +} + +// authenticateGithub authenticates the user with Github using their username +// and password. +// A Github client is returned. +func authenticateGithub(username string, token string) *github.Client { + ctx := context.Background() + ts := github.BasicAuthTransport{ + Username: username, + Password: token, + } + client := github.NewClient(ts.Client()) + _, _, err := client.Users.Get(ctx, "") + if err != nil { + fmt.Println("Error", err) + } + return client +} + +func authenticateGitea(host string, user string, token string) *gitea.Client { + client, err := gitea.NewClient(host, gitea.SetBasicAuth(user, token)) + checkErr(err) + _, _, err = client.GetMyUserInfo() + checkErr(err) + return client +}