Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions cmd/direct-transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import readline from 'readline/promises';
import { writeFile } from 'fs/promises';
import { COPY_PROJECT_GROUP_DESC, SOURCE_REGIONS } from '../config.js';
import { getWithRetry } from './utils/requests.js';
import Papa from 'papaparse';
import fs from 'fs';

const HTTP_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes default

Expand Down Expand Up @@ -158,11 +160,26 @@ class GitLabClient {
return out;
}

async getGroupPlaceholderCsv(groupId) {
const response = await this.client.get(`/groups/${groupId}/placeholder_reassignments`);
return response.data;
}

async reassignGroupPlaceholder(groupId, form) {
const response = await this.client.postForm(`/groups/${groupId}/placeholder_reassignments`, form);
return response.data;
}

async getGroup(groupId) {
const response = await this.client.get(`/groups/${groupId}`);
return response.data;
}

async syncUser(syncData) {
const response = await this.client.post(`https://otc-github-consolidated-broker.${syncData.destRegion}.devops.cloud.ibm.com/git-user-sync`, syncData);
return response.data;
}

async createBulkImport(importData) {
const response = await this.client.post('/bulk_imports', importData);
return response.data;
Expand Down Expand Up @@ -657,6 +674,31 @@ async function directTransfer(options) {
const finishedEntities = entities.filter(e => e.status === 'finished');
const failedEntities = entities.filter(e => e.status === 'failed');

const getGroupPlaceholderCsvData = await destination.getGroupPlaceholderCsv(destinationGroupPath);
const groupPlaceholders = Papa.parse(getGroupPlaceholderCsvData, { header: true, skipEmptyLines: true }).data;
console.log(JSON.stringify(groupPlaceholders));

for (let i = 0; i < groupPlaceholders.length; i++) {
console.log(JSON.stringify(groupPlaceholders[i]));
const { username: destinationUsername } = await destination.syncUser({
sourceRegion: options.sourceRegion,
destRegion: options.destRegion,
groupId: destinationGroupPath,
userId: groupPlaceholders[i]['Source user identifier'],
});
console.log(destinationUsername);
groupPlaceholders[i]['GitLab username'] = destinationUsername;
}

const csvForm = Papa.unparse(groupPlaceholders);
fs.writeFileSync('groupPlaceholders.csv', csvForm, 'utf8');
const csvConfig = {
file : fs.createReadStream('groupPlaceholders.csv')
};

const reassignGroupPlaceholderData = await destination.reassignGroupPlaceholder(destinationGroupPath, csvConfig);
console.log(reassignGroupPlaceholderData);

if (importStatus === 'finished' && finishedEntities.length > 0) {
console.log(`\nGroup migration completed successfully!`);
console.log(`Migration Results:`);
Expand Down
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"commander": "^14.0.1",
"json-to-tf": "^0.3.1",
"ora": "^9.0.0",
"papaparse": "^5.5.3",
"strip-ansi": "^7.1.2"
},
"bin": {
Expand Down