mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-11 12:12:55 +00:00
refactor: adjust report generation and tidying
This commit is contained in:
14
package-lock.json
generated
14
package-lock.json
generated
@@ -14,9 +14,9 @@
|
||||
}
|
||||
},
|
||||
"@openstapps/gitlab-api": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@openstapps/gitlab-api/-/gitlab-api-0.1.0.tgz",
|
||||
"integrity": "sha512-CLP2sjWphT80AWC7uHLgnmlOO1IjRZbaMgq31lTuU5V06SiXvDzpJpoiRJFLp82TDNc1pWIxOx2jlJPrq9/whg==",
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@openstapps/gitlab-api/-/gitlab-api-0.2.0.tgz",
|
||||
"integrity": "sha512-bvxuVB0+4E/WnKpk5hQGyFItp+hpAWhHlpDi+3+60J2QAE+28HO6WYHL+4ukdTdcZjH4214R1qYHZLLlT4iyJw==",
|
||||
"requires": {
|
||||
"@openstapps/logger": "0.0.3",
|
||||
"@types/request": "2.48.1",
|
||||
@@ -2612,6 +2612,14 @@
|
||||
"shelljs": "^0.8.2",
|
||||
"typedoc-default-themes": "^0.5.0",
|
||||
"typescript": "3.1.x"
|
||||
},
|
||||
"dependencies": {
|
||||
"typescript": {
|
||||
"version": "3.1.6",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.1.6.tgz",
|
||||
"integrity": "sha512-tDMYfVtvpb96msS1lDX9MEdHrW4yOuZ4Kdc4Him9oU796XldPYF/t2+uKoX0BBa0hXXwDlqYQbXY5Rzjzc5hBA==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"typedoc-default-themes": {
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
],
|
||||
"license": "GPL-3.0-only",
|
||||
"dependencies": {
|
||||
"@openstapps/gitlab-api": "0.1.0",
|
||||
"@openstapps/gitlab-api": "0.2.0",
|
||||
"@openstapps/logger": "0.0.3",
|
||||
"@types/del": "3.0.1",
|
||||
"@types/glob": "7.1.1",
|
||||
|
||||
@@ -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!');
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user