refactor: adjust report generation and tidying

This commit is contained in:
Karl-Philipp Wulfert
2018-11-30 14:09:47 +01:00
parent a706928f51
commit e2b9e1a07e
5 changed files with 77 additions and 21 deletions

View File

@@ -43,9 +43,9 @@ if (existsSync(join(__dirname, 'package.json'))) {
}
commander
.command('report <milestone>')
.action(async (milestone: string) => {
await report(gitlabApi, milestone);
.command('report <label>')
.action(async (label: string) => {
await report(gitlabApi, label);
logger.ok('Done!');
});

View File

@@ -118,17 +118,18 @@ function issueToString(issue: any,
* Get issues from all groups with a specific milestone
*
* @param api GitLab API to make requests with
* @param milestone Milestone to filter by
* @param label Label to filter by
*/
export async function getIssues(api: Api, milestone: string): Promise<Issue[]> {
export async function getIssues(api: Api, label: string): Promise<Issue[]> {
const issueResults = await asyncPool(2, GROUPS, (groupId) => {
return api.getIssues({
groupId: groupId,
milestone: milestone as any,
});
});
const issues = flatten2dArray(issueResults);
const issues = flatten2dArray(issueResults).filter((issue) => {
return issue.labels.indexOf(label) >= 0;
});
logger.log('Fetched ' + issues.length + ' issue(s).');
@@ -291,11 +292,11 @@ export async function getMergeRequestsForProjects(api: Api,
return projectMergeRequests;
}
export async function report(api: Api, milestone: string) {
export async function report(api: Api, label: string) {
const templates = compileTemplates();
const projects = await getProjects(api, GROUPS);
const issues = await getIssues(api, milestone);
const issues = await getIssues(api, label);
const issuesGroupedByAssignee = groupIssuesByAssignee(issues);
@@ -315,13 +316,13 @@ export async function report(api: Api, milestone: string) {
let weightA = 0;
let weightB = 0;
Object.keys(LABEL_WEIGHTS).forEach((label: string) => {
if (a.labels.indexOf(label) >= 0) {
weightA += LABEL_WEIGHTS[label];
Object.keys(LABEL_WEIGHTS).forEach((issueLabel) => {
if (a.labels.indexOf(issueLabel) >= 0) {
weightA += LABEL_WEIGHTS[issueLabel];
}
if (b.labels.indexOf(label) >= 0) {
weightB += LABEL_WEIGHTS[label];
if (b.labels.indexOf(issueLabel) >= 0) {
weightB += LABEL_WEIGHTS[issueLabel];
}
});
@@ -348,8 +349,8 @@ export async function report(api: Api, milestone: string) {
let filename = join(cwd(), 'reports', meetingDay + '.md');
if (milestone === 'Backlog') {
filename = join(cwd(), 'reports', 'Backlog.md');
if (label !== 'meeting') {
filename = join(cwd(), 'reports', 'label.md');
}
await asyncWriteFile(filename, allMarkdown);

View File

@@ -74,6 +74,45 @@ export async function tidyIssuesWithoutMilestone(api: Api): Promise<void> {
logger.ok('Tidied issues without milestones.');
}
/**
* Tidy open issues without meeting label
*
* This adds the label 'meeting' to all open issues that do not have this label.
*
* @param api GitLab API instante to use for requests
*/
export async function tidyOpenIssuesWithoutMeetingLabel(api: Api): Promise<void> {
// fetch all open issues
const issueResults = await asyncPool(3, GROUPS, (groupId) => {
return api.getIssues({
groupId: groupId,
state: 'opened',
});
});
// flatten structure, e.g. put all issues in one array
const openIssues = flatten2dArray(issueResults);
logger.info(`Found ${openIssues.length} open issue(s).`);
// filter issues without meeting label
const openIssuesWithoutMeetingLabel = openIssues.filter((openIssue) => {
logger.log(openIssue.labels);
return openIssue.labels.indexOf('meeting') === -1;
});
logger.info(`Filtered ${openIssuesWithoutMeetingLabel.length} open issue(s) without label 'meeting'.`);
await asyncPool(5, openIssuesWithoutMeetingLabel, async (issue) => {
return api.createNote(
issue.project_id,
issue.iid,
`${NOTE_PREFIX} Automatically adding label 'meeting'\n\n/label ~meeting`);
});
logger.ok(`Tidied open issues without label 'meeting'.`);
}
/**
* Tidy labels in a list of projects
*
@@ -215,6 +254,13 @@ export async function tidySubGroupMembers(api: Api): Promise<void> {
logger.ok('Tidied "sub" group members.');
}
/**
* Tidy issues without assignee
*
* Set assignee to author if no assignee is set.
*
* @param api
*/
export async function tidyIssuesWithoutAssignee(api: Api): Promise<void> {
// fetch issues without milestone from all groups
const issueResults = await asyncPool(3, GROUPS, (groupId) => {
@@ -263,6 +309,7 @@ export async function tidy(api: Api) {
tidySubGroupMembers(api),
]);
await tidyIssuesWithoutMilestone(api);
// await tidyIssuesWithoutMilestone(api);
await tidyOpenIssuesWithoutMeetingLabel(api);
await tidyIssuesWithoutAssignee(api);
}