-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathGenerateScriptCommand.cs
More file actions
141 lines (122 loc) · 6.27 KB
/
Copy pathGenerateScriptCommand.cs
File metadata and controls
141 lines (122 loc) · 6.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System;
using System.CommandLine;
using System.IO;
using System.Runtime.CompilerServices;
using Microsoft.Extensions.DependencyInjection;
using OctoshiftCLI.Commands;
using OctoshiftCLI.Contracts;
using OctoshiftCLI.Extensions;
using OctoshiftCLI.GithubEnterpriseImporter.Factories;
using OctoshiftCLI.Services;
[assembly: InternalsVisibleTo("OctoshiftCLI.Tests")]
namespace OctoshiftCLI.GithubEnterpriseImporter.Commands.GenerateScript
{
public class GenerateScriptCommand : CommandBase<GenerateScriptCommandArgs, GenerateScriptCommandHandler>
{
public GenerateScriptCommand() : base(
name: "generate-script",
description: "Generates a migration script. This provides you the ability to review the steps that this tool will take, and optionally modify the script if desired before running it.")
{
AddOption(GithubSourceOrg);
AddOption(GithubTargetOrg);
AddOption(TargetApiUrl);
AddOption(TargetUploadsUrl);
AddOption(GhesApiUrl);
AddOption(AwsBucketName);
AddOption(AwsRegion);
AddOption(NoSslVerify);
AddOption(DownloadMigrationLogs);
AddOption(SkipReleases);
AddOption(LockSourceRepo);
AddOption(Output);
AddOption(Sequential);
AddOption(GithubSourcePat);
AddOption(Verbose);
AddOption(KeepArchive);
AddOption(UseGithubStorage);
}
public Option<string> GithubSourceOrg { get; } = new("--github-source-org")
{
Description = "Uses GH_SOURCE_PAT env variable or --github-source-pat option. Will fall back to GH_PAT if not set.",
IsRequired = true,
};
public Option<string> GithubTargetOrg { get; } = new("--github-target-org")
{
IsRequired = true
};
// GHES migration path
public Option<string> GhesApiUrl { get; } = new("--ghes-api-url")
{
Description = "Required if migrating from GHES. The api endpoint for the hostname of your GHES instance. For example: http(s)://myghes.com/api/v3"
};
public Option<bool> NoSslVerify { get; } = new("--no-ssl-verify")
{
Description = "Only effective if migrating from GHES. Disables SSL verification when communicating with your GHES instance. All other migration steps will continue to verify SSL. If your GHES instance has a self-signed SSL certificate then setting this flag will allow data to be extracted."
};
public Option<bool> SkipReleases { get; } = new("--skip-releases")
{
Description = "Skip releases when migrating."
};
public Option<bool> LockSourceRepo { get; } = new("--lock-source-repo")
{
Description = "Lock the source repository when migrating."
};
public Option<bool> DownloadMigrationLogs { get; } = new("--download-migration-logs")
{
Description = "Downloads the migration log for each repository migration."
};
public Option<FileInfo> Output { get; } = new("--output", () => new FileInfo("./migrate.ps1"));
public Option<bool> Sequential { get; } = new("--sequential")
{
Description = "Waits for each migration to finish before moving on to the next one."
};
public Option<string> GithubSourcePat { get; } = new("--github-source-pat");
public Option<string> AwsBucketName { get; } = new("--aws-bucket-name")
{
Description = "If using AWS, the name of the S3 bucket to upload the BBS archive to."
};
public Option<string> AwsRegion { get; } = new("--aws-region")
{
Description = "If using AWS, the AWS region. If not provided, it will be read from AWS_REGION environment variable. " +
"Required if using AWS."
};
public Option<bool> Verbose { get; } = new("--verbose");
public Option<bool> KeepArchive { get; } = new("--keep-archive")
{
Description = "Keeps the archive on this machine after uploading to the blob storage account. Only applicable for migrations from GitHub Enterprise Server versions before 3.8.0."
};
public Option<string> TargetApiUrl { get; } = new("--target-api-url")
{
Description = "The URL of the target API, if not migrating to github.com. Defaults to https://api.github.com"
};
public Option<string> TargetUploadsUrl { get; } = new(
name: "--target-uploads-url",
description: "The URL of the target uploads API, if not migrating to github.com. Defaults to https://uploads.github.com");
public Option<bool> UseGithubStorage { get; } = new("--use-github-storage")
{
IsHidden = true,
Description = "Enables multipart uploads to a GitHub owned storage for use during migration. " +
"Configure chunk size with the GITHUB_OWNED_STORAGE_MULTIPART_MEBIBYTES environment variable (default: 100 MiB, minimum: 5 MiB).",
};
public override GenerateScriptCommandHandler BuildHandler(GenerateScriptCommandArgs args, IServiceProvider sp)
{
if (args is null)
{
throw new ArgumentNullException(nameof(args));
}
if (sp is null)
{
throw new ArgumentNullException(nameof(sp));
}
var log = sp.GetRequiredService<OctoLogger>();
var versionProvider = sp.GetRequiredService<IVersionProvider>();
var ghesVersionCheckerFactory = sp.GetRequiredService<GhesVersionCheckerFactory>();
var sourceGithubApiFactory = sp.GetRequiredService<ISourceGithubApiFactory>();
var sourceGithubApi = args.GhesApiUrl.HasValue() && args.NoSslVerify ?
sourceGithubApiFactory.CreateClientNoSsl(args.GhesApiUrl, args.TargetUploadsUrl, args.GithubSourcePat) :
sourceGithubApiFactory.Create(args.GhesApiUrl, args.TargetUploadsUrl, args.GithubSourcePat);
var ghesVersionChecker = ghesVersionCheckerFactory.Create(sourceGithubApi);
return new GenerateScriptCommandHandler(log, sourceGithubApi, versionProvider, ghesVersionChecker);
}
}
}