Commit e3cebf56 authored by Martin Lowe's avatar Martin Lowe 🇨🇦
Browse files

Impl for adding bots to groups if they already exist

Fixes logic with lookups as well to use project ID instead of short ID, which is how its done in the Eclipse API code.
parent eb183a7b
......@@ -150,7 +150,6 @@ export class GitlabSyncRunner {
async run(): Promise<void> {
// prepopulate caches to optimally retrieve info used in sync ops
await this.prepareCaches();
// fetch org group from results, create if missing
this.logger.info('Starting sync');
const g = this.getRootGroup();
......@@ -207,9 +206,25 @@ export class GitlabSyncRunner {
await this.addUserToGroup(user, namespaceGroup._self!, userList[uname].accessLevel);
// if not tracked, track current project for group for post-sync cleanup
if (namespaceGroup.projectTargets.indexOf(project.short_project_id) === -1) {
namespaceGroup.projectTargets.push(project.short_project_id);
if (namespaceGroup.projectTargets.indexOf(project.project_id) === -1) {
namespaceGroup.projectTargets.push(project.project_id);
}
}
// retrieve bots for current project and add them to the groups
for (const botIdx in this.bots[project.project_id]) {
const bot = this.bots[project.project_id][botIdx];
this.logger.verbose(`Found ${bot} for ${project.project_id}`);
// get the bot user if it exists already
const botUser = await this.getUser(bot, bot);
if (botUser == null) {
this.logger.info(`Could not retrieve user for bot user ${bot} for project ${project.project_id}, `
+ 'not attempting to add to group');
continue;
}
// add bot user to the group
this.logger.verbose(`Adding bot ${bot} to group ${namespaceGroup._self!.path}`);
await this.addUserToGroup(botUser, namespaceGroup._self!, maintainerPermissionsLevel);
}
}
// perform cleanup operations to clean out extra users
......@@ -238,7 +253,7 @@ export class GitlabSyncRunner {
this.generateGroupsCache(groups);
this.namedUsers = users.reduce((acc, item) => ({ ...acc, [item.username]: item }), {} as Record<string, UserSchema>);
this.eclipseProjectCache = data.reduce(
(acc, item) => ({ ...acc, [item.short_project_id]: item }),
(acc, item) => ({ ...acc, [item.project_id]: item }),
{} as Record<string, EclipseProject>,
);
} catch (e) {
......@@ -761,7 +776,7 @@ export class GitlabSyncRunner {
*/
getUserList(project: EclipseProject): Record<string, EclipseUserAccess> {
if (this.config.verbose) {
this.logger.debug(`GitlabSync:getUserList(project = ${project.short_project_id})`);
this.logger.debug(`GitlabSync:getUserList(project = ${project.project_id})`);
}
const l: Record<string, EclipseUserAccess> = {};
// add the contributors with reporter access
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment