Closed ken1714 closed 2 years ago
ソースコードの移行はCUIで行う。過去のコミット履歴等もすべて移行できるが、コミットメッセージ等の必要な修正は全て終わっているものとする。
ラベル、issueの移行にはhttps://github.com/piceaTech/node-gitlab-2-github/tree/c4951e557df2263049bac439ce746b0deb061f7dのREADMEに記載された手順に沿って作業を実行する。
大まかにまとめると、
SSH鍵はGitHubに登録済みとする。GitLabのprogramming-training
リポジトリをdehazing-sample
リポジトリに移行している。
$ git clone --mirror git@gitlab.com:ken1714/programming-training.git
$ cd programming-training.git
$ git remote add --mirror=push dehazing-sample git@github.com:ken1714/dehazing-sample.git
$ git push dehazing-sample
node-gitlab-2-githubのREADME.mdには
gitlab.token
Go to Settings / Access Tokens. Create a new Access Token with api and read_repository scopes and copy that into the settings.tsgithub.token Go to Settings / Developer settings / Personal access tokens. Generate a new token with repo scope and copy that into the settings.ts
と記載されているので、その通りに進めればよい。下記は実際に発行したアクセストークンの権限。
aptによりnpmをインストールすることは可能であるが、Node.jsのバージョンが12未満の場合、issueおよびmerge requestの移行処理の実行時にエラーが起きてしまう。
$ sudo apt install npm
$ nodejs -v
v10.19.0
Node.jsのv10.19.0を使用した際のnode-gitlab-2-github実行時ログ
$ cd node-gitlab-2-github
$ npm i
$ npm run start
> gitlab-2-github@0.1.5 start /root/node-gitlab-2-github
> node node_modules/ts-node/dist/bin.js ./src/index.ts
==================================
Transferring Milestones
==================================
==================================
Transferring Labels
==================================
Already exists: c++
Already exists: docker
Already exists: python
Already exists: ros
Already exists: setup
Already exists: has attachment
Already exists: gitlab merge request
==================================
Transferring Issues
==================================
Transferring 19 issues.
Migrating issue #1 ('Dockerインストール')...
...ERROR while migrating issue #1.
DEBUG:
TypeError: body.matchAll is not a function
at /root/node-gitlab-2-github/src/utils.ts:45:24
at step (/root/node-gitlab-2-github/src/utils.ts:52:23)
at Object.next (/root/node-gitlab-2-github/src/utils.ts:33:53)
at /root/node-gitlab-2-github/src/utils.ts:27:71
at new Promise (<anonymous>)
at __awaiter (/root/node-gitlab-2-github/src/utils.ts:23:12)
at Object.exports.migrateAttachments (/root/node-gitlab-2-github/src/utils.ts:36:132)
at GithubHelper.<anonymous> (/root/node-gitlab-2-github/src/githubHelper.ts:828:36)
at step (/root/node-gitlab-2-github/src/githubHelper.ts:52:23)
at Object.next (/root/node-gitlab-2-github/src/githubHelper.ts:33:53)
-> creating a replacement issue...
...ERROR: Could not create replacement issue either!
そのため、Node.jsが12以上となるようにインストールする必要がある。今回はnode-gitlab-2-githubの実行用にDockerコンテナを用意する。
下記サイトを参考にしつつ、Node.jsのバージョンを12.0.0とする。
使用したDockerfile
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Tokyo
# Install npm and node.js
RUN apt-get update && apt-get install -y curl
RUN apt-get install -y npm nodejs
# Install n and the node.js v12.0.0
RUN npm install -g n
RUN n 12.0.0
Dockerイメージのビルドおよびコンテナの起動
$ cd node-gitlab-2-github
$ docker image build . -t node-gitlab2github-image
$ docker run -it -v $PWD:/root/node-gitlab-2-github --name node-gitlab2github node-gitlab2github-image bash
余談ではあるが、2022/01/02現在の最新のNode.jsであるv17.3.0を使用してnode-gitlab-2-githubの実行を試みると失敗した。
$ npm i
npm WARN old lockfile
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile
up to date, audited 221 packages in 6s
24 packages are looking for funding
run `npm fund` for details
3 moderate severity vulnerabilities
To address all issues, run:
npm audit fix
Run `npm audit` for details.
$ npm run start
> gitlab-2-github@0.1.5 start
> node node_modules/ts-node/dist/bin.js ./src/index.ts
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module '/root/node-gitlab-2-github/node_modules/ts-node/dist/bin.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v17.3.0
projectIdにnullを指定すると、GitLab内の各リポジトリのprojectIdが表示されるので、移行したいprojectIdを指定して再度実行する。
import Settings from './src/settings';
export default {
gitlab: {
// url: 'https://gitlab.com',
token: '(GitLabのアクセストークン),
projectId: (表示されたprojectIdを指定。1回目の実行時はnullとする),
sessionCookie: null,
},
github: {
// baseUrl: 'api.github.com',
owner: 'ken1714',
token: '(GitHubのアクセストークン)',
repo: 'dehazing-sample',
},
// s3: {
// accessKeyId: '{{accessKeyId}}',
// secretAccessKey: '{{secretAccessKey}}',
// bucket: 'my-gitlab-bucket',
// },
usermap: {
'ken1714': 'ken1714',
'(GitLabでの表示名)': 'ken1714', // ここはおそらく不要
},
projectmap: {
'ken1714/programming-training': 'ken1714/dehazing-sample',
},
conversion: {
useLowerCaseLabels: true,
},
transfer: {
milestones: false,
labels: false,
issues: false,
mergeRequests: true,
},
debug: false,
usePlaceholderIssuesForMissingIssues: true,
useReplacementIssuesForCreationFails: true,
useIssuesForAllMergeRequests: false,
filterByLabel: null,
skipMatchingComments: [],
mergeRequests: {
logFile: './merge-requests.json',
log: false,
},
} as Settings;
Dockerコンテナ上で下記コマンドを実行。
$ cd node-gitlab-2-github
$ npm i
$ npm run start
マージリクエストについては、同名のタイトルのissueをすでに移行してしまったため、名前が重複して移行できなかった。移行元のマージリクエストにはほとんどコメントがなかったので、ひとまずこのままでOKとする。
本リポジトリをGitLabからGitHubに移行する際に行った操作をまとめていく。