feat: include sub groups in report generation

This commit is contained in:
Karl-Philipp Wulfert
2019-01-28 16:49:32 +01:00
parent f1fe412734
commit 040c666e74
2 changed files with 21 additions and 3 deletions

View File

@@ -13,7 +13,7 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Api} from '@openstapps/gitlab-api';
import {Project} from '@openstapps/gitlab-api/lib/types';
import {Group, Project} from '@openstapps/gitlab-api/lib/types';
import {Logger} from '@openstapps/logger';
import {asyncPool} from 'async-pool-native/dist/async-pool';
import {readFile, unlink, writeFile} from 'fs';
@@ -45,6 +45,18 @@ export async function getProjects(api: Api, groups: number[]): Promise<Project[]
return projects;
}
/**
* Get subgroups for a list of groups
*
* @param api GitLab API to make requests with
* @param groups List of groups
*/
export async function getSubGroups(api: Api, groups: number[]): Promise<Group[]> {
return flatten2dArray(await asyncPool(2, groups, async (groupId) => {
return await api.getSubGroupsForGroup(groupId);
}));
}
/**
* Flatten 2d array
*

View File

@@ -20,7 +20,7 @@ import * as moment from 'moment';
import {join} from 'path';
import {cwd} from 'process';
import {promisify} from 'util';
import {flatten2dArray, getProjects, logger} from '../common';
import {flatten2dArray, getProjects, getSubGroups, logger} from '../common';
import {BOLD_LABELS, GROUPS, LABEL_WEIGHTS} from '../configuration';
const asyncWriteFile = promisify(writeFile);
@@ -295,7 +295,13 @@ export async function getMergeRequestsForProjects(api: Api,
export async function report(api: Api, label: string) {
const templates = compileTemplates();
const projects = await getProjects(api, GROUPS);
const groupIds: number[] = [];
groupIds.push.apply(groupIds, GROUPS);
groupIds.push.apply(groupIds, (await getSubGroups(api, GROUPS)).map((group) => group.id));
logger.log(`Getting data for ${groupIds.length} group(s).`);
const projects = await getProjects(api, groupIds);
const issues = await getIssues(api, label);
const issuesGroupedByAssignee = groupIssuesByAssignee(issues);