Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
PR Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenan Warren committed Apr 29, 2021
1 parent 8d76aad commit 0832ca3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
8 changes: 4 additions & 4 deletions src/provider/SonarqubeClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe('#iterateUsers', () => {
});
});

describe('#iterateUsersGroups', () => {
describe('#iterateGroupsAssignedToUser', () => {
let recording: Recording;

afterEach(async () => {
Expand All @@ -253,7 +253,7 @@ describe('#iterateUsersGroups', () => {
test('should fetch users user groups with valid config', async () => {
recording = setupRecording({
directory: __dirname,
name: 'iterateUsersGroupsShouldFetchUserGroupsWithValidConfig',
name: 'iterateGroupsAssignedToUserShouldFetchUserGroupsWithValidConfig',
options: {
matchRequestsBy: {
url: {
Expand All @@ -274,9 +274,9 @@ describe('#iterateUsersGroups', () => {
const provider = createSonarqubeClient(context.instance.config);

const results: SonarqubeUserGroup[] = [];
await provider.iterateUsersGroups((userGroup) => {
await provider.iterateGroupsAssignedToUser('testUser', (userGroup) => {
results.push(userGroup);
}, 'testUser');
});

expect(results).toEqual(
expect.arrayContaining([
Expand Down
4 changes: 2 additions & 2 deletions src/provider/SonarqubeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ export class SonarqubeClient {
);
}

async iterateUsersGroups(
iteratee: ResourceIteratee<SonarqubeUserGroup>,
async iterateGroupsAssignedToUser(
login: string,
iteratee: ResourceIteratee<SonarqubeUserGroup>,
params?: NodeJS.Dict<string | string[]>,
): Promise<void> {
return this.iterateResources<'groups', SonarqubeUserGroup>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"log": {
"_recordingName": "iterateUsersGroupsShouldFetchUserGroupsWithValidConfig",
"_recordingName": "iterateGroupsAssignedToUserShouldFetchUserGroupsWithValidConfig",
"creator": {
"comment": "persister:JupiterOneIntegationFSPersister",
"name": "Polly.JS",
Expand Down Expand Up @@ -99,7 +99,7 @@
},
{
"name": "date",
"value": "Thu, 29 Apr 2021 17:12:45 GMT"
"value": "Thu, 29 Apr 2021 18:33:59 GMT"
},
{
"name": "connection",
Expand All @@ -112,16 +112,16 @@
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2021-04-29T17:12:44.981Z",
"time": 18,
"startedDateTime": "2021-04-29T18:33:59.607Z",
"time": 21,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 18
"wait": 21
}
},
{
Expand Down Expand Up @@ -216,7 +216,7 @@
},
{
"name": "date",
"value": "Thu, 29 Apr 2021 17:12:45 GMT"
"value": "Thu, 29 Apr 2021 18:33:59 GMT"
},
{
"name": "connection",
Expand All @@ -229,16 +229,16 @@
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2021-04-29T17:12:45.000Z",
"time": 13,
"startedDateTime": "2021-04-29T18:33:59.630Z",
"time": 9,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 13
"wait": 9
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion src/steps/user/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('#buildUserGroupUserRelationships', () => {
schema: {
properties: {
_class: { const: RelationshipClass.HAS },
_type: { const: 'sonarqube_user_group_has_user' },
_type: { const: Relationships.GROUP_HAS_USER._type },
},
},
});
Expand Down
39 changes: 22 additions & 17 deletions src/steps/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,33 @@ export async function buildUserGroupUserRelationships({
instance,
jobState,
}: IntegrationStepExecutionContext<SonarqubeIntegrationConfig>) {
const client = createSonarqubeClient(instance.config);
await jobState.iterateEntities(
{ _type: Entities.USER._type },
async (userEntity) => {
const client = createSonarqubeClient(instance.config);
await client.iterateUsersGroups(async (userGroup) => {
const userGroupEntityId = createUserGroupEntityIdentifier(userGroup.id);
const userGroupEntity = await jobState.findEntity(userGroupEntityId);

if (!userGroupEntity) {
throw new IntegrationMissingKeyError(
`Expected user group with key to exist (key=${userGroupEntityId})`,
await client.iterateGroupsAssignedToUser(
userEntity.login as string,
async (userGroup) => {
const userGroupEntityId = createUserGroupEntityIdentifier(
userGroup.id,
);
}
const userGroupEntity = await jobState.findEntity(userGroupEntityId);

await jobState.addRelationship(
createDirectRelationship({
_class: RelationshipClass.HAS,
from: userGroupEntity,
to: userEntity,
}),
);
}, userEntity.login as string);
if (!userGroupEntity) {
throw new IntegrationMissingKeyError(
`Expected user group with key to exist (key=${userGroupEntityId})`,
);
}

await jobState.addRelationship(
createDirectRelationship({
_class: RelationshipClass.HAS,
from: userGroupEntity,
to: userEntity,
}),
);
},
);
},
);
}
Expand Down

0 comments on commit 0832ca3

Please sign in to comment.