-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.sh
executable file
·147 lines (127 loc) · 3.35 KB
/
import.sh
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
142
143
144
145
146
147
#!/bin/bash
### variables to call external dependencies.
script_path=$(dirname "$0")
###
info_color="\033[0;36m"
if [ -z "$TARGET_PAT" ]; then
echo "TARGET_PAT environment variable missing"
exit 1
fi
if [ "$#" -ne 5 ];
then
echo "Usage: $0 <org> <source repo url> <target repo name> <git archive url> <metadata archive url>"
echo "eg $0 octo-org https://HOST/org/repo https://HOST newrepo https://test.com/gitarchive.tar.gz https://test.com/metadata.tar.gz"
exit 1
fi
target_org=$1
source_repo_url=$2
repo=$3
git_archive_url=$4
metadata_archive_url=$5
if [ -n "$GH_HOST" ];then
echo -e "${info_color}GH_HOST environment detected. Using github.com instead"
unset GH_HOST
fi
if [ -n "$GH_ENTERPRISE_TOKEN" ];then
echo -e "${info_color}GH_ENTERPRISE_TOKEN environment detected. Will ignore it and use TARGET_PAT instead"
unset GH_ENTERPRISE_TOKEN
fi
user=$(gh api user -q .login)
echo using user "$user" for import
source_url=$(dirname "$source_repo_url")
echo ""
orgid=$(GITHUB_TOKEN=$TARGET_PAT gh api "orgs/$target_org" -q .node_id)
echo "orgid: $orgid"
migration_source_id=$(GITHUB_TOKEN=$TARGET_PAT gh api graphql \
-F name="GHES" \
-F "url=$source_url" \
-F "ownerId=$orgid" \
-F type="GITHUB_ARCHIVE" \
-f query='mutation createMigrationSource(
$name: String!
$url: String!
$ownerId: ID!
$type: MigrationSourceType!
) {
createMigrationSource(
input: { name: $name, url: $url, ownerId: $ownerId, type: $type }
) {
migrationSource {
id
name
url
type
}
}
}' -q .data.createMigrationSource.migrationSource.id)
echo "migration_source_id: $migration_source_id"
migration_id=$(GITHUB_TOKEN=$TARGET_PAT gh api graphql \
-F sourceId="$migration_source_id" \
-F ownerId="$orgid" \
-F sourceRepositoryUrl="$source_repo_url" \
-F repositoryName="$repo" \
-F continueOnError="true" \
-F gitArchiveUrl="$git_archive_url" \
-F metadataArchiveUrl="$metadata_archive_url" \
-F lockRepositories="false" \
-F accessToken="****" \
-F githubPat="$TARGET_PAT" \
-F skipReleases="false" \
-F lockSource="false" \
-f query='mutation startRepositoryMigration(
$sourceId: ID!
$ownerId: ID!
$sourceRepositoryUrl: URI!
$repositoryName: String!
$continueOnError: Boolean!
$gitArchiveUrl: String
$metadataArchiveUrl: String
$accessToken: String!
$githubPat: String
$skipReleases: Boolean
$lockSource: Boolean
) {
startRepositoryMigration(
input: {
sourceId: $sourceId
ownerId: $ownerId
sourceRepositoryUrl: $sourceRepositoryUrl
repositoryName: $repositoryName
continueOnError: $continueOnError
gitArchiveUrl: $gitArchiveUrl
metadataArchiveUrl: $metadataArchiveUrl
accessToken: $accessToken
githubPat: $githubPat
skipReleases: $skipReleases
lockSource: $lockSource
}
) {
repositoryMigration {
id
migrationSource {
id
name
type
}
sourceUrl
state
failureReason
}
}
}' -q .data.startRepositoryMigration.repositoryMigration.id)
if [ $? -ne 0 ] || [ -z "$migration_id" ]; then
echo "Failed to start migration."
exit 1
fi
echo "migration id: ${migration_id}"
"$script_path/_wait_for_import.sh" "${migration_id}"
logs_url=$(GITHUB_TOKEN=$TARGET_PAT gh api graphql \
-F id="$migration_id" \
-f query='query ($id: ID!) {
node(id: $id) {
... on Migration {
migrationLogUrl
}
}
}' -q .data.node.migrationLogUrl)
echo "You can see logs at: $logs_url or in the repo as an issue"