mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-03 20:12:51 +00:00
refactor: move to eslint
This commit is contained in:
2
.eslintignore
Normal file
2
.eslintignore
Normal file
@@ -0,0 +1,2 @@
|
||||
resources
|
||||
openapi
|
||||
3
.eslintrc.json
Normal file
3
.eslintrc.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "@openstapps"
|
||||
}
|
||||
@@ -3,6 +3,10 @@ image: registry.gitlab.com/openstapps/projectmanagement/node
|
||||
before_script:
|
||||
- npm ci
|
||||
|
||||
default:
|
||||
tags:
|
||||
- performance
|
||||
|
||||
stages:
|
||||
- build
|
||||
- test
|
||||
@@ -39,7 +43,7 @@ docker image builder:
|
||||
- docker build -t registry.gitlab.com/openstapps/projectmanagement/builder -f images/builder/Dockerfile .
|
||||
- docker push registry.gitlab.com/openstapps/projectmanagement/builder
|
||||
tags:
|
||||
- docker
|
||||
- secrecy
|
||||
|
||||
docker image node:
|
||||
image: registry.gitlab.com/openstapps/projectmanagement/builder
|
||||
@@ -56,7 +60,7 @@ docker image node:
|
||||
- docker build -t registry.gitlab.com/openstapps/projectmanagement/node -f images/node/Dockerfile images/node
|
||||
- docker push registry.gitlab.com/openstapps/projectmanagement/node
|
||||
tags:
|
||||
- docker
|
||||
- secrecy
|
||||
|
||||
npm audit:
|
||||
allow_failure: true
|
||||
@@ -119,7 +123,7 @@ pages:
|
||||
paths:
|
||||
- public
|
||||
|
||||
package:
|
||||
npm package:
|
||||
dependencies:
|
||||
- npm build
|
||||
tags:
|
||||
@@ -166,7 +170,7 @@ renovate:
|
||||
variables:
|
||||
- $RENOVATE == "true"
|
||||
tags:
|
||||
- gitlab-org-docker
|
||||
- secrecy
|
||||
artifacts:
|
||||
when: always
|
||||
expire_in: 1d
|
||||
|
||||
1600
package-lock.json
generated
1600
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
35
package.json
35
package.json
@@ -7,17 +7,17 @@
|
||||
"url": "git@gitlab.com:openstapps/projectmanagement.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run tslint && npm run compile",
|
||||
"build": "npm run lint && npm run compile",
|
||||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md && git commit -m 'docs: update changelog'",
|
||||
"check-configuration": "openstapps-configuration",
|
||||
"compile": "rimraf lib && tsc && prepend lib/cli.js '#!/usr/bin/env node\n'",
|
||||
"documentation": "typedoc --out docs --readme README.md --listInvalidSymbolLinks --entryPointStrategy expand src",
|
||||
"postversion": "npm run changelog",
|
||||
"prepublishOnly": "npm ci && npm run build",
|
||||
"prepublishOnly": "npm ci && npm run build && npm run test",
|
||||
"preversion": "npm run prepublishOnly",
|
||||
"push": "git push && git push origin \"v$npm_package_version\"",
|
||||
"test": "nyc mocha --require ts-node/register 'test/**/*.spec.ts'",
|
||||
"tslint": "tslint -p tsconfig.json -c tslint.json 'src/**/*.ts'"
|
||||
"lint": "eslint --ext .ts src/"
|
||||
},
|
||||
"author": "Karl-Philipp Wulfert <krlwlfrt@gmail.com>",
|
||||
"contributors": [
|
||||
@@ -31,32 +31,41 @@
|
||||
"dependencies": {
|
||||
"@krlwlfrt/async-pool": "0.4.1",
|
||||
"@openstapps/gitlab-api": "0.9.0",
|
||||
"@openstapps/logger": "0.8.1",
|
||||
"@openstapps/logger": "1.0.0",
|
||||
"@slack/client": "5.0.2",
|
||||
"@types/glob": "7.2.0",
|
||||
"@types/mustache": "4.1.3",
|
||||
"@types/mustache": "4.2.1",
|
||||
"@types/node": "14.18.21",
|
||||
"@types/tmp": "0.2.3",
|
||||
"commander": "9.3.0",
|
||||
"commander": "9.4.1",
|
||||
"glob": "8.0.3",
|
||||
"moment": "2.29.3",
|
||||
"moment": "2.29.4",
|
||||
"mustache": "4.2.0",
|
||||
"tmp": "0.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@openstapps/configuration": "0.29.1",
|
||||
"@testdeck/mocha": "0.2.0",
|
||||
"@types/chai": "4.3.1",
|
||||
"@openstapps/configuration": "0.33.0",
|
||||
"@openstapps/eslint-config": "1.1.0",
|
||||
"@testdeck/mocha": "0.2.1",
|
||||
"@types/chai": "4.3.3",
|
||||
"@types/chai-as-promised": "7.1.5",
|
||||
"@types/mocha": "9.1.1",
|
||||
"@types/mocha": "10.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "5.39.0",
|
||||
"@typescript-eslint/parser": "5.39.0",
|
||||
"chai": "4.3.6",
|
||||
"chai-as-promised": "7.1.1",
|
||||
"conventional-changelog-cli": "2.2.2",
|
||||
"mocha": "9.2.2",
|
||||
"eslint": "8.24.0",
|
||||
"eslint-config-prettier": "8.5.0",
|
||||
"eslint-plugin-jsdoc": "39.3.6",
|
||||
"eslint-plugin-prettier": "4.2.1",
|
||||
"eslint-plugin-unicorn": "44.0.2",
|
||||
"mocha": "10.0.0",
|
||||
"nyc": "15.1.0",
|
||||
"prepend-file-cli": "1.0.6",
|
||||
"prettier": "2.7.1",
|
||||
"rimraf": "3.0.2",
|
||||
"ts-node": "10.8.2",
|
||||
"ts-node": "10.9.1",
|
||||
"tslint": "6.1.3",
|
||||
"typedoc": "0.22.17",
|
||||
"typescript": "4.4.4"
|
||||
|
||||
@@ -53,7 +53,6 @@
|
||||
"reviewers": [
|
||||
"abcdev",
|
||||
"jovankrunic",
|
||||
"FrankNagel",
|
||||
"theaninova"
|
||||
]
|
||||
}
|
||||
|
||||
80
src/cli.ts
80
src/cli.ts
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 StApps
|
||||
* Copyright (C) 2019-2022 Open StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
@@ -18,7 +18,7 @@ import {AddLogLevel} from '@openstapps/logger/lib/transformations/add-log-level'
|
||||
import {Colorize} from '@openstapps/logger/lib/transformations/colorize';
|
||||
import {Command} from 'commander';
|
||||
import {existsSync, readFileSync} from 'fs';
|
||||
import {join, resolve} from 'path';
|
||||
import path from 'path';
|
||||
import {cwd, stdout} from 'process';
|
||||
import {GITLAB_API_URL} from './configuration';
|
||||
import {getUsedVersionMajorMinor} from './tasks/get-used-version';
|
||||
@@ -27,12 +27,10 @@ import {tidy} from './tasks/tidy';
|
||||
import {unlabel} from './tasks/unlabel';
|
||||
|
||||
// add default handler for unhandled rejections
|
||||
process.on('unhandledRejection', async (reason) => {
|
||||
if (reason instanceof Error) {
|
||||
await Logger.error('Unhandled rejection', reason.stack);
|
||||
} else {
|
||||
await Logger.error('Unhandled rejection', reason);
|
||||
}
|
||||
process.on('unhandledRejection', async reason => {
|
||||
await (reason instanceof Error
|
||||
? Logger.error('Unhandled rejection', reason.stack)
|
||||
: Logger.error('Unhandled rejection', reason));
|
||||
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -42,54 +40,46 @@ const commander = new Command('openstapps-projectmanagement');
|
||||
|
||||
// error on unknown commands
|
||||
commander.on('command:*', async () => {
|
||||
await Logger.error('Invalid command: %s\nSee --help for a list of available commands.', commander.args.join(' '));
|
||||
await Logger.error(
|
||||
'Invalid command: %s\nSee --help for a list of available commands.',
|
||||
commander.args.join(' '),
|
||||
);
|
||||
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
const gitlabApi = new Api(GITLAB_API_URL, process.env.GITLAB_PRIVATE_TOKEN as string);
|
||||
|
||||
Logger.setTransformations([
|
||||
new AddLogLevel(),
|
||||
new Colorize(),
|
||||
]);
|
||||
Logger.setTransformations([new AddLogLevel(), new Colorize()]);
|
||||
|
||||
if (existsSync(join(__dirname, 'package.json'))) {
|
||||
commander.version(JSON.parse(readFileSync(join(__dirname, '..', 'package.json'))
|
||||
.toString()).version);
|
||||
// eslint-disable-next-line unicorn/prefer-module
|
||||
if (existsSync(path.join(__dirname, 'package.json'))) {
|
||||
// eslint-disable-next-line unicorn/prefer-module
|
||||
commander.version(JSON.parse(readFileSync(path.join(__dirname, '..', 'package.json')).toString()).version);
|
||||
}
|
||||
|
||||
commander
|
||||
.command('unlabel')
|
||||
.action(async () => {
|
||||
await unlabel(gitlabApi);
|
||||
Logger.ok('Done!');
|
||||
});
|
||||
commander.command('unlabel').action(async () => {
|
||||
await unlabel(gitlabApi);
|
||||
Logger.ok('Done!');
|
||||
});
|
||||
|
||||
commander
|
||||
.command('tidy')
|
||||
.action(async () => {
|
||||
await tidy(gitlabApi);
|
||||
Logger.ok('Done!');
|
||||
});
|
||||
commander.command('tidy').action(async () => {
|
||||
await tidy(gitlabApi);
|
||||
Logger.ok('Done!');
|
||||
});
|
||||
|
||||
commander
|
||||
.command('remind')
|
||||
.action(async () => {
|
||||
await remind(gitlabApi);
|
||||
Logger.ok('Done!');
|
||||
});
|
||||
commander.command('remind').action(async () => {
|
||||
await remind(gitlabApi);
|
||||
Logger.ok('Done!');
|
||||
});
|
||||
|
||||
commander
|
||||
.command('get-used-version <dependency> [path]')
|
||||
.action(async (dependency, path) => {
|
||||
let fallbackPath = cwd();
|
||||
if (typeof path === 'string' && path.length > 0) {
|
||||
fallbackPath = resolve(path);
|
||||
}
|
||||
commander.command('get-used-version <dependency> [path]').action(async (dependency, filePath) => {
|
||||
let fallbackPath = cwd();
|
||||
if (typeof filePath === 'string' && filePath.length > 0) {
|
||||
fallbackPath = path.resolve(filePath);
|
||||
}
|
||||
|
||||
stdout.write(await getUsedVersionMajorMinor(fallbackPath, dependency));
|
||||
});
|
||||
stdout.write(await getUsedVersionMajorMinor(fallbackPath, dependency));
|
||||
});
|
||||
|
||||
commander
|
||||
.parse(process.argv);
|
||||
commander.parse(process.argv);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018, 2019 StApps
|
||||
* Copyright (C) 2018-2022 Open StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
@@ -39,7 +39,7 @@ export const writeFilePromisified = promisify(writeFile);
|
||||
export async function getProjects(api: Api, groups: number[]): Promise<Project[]> {
|
||||
Logger.info(`Fetching all projects for specified groups (${groups.length})...`);
|
||||
|
||||
const projectResults = await asyncPool(CONCURRENCY, groups, async (groupId) => {
|
||||
const projectResults = await asyncPool(CONCURRENCY, groups, async groupId => {
|
||||
return api.getProjectsForGroup(groupId);
|
||||
});
|
||||
|
||||
@@ -57,16 +57,19 @@ export async function getProjects(api: Api, groups: number[]): Promise<Project[]
|
||||
* @param groups List of groups
|
||||
*/
|
||||
export async function getSubGroups(api: Api, groups: number[]): Promise<Group[]> {
|
||||
return flatten2dArray(await asyncPool(CONCURRENCY, groups, async (groupId) => {
|
||||
return api.getSubGroupsForGroup(groupId);
|
||||
}));
|
||||
return flatten2dArray(
|
||||
await asyncPool(CONCURRENCY, groups, async groupId => {
|
||||
return api.getSubGroupsForGroup(groupId);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten 2d array
|
||||
*
|
||||
* @param arr Flattened array
|
||||
* @param array Flattened array
|
||||
*/
|
||||
export function flatten2dArray<T>(arr: T[][]): T[] {
|
||||
return ([] as T[]).concat(...arr);
|
||||
export function flatten2dArray<T>(array: T[][]): T[] {
|
||||
// eslint-disable-next-line unicorn/prefer-spread
|
||||
return ([] as T[]).concat(...array);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018, 2019 StApps
|
||||
* Copyright (C) 2018-2022 Open StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
@@ -18,38 +18,35 @@ import moment from 'moment';
|
||||
/**
|
||||
* List of schools with their IDs
|
||||
*/
|
||||
export const SCHOOLS: { [school: string]: number; } = {};
|
||||
export const SCHOOLS: {[school: string]: number} = {};
|
||||
|
||||
/**
|
||||
* ID OF openstapps main group
|
||||
*/
|
||||
const STAPPS_GROUP_ID = 4088298;
|
||||
const STAPPS_GROUP_ID = 4_088_298;
|
||||
|
||||
/**
|
||||
* List of group IDs to fetch issues for
|
||||
*/
|
||||
export const GROUPS: number[] = [STAPPS_GROUP_ID]
|
||||
.concat(Object.keys(SCHOOLS)
|
||||
.map((school) => {
|
||||
return SCHOOLS[school];
|
||||
}),
|
||||
);
|
||||
export const GROUPS: number[] = [
|
||||
STAPPS_GROUP_ID,
|
||||
...Object.keys(SCHOOLS).map(school => {
|
||||
return SCHOOLS[school];
|
||||
}),
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export const LABEL_WEIGHTS: { [key: string]: number; } = {
|
||||
'bug': 1,
|
||||
'critical': 2,
|
||||
export const LABEL_WEIGHTS: {[key: string]: number} = {
|
||||
bug: 1,
|
||||
critical: 2,
|
||||
};
|
||||
|
||||
/**
|
||||
* List of labels to print bold in report
|
||||
*/
|
||||
export const BOLD_LABELS: string[] = [
|
||||
'bug',
|
||||
'critical',
|
||||
];
|
||||
export const BOLD_LABELS: string[] = ['bug', 'critical'];
|
||||
|
||||
/**
|
||||
* GitLab API URL
|
||||
@@ -59,124 +56,122 @@ export const GITLAB_API_URL = 'https://gitlab.com/api/v4/';
|
||||
/**
|
||||
* Milestones to add to projects
|
||||
*/
|
||||
export const NEEDED_MILESTONES = [
|
||||
'Backlog',
|
||||
];
|
||||
export const NEEDED_MILESTONES = ['Backlog'];
|
||||
|
||||
/**
|
||||
* Protected branches
|
||||
*/
|
||||
export const PROTECTED_BRANCHES = [
|
||||
'develop',
|
||||
'master',
|
||||
];
|
||||
export const PROTECTED_BRANCHES = ['develop', 'master'];
|
||||
|
||||
/**
|
||||
* Labels to add to all projects
|
||||
*/
|
||||
export const NEEDED_LABELS: Label[] = [{
|
||||
color: '#FF0000',
|
||||
description: 'An error/something that is not working as expected',
|
||||
name: 'bug',
|
||||
},
|
||||
{
|
||||
color: '#5CB85C',
|
||||
name: 'consistency',
|
||||
},
|
||||
{
|
||||
color: '#FF0000',
|
||||
name: 'confirmed',
|
||||
},
|
||||
{
|
||||
color: '#FF0000',
|
||||
description: 'A blocking issue/something that needs to be fixed ASAP',
|
||||
name: 'critical',
|
||||
},
|
||||
{
|
||||
color: '#428BCA',
|
||||
name: 'design',
|
||||
},
|
||||
{
|
||||
color: '#0033CC',
|
||||
description: 'An issue about the documentation of the software',
|
||||
name: 'documentation',
|
||||
},
|
||||
{
|
||||
color: '#5CB85C',
|
||||
name: 'Doing',
|
||||
},
|
||||
{
|
||||
color: '#5CB85C',
|
||||
description: 'A feature proposal/something that will be developed',
|
||||
name: 'feature',
|
||||
},
|
||||
{
|
||||
color: '#7F8C8D',
|
||||
description: 'An issue that is unimportant or invalid',
|
||||
name: 'invalid',
|
||||
},
|
||||
{
|
||||
color: '#FFFF88',
|
||||
name: 'meeting',
|
||||
},
|
||||
{
|
||||
color: '#8E44AD',
|
||||
name: 'organization',
|
||||
},
|
||||
{
|
||||
color: '#FF0000',
|
||||
description: 'An issue with the performance of the software',
|
||||
name: 'performance',
|
||||
},
|
||||
{
|
||||
color: '#69D100',
|
||||
name: 'refactoring',
|
||||
},
|
||||
{
|
||||
color: '#FF0000',
|
||||
description: 'An issue with the security of the software',
|
||||
name: 'security',
|
||||
},
|
||||
{
|
||||
color: '#D1D100',
|
||||
description: 'An issue about the testing procedure of the software',
|
||||
name: 'testing',
|
||||
},
|
||||
{
|
||||
color: '#F0AD4E',
|
||||
name: 'To Do',
|
||||
},
|
||||
{
|
||||
color: '#A8D695',
|
||||
description: 'An issue with low priority',
|
||||
name: 'unimportant',
|
||||
},
|
||||
{
|
||||
color: '#D10069',
|
||||
description: 'An issue with the usability of the software',
|
||||
name: 'usability',
|
||||
},
|
||||
{
|
||||
color: '#428BCA',
|
||||
description: 'Feedback from the feedback-module of the app',
|
||||
name: 'user-feedback',
|
||||
}]
|
||||
.concat(Object.keys(SCHOOLS)
|
||||
.map((school) => {
|
||||
return {
|
||||
color: '#F0AD4E',
|
||||
description: 'An issue that specifically applies to this school',
|
||||
name: `school-${school}`,
|
||||
};
|
||||
}))
|
||||
.concat(['android', 'iOS', 'web', 'node']
|
||||
.map((platform) => {
|
||||
return {
|
||||
color: '#FFECDB',
|
||||
description: 'An issue that specifically applies to this platform',
|
||||
name: `platform::${platform}`,
|
||||
};
|
||||
}));
|
||||
export const NEEDED_LABELS: Label[] = [
|
||||
// eslint-disable-next-line unicorn/no-useless-spread
|
||||
...[
|
||||
{
|
||||
color: '#FF0000',
|
||||
description: 'An error/something that is not working as expected',
|
||||
name: 'bug',
|
||||
},
|
||||
{
|
||||
color: '#5CB85C',
|
||||
name: 'consistency',
|
||||
},
|
||||
{
|
||||
color: '#FF0000',
|
||||
name: 'confirmed',
|
||||
},
|
||||
{
|
||||
color: '#FF0000',
|
||||
description: 'A blocking issue/something that needs to be fixed ASAP',
|
||||
name: 'critical',
|
||||
},
|
||||
{
|
||||
color: '#428BCA',
|
||||
name: 'design',
|
||||
},
|
||||
{
|
||||
color: '#0033CC',
|
||||
description: 'An issue about the documentation of the software',
|
||||
name: 'documentation',
|
||||
},
|
||||
{
|
||||
color: '#5CB85C',
|
||||
name: 'Doing',
|
||||
},
|
||||
{
|
||||
color: '#5CB85C',
|
||||
description: 'A feature proposal/something that will be developed',
|
||||
name: 'feature',
|
||||
},
|
||||
{
|
||||
color: '#7F8C8D',
|
||||
description: 'An issue that is unimportant or invalid',
|
||||
name: 'invalid',
|
||||
},
|
||||
{
|
||||
color: '#FFFF88',
|
||||
name: 'meeting',
|
||||
},
|
||||
{
|
||||
color: '#8E44AD',
|
||||
name: 'organization',
|
||||
},
|
||||
{
|
||||
color: '#FF0000',
|
||||
description: 'An issue with the performance of the software',
|
||||
name: 'performance',
|
||||
},
|
||||
{
|
||||
color: '#69D100',
|
||||
name: 'refactoring',
|
||||
},
|
||||
{
|
||||
color: '#FF0000',
|
||||
description: 'An issue with the security of the software',
|
||||
name: 'security',
|
||||
},
|
||||
{
|
||||
color: '#D1D100',
|
||||
description: 'An issue about the testing procedure of the software',
|
||||
name: 'testing',
|
||||
},
|
||||
{
|
||||
color: '#F0AD4E',
|
||||
name: 'To Do',
|
||||
},
|
||||
{
|
||||
color: '#A8D695',
|
||||
description: 'An issue with low priority',
|
||||
name: 'unimportant',
|
||||
},
|
||||
{
|
||||
color: '#D10069',
|
||||
description: 'An issue with the usability of the software',
|
||||
name: 'usability',
|
||||
},
|
||||
{
|
||||
color: '#428BCA',
|
||||
description: 'Feedback from the feedback-module of the app',
|
||||
name: 'user-feedback',
|
||||
},
|
||||
],
|
||||
...Object.keys(SCHOOLS).map(school => {
|
||||
return {
|
||||
color: '#F0AD4E',
|
||||
description: 'An issue that specifically applies to this school',
|
||||
name: `school-${school}`,
|
||||
};
|
||||
}),
|
||||
...['android', 'iOS', 'web', 'node'].map(platform => {
|
||||
return {
|
||||
color: '#FFECDB',
|
||||
description: 'An issue that specifically applies to this platform',
|
||||
name: `platform::${platform}`,
|
||||
};
|
||||
}),
|
||||
];
|
||||
|
||||
/**
|
||||
* Prefix for automatically created notes
|
||||
@@ -215,5 +210,4 @@ if (NEXT_MEETING.isBefore(moment())) {
|
||||
/**
|
||||
* Last meeting
|
||||
*/
|
||||
export const LAST_MEETING = moment(NEXT_MEETING)
|
||||
.subtract(1, 'week');
|
||||
export const LAST_MEETING = moment(NEXT_MEETING).subtract(1, 'week');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 StApps
|
||||
* Copyright (C) 2019-2022 Open StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
@@ -13,33 +13,33 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {existsSync, PathLike} from 'fs';
|
||||
import {join} from 'path';
|
||||
import path from 'path';
|
||||
import {readFilePromisified} from '../common';
|
||||
|
||||
/**
|
||||
* Get used version of a dependency of a project referenced by a path
|
||||
*
|
||||
* @param path Path to a Node.js project directory
|
||||
* @param directoryPath Path to a Node.js project directory
|
||||
* @param dependency Dependency to get used version of
|
||||
*/
|
||||
export async function getUsedVersion(path: PathLike, dependency: string): Promise<string> {
|
||||
if (!existsSync(join(path.toString(), 'package.json'))) {
|
||||
throw new Error(`'package.json' does not exist in '${path}'. Not a Node.js project?`);
|
||||
export async function getUsedVersion(directoryPath: PathLike, dependency: string): Promise<string> {
|
||||
if (!existsSync(path.join(directoryPath.toString(), 'package.json'))) {
|
||||
throw new Error(`'package.json' does not exist in '${directoryPath}'. Not a Node.js project?`);
|
||||
}
|
||||
|
||||
const buffer = await readFilePromisified(join(path.toString(), 'package.json'));
|
||||
const buffer = await readFilePromisified(path.join(directoryPath.toString(), 'package.json'));
|
||||
const content = buffer.toString();
|
||||
const pkgJson = JSON.parse(content);
|
||||
const packageJson = JSON.parse(content);
|
||||
|
||||
if (typeof pkgJson.dependencies !== 'object') {
|
||||
throw new Error(`Project in '${path}' has no dependencies!`);
|
||||
if (typeof packageJson.dependencies !== 'object') {
|
||||
throw new TypeError(`Project in '${directoryPath}' has no dependencies!`);
|
||||
}
|
||||
|
||||
if (typeof pkgJson.dependencies[dependency] !== 'string') {
|
||||
throw new Error(`Project in '${path}' does not depend on '${dependency}'.`);
|
||||
if (typeof packageJson.dependencies[dependency] !== 'string') {
|
||||
throw new TypeError(`Project in '${directoryPath}' does not depend on '${dependency}'.`);
|
||||
}
|
||||
|
||||
return pkgJson.dependencies[dependency];
|
||||
return packageJson.dependencies[dependency];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,7 +51,8 @@ export async function getUsedVersion(path: PathLike, dependency: string): Promis
|
||||
* @param dependency see [[getUsedVersion]]
|
||||
*/
|
||||
export async function getUsedVersionMajorMinor(path: PathLike, dependency: string): Promise<string> {
|
||||
const versionMatch = (await getUsedVersion(path, dependency)).match(/([0-9]+\.[0-9]+)\.[0-9]+/);
|
||||
const usedVersions = await getUsedVersion(path, dependency);
|
||||
const versionMatch = usedVersions.match(/([0-9]+\.[0-9]+)\.[0-9]+/);
|
||||
|
||||
// istanbul ignore if
|
||||
if (versionMatch === null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 StApps
|
||||
* Copyright (C) 2019-2022 Open StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
@@ -33,17 +33,20 @@ import {CONCURRENCY, GROUPS, MAX_DEPTH_FOR_REMINDER, NOTE_PREFIX, SLACK_CHANNEL}
|
||||
*/
|
||||
export async function remind(api: Api): Promise<void> {
|
||||
// get list of open merge requests
|
||||
const allMergeRequests = await api
|
||||
.getMergeRequests(MembershipScope.GROUPS, GROUPS[0], MergeRequestState.OPENED);
|
||||
const allMergeRequests = await api.getMergeRequests(
|
||||
MembershipScope.GROUPS,
|
||||
GROUPS[0],
|
||||
MergeRequestState.OPENED,
|
||||
);
|
||||
|
||||
const mergeRequests = allMergeRequests.filter((mergeRequest) => {
|
||||
const mergeRequests = allMergeRequests.filter(mergeRequest => {
|
||||
const parts = mergeRequest.web_url.split('/');
|
||||
|
||||
// remove protocol, server name and main group
|
||||
parts.splice(0, parts.indexOf('gitlab.com') + 1 + 1);
|
||||
|
||||
// remove merge_requests and INDEX parts
|
||||
parts.splice(parts.length - 1 - 1);
|
||||
parts.splice(-1 - 1);
|
||||
|
||||
return parts.length <= MAX_DEPTH_FOR_REMINDER;
|
||||
});
|
||||
@@ -51,18 +54,19 @@ export async function remind(api: Api): Promise<void> {
|
||||
Logger.info(`Found ${mergeRequests.length} open merge requests.`);
|
||||
|
||||
// instantiate slack client
|
||||
const client = typeof process.env.SLACK_API_TOKEN !== 'undefined' ?
|
||||
new WebClient(process.env.SLACK_API_TOKEN) :
|
||||
undefined;
|
||||
const client =
|
||||
typeof process.env.SLACK_API_TOKEN !== 'undefined'
|
||||
? new WebClient(process.env.SLACK_API_TOKEN)
|
||||
: undefined;
|
||||
|
||||
// get members of main group
|
||||
const members = await api.getMembers(MembershipScope.GROUPS, GROUPS[0]);
|
||||
|
||||
// filter members with at least maintainer status
|
||||
const maintainers = members.filter((member) => member.access_level >= AccessLevel.Maintainer);
|
||||
const maintainers = members.filter(member => member.access_level >= AccessLevel.Maintainer);
|
||||
|
||||
// extract maintainer's usernames
|
||||
const maintainerUsernames = maintainers.map((maintainer) => maintainer.username);
|
||||
const maintainerUsernames = maintainers.map(maintainer => maintainer.username);
|
||||
|
||||
// sort maintainer's usernames alphabetically
|
||||
maintainerUsernames.sort((a, b) => {
|
||||
@@ -71,7 +75,7 @@ export async function remind(api: Api): Promise<void> {
|
||||
|
||||
Logger.info(`Found ${maintainers.length} maintainer(s).`);
|
||||
|
||||
await asyncPool(CONCURRENCY, mergeRequests, async (mergeRequest) => {
|
||||
await asyncPool(CONCURRENCY, mergeRequests, async mergeRequest => {
|
||||
// check if merge request is WIP
|
||||
if (mergeRequest.work_in_progress) {
|
||||
Logger.info(`Merge request '${mergeRequest.title}' is WIP.`);
|
||||
@@ -86,8 +90,8 @@ export async function remind(api: Api): Promise<void> {
|
||||
const discussions = await api.getMergeRequestDiscussions(mergeRequest.project_id, mergeRequest.iid);
|
||||
|
||||
// check if at least one of the discussions is unresolved
|
||||
const hasUnresolvedDiscussions = discussions.some((discussion) => {
|
||||
return discussion.notes.some((note) => {
|
||||
const hasUnresolvedDiscussions = discussions.some(discussion => {
|
||||
return discussion.notes.some(note => {
|
||||
return note.resolvable && (typeof note.resolved === 'undefined' || !note.resolved);
|
||||
});
|
||||
});
|
||||
@@ -116,7 +120,7 @@ export async function remind(api: Api): Promise<void> {
|
||||
|
||||
// get possible appropers, prefixed with '@' and joined with commas
|
||||
const possibleApprovers = maintainerUsernames
|
||||
.filter((username) => {
|
||||
.filter(username => {
|
||||
if (mergeRequest.assignee.username === username) {
|
||||
return false;
|
||||
}
|
||||
@@ -128,22 +132,24 @@ export async function remind(api: Api): Promise<void> {
|
||||
return true;
|
||||
}
|
||||
|
||||
return approval.approved_by.find((approver: {
|
||||
/**
|
||||
* Possible approver
|
||||
*/
|
||||
user: User;
|
||||
}) => {
|
||||
return approver.user.username !== username;
|
||||
});
|
||||
return approval.approved_by.find(
|
||||
(approver: {
|
||||
/**
|
||||
* Possible approver
|
||||
*/
|
||||
user: User;
|
||||
}) => {
|
||||
return approver.user.username !== username;
|
||||
},
|
||||
);
|
||||
})
|
||||
.map((username) => `@${username}`)
|
||||
.map(username => `@${username}`)
|
||||
.join(' ');
|
||||
|
||||
// send message to slack
|
||||
await client?.chat.postMessage({
|
||||
channel: SLACK_CHANNEL,
|
||||
text: `Merge request '${mergeRequest.title}' needs more approvals! See ${mergeRequest.web_url}!`,
|
||||
channel: SLACK_CHANNEL,
|
||||
text: `Merge request '${mergeRequest.title}' needs more approvals! See ${mergeRequest.web_url}!`,
|
||||
});
|
||||
|
||||
// assign reviewers
|
||||
@@ -153,22 +159,21 @@ export async function remind(api: Api): Promise<void> {
|
||||
mergeRequest.iid,
|
||||
`/assign_reviewer ${possibleApprovers}`,
|
||||
);
|
||||
|
||||
} else {
|
||||
Logger.log(`Merge request '${mergeRequest.title}' is ready to be merged!`);
|
||||
|
||||
// send message to slack
|
||||
await client?.chat.postMessage({
|
||||
channel: SLACK_CHANNEL,
|
||||
text: `Merge request '${mergeRequest.title}' is ready to be merged! See ${mergeRequest.web_url}!`,
|
||||
channel: SLACK_CHANNEL,
|
||||
text: `Merge request '${mergeRequest.title}' is ready to be merged! See ${mergeRequest.web_url}!`,
|
||||
});
|
||||
|
||||
// prefix maintainers with '@' and join with commas
|
||||
const possibleMergers = maintainerUsernames
|
||||
.filter((username) => {
|
||||
return mergeRequest.assignee.username !== username;
|
||||
.filter(username => {
|
||||
return mergeRequest.assignee.username !== username;
|
||||
})
|
||||
.map((username) => `@${username}`)
|
||||
.map(username => `@${username}`)
|
||||
.join(', ');
|
||||
|
||||
// create note in merge request
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018, 2019 StApps
|
||||
* Copyright (C) 2018-2022 Open StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
@@ -14,11 +14,18 @@
|
||||
*/
|
||||
import {asyncPool} from '@krlwlfrt/async-pool';
|
||||
import {Api} from '@openstapps/gitlab-api';
|
||||
import {Issue, IssueState, MembershipScope, MergeRequestState, Project, User} from '@openstapps/gitlab-api/lib/types';
|
||||
import {
|
||||
Issue,
|
||||
IssueState,
|
||||
MembershipScope,
|
||||
MergeRequestState,
|
||||
Project,
|
||||
User,
|
||||
} from '@openstapps/gitlab-api/lib/types';
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import moment from 'moment';
|
||||
import {render} from 'mustache';
|
||||
import {join, resolve} from 'path';
|
||||
import path from 'path';
|
||||
import {cwd} from 'process';
|
||||
import {flatten2dArray, getProjects, readFilePromisified, writeFilePromisified} from '../common';
|
||||
import {BOLD_LABELS, CONCURRENCY, GROUPS, LABEL_WEIGHTS, NEXT_MEETING} from '../configuration';
|
||||
@@ -139,8 +146,10 @@ export interface MergeRequestsForProjects {
|
||||
*
|
||||
* @param state State to check
|
||||
*/
|
||||
export function issueStateIsOpenedOrClosed(state: IssueState): state is IssueState.OPENED | IssueState.CLOSED {
|
||||
return ['opened', 'closed'].indexOf(state) >= 0;
|
||||
export function issueStateIsOpenedOrClosed(
|
||||
state: IssueState,
|
||||
): state is IssueState.OPENED | IssueState.CLOSED {
|
||||
return ['opened', 'closed'].includes(state);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,19 +159,24 @@ export function issueStateIsOpenedOrClosed(state: IssueState): state is IssueSta
|
||||
* @param projectId Project ID to get data about merge requests for
|
||||
* @param issueIid Issue IID in certain project (relative ID, and not issue's GitLab API ID)
|
||||
*/
|
||||
export function getMergeRequestUrls(projectMergeRequests: MergeRequestsForProjects,
|
||||
projectId: number,
|
||||
issueIid: number): string[] {
|
||||
if (typeof projectMergeRequests[projectId] === 'undefined' || projectMergeRequests[projectId].length === 0) {
|
||||
export function getMergeRequestUrls(
|
||||
projectMergeRequests: MergeRequestsForProjects,
|
||||
projectId: number,
|
||||
issueIid: number,
|
||||
): string[] {
|
||||
if (
|
||||
typeof projectMergeRequests[projectId] === 'undefined' ||
|
||||
projectMergeRequests[projectId].length === 0
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return projectMergeRequests[projectId]
|
||||
.filter((obj) => {
|
||||
return obj.issue_iid === issueIid;
|
||||
.filter(object => {
|
||||
return object.issue_iid === issueIid;
|
||||
})
|
||||
.map((obj) => {
|
||||
return obj.web_url;
|
||||
.map(object => {
|
||||
return object.web_url;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -174,16 +188,15 @@ export function getMergeRequestUrls(projectMergeRequests: MergeRequestsForProjec
|
||||
* @param groups List of groups to get issues for
|
||||
*/
|
||||
export async function getIssues(api: Api, label: string, groups: number[]): Promise<Issue[]> {
|
||||
const issueResults = await asyncPool(CONCURRENCY, groups, async (groupId) => {
|
||||
const issueResults = await asyncPool(CONCURRENCY, groups, async groupId => {
|
||||
return api.getIssues({
|
||||
groupId: groupId,
|
||||
});
|
||||
});
|
||||
|
||||
const issues = flatten2dArray(issueResults)
|
||||
.filter((issue) => {
|
||||
return issue.labels.indexOf(label) >= 0;
|
||||
});
|
||||
const issues = flatten2dArray(issueResults).filter(issue => {
|
||||
return issue.labels.includes(label);
|
||||
});
|
||||
|
||||
Logger.log(`Fetched ${issues.length} issue(s).`);
|
||||
|
||||
@@ -196,24 +209,22 @@ export async function getIssues(api: Api, label: string, groups: number[]): Prom
|
||||
* @param api GitLab API To make requests with
|
||||
* @param projects List of projects
|
||||
*/
|
||||
export async function getIssueBranches(
|
||||
api: Api,
|
||||
projects: Project[]): Promise<{ [k: string]: number[]; }> {
|
||||
const projectBranches: { [k: string]: number[]; } = {};
|
||||
export async function getIssueBranches(api: Api, projects: Project[]): Promise<{[k: string]: number[]}> {
|
||||
const projectBranches: {[k: string]: number[]} = {};
|
||||
|
||||
await asyncPool(CONCURRENCY, projects, async (project) => {
|
||||
await asyncPool(CONCURRENCY, projects, async project => {
|
||||
const branches = await api.getBranchesForProject(project.id);
|
||||
|
||||
// extract issue number from branch
|
||||
projectBranches[project.id] = branches
|
||||
.map((branch) => {
|
||||
.map(branch => {
|
||||
return branch.name.split('-')[0];
|
||||
})
|
||||
.filter((branchNameStart) => {
|
||||
.filter(branchNameStart => {
|
||||
return branchNameStart.match(/^[0-9]+$/);
|
||||
})
|
||||
.map((branchNameStart) => {
|
||||
return parseInt(branchNameStart, 10);
|
||||
.map(branchNameStart => {
|
||||
return Number.parseInt(branchNameStart, 10);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -229,26 +240,26 @@ export async function getIssueBranches(
|
||||
export async function getIssuesGroupedByAssignees(api: Api, label: string): Promise<AssigneeWithIssues[]> {
|
||||
const issuesByAssignee: IssuesGroupedByAssigneeId = {};
|
||||
|
||||
const groups = flatten2dArray(await asyncPool(CONCURRENCY, GROUPS, async (groupId) => {
|
||||
return (await api.getSubGroupsForGroup(groupId)).map((group) => {
|
||||
return group.id;
|
||||
});
|
||||
}));
|
||||
groups.push.apply(groups, GROUPS);
|
||||
const groups = flatten2dArray(
|
||||
await asyncPool(CONCURRENCY, GROUPS, async groupId => {
|
||||
const subGroups = await api.getSubGroupsForGroup(groupId);
|
||||
return subGroups.map(group => {
|
||||
return group.id;
|
||||
});
|
||||
}),
|
||||
);
|
||||
groups.push(...groups, ...GROUPS);
|
||||
|
||||
const [issues, projects] = await Promise.all([
|
||||
getIssues(api, label, groups),
|
||||
getProjects(api, groups),
|
||||
]);
|
||||
const [issues, projects] = await Promise.all([getIssues(api, label, groups), getProjects(api, groups)]);
|
||||
|
||||
const issueBranches = await getIssueBranches(api, projects);
|
||||
const mergeRequests = await getMergeRequests(api, projects);
|
||||
|
||||
issues.forEach((issue) => {
|
||||
for (const issue of issues) {
|
||||
if (issue.assignee === null) {
|
||||
Logger.warn('Issue without assignee!', issue.web_url);
|
||||
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof issuesByAssignee[issue.assignee.id] === 'undefined') {
|
||||
@@ -267,33 +278,33 @@ export async function getIssuesGroupedByAssignees(api: Api, label: string): Prom
|
||||
issue.state = IssueState.OPENED;
|
||||
}
|
||||
|
||||
const issueMeta = {
|
||||
$branchExists:
|
||||
typeof issueBranches[issue.project_id] !== 'undefined' &&
|
||||
issueBranches[issue.project_id].includes(issue.iid),
|
||||
$closed: issue.state === IssueState.CLOSED,
|
||||
$issue: issue,
|
||||
$labels: issue.labels.map((issueLabel: string) => {
|
||||
return {
|
||||
bold: BOLD_LABELS.includes(issueLabel),
|
||||
label: issueLabel,
|
||||
};
|
||||
}),
|
||||
$mergeRequestUrl: getMergeRequestUrls(mergeRequests, issue.project_id, issue.iid)[0],
|
||||
$project: issue.web_url.replace('https://gitlab.com/', '').split('/-/issues/')[0],
|
||||
$weeksOpen: moment().diff(moment(issue.created_at), 'weeks'),
|
||||
};
|
||||
|
||||
const issueWithMeta: IssueWithMeta = {
|
||||
...issue,
|
||||
...{
|
||||
$branchExists: typeof issueBranches[issue.project_id] !== 'undefined'
|
||||
&& issueBranches[issue.project_id].indexOf(issue.iid) >= 0,
|
||||
$closed: issue.state === IssueState.CLOSED,
|
||||
$issue: issue,
|
||||
$labels: issue.labels.map((issueLabel: string) => {
|
||||
return {
|
||||
bold: BOLD_LABELS.includes(issueLabel),
|
||||
label: issueLabel,
|
||||
};
|
||||
}),
|
||||
$mergeRequestUrl: getMergeRequestUrls(mergeRequests, issue.project_id, issue.iid)[0],
|
||||
$project: issue.web_url
|
||||
.replace('https://gitlab.com/', '')
|
||||
.split('/-/issues/')[0],
|
||||
$weeksOpen: moment()
|
||||
.diff(moment(issue.created_at), 'weeks'),
|
||||
},
|
||||
...issueMeta,
|
||||
};
|
||||
|
||||
if (issueStateIsOpenedOrClosed(issue.state)) {
|
||||
issuesByAssignee[issue.assignee.id].issueCounts[issue.state]++;
|
||||
issuesByAssignee[issue.assignee.id].issues.push(issueWithMeta);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// calculate quota
|
||||
for (const _assigneeId in issuesByAssignee) {
|
||||
@@ -301,13 +312,14 @@ export async function getIssuesGroupedByAssignees(api: Api, label: string): Prom
|
||||
continue;
|
||||
}
|
||||
|
||||
const assigneeId = parseInt(_assigneeId, 10);
|
||||
const assigneeId = Number.parseInt(_assigneeId, 10);
|
||||
|
||||
issuesByAssignee[assigneeId].quota = Math.floor(
|
||||
issuesByAssignee[assigneeId].issueCounts.closed
|
||||
/ (issuesByAssignee[assigneeId].issueCounts.opened
|
||||
// tslint:disable-next-line:no-magic-numbers
|
||||
+ issuesByAssignee[assigneeId].issueCounts.closed) * 100,
|
||||
(issuesByAssignee[assigneeId].issueCounts.closed /
|
||||
(issuesByAssignee[assigneeId].issueCounts.opened +
|
||||
// tslint:disable-next-line:no-magic-numbers
|
||||
issuesByAssignee[assigneeId].issueCounts.closed)) *
|
||||
100,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -317,7 +329,7 @@ export async function getIssuesGroupedByAssignees(api: Api, label: string): Prom
|
||||
continue;
|
||||
}
|
||||
|
||||
const assigneeId = parseInt(_assigneeId, 10);
|
||||
const assigneeId = Number.parseInt(_assigneeId, 10);
|
||||
|
||||
issuesByAssignee[assigneeId].issues.sort((a, b) => {
|
||||
let weightA = 0;
|
||||
@@ -328,11 +340,11 @@ export async function getIssuesGroupedByAssignees(api: Api, label: string): Prom
|
||||
continue;
|
||||
}
|
||||
|
||||
if (a.labels.indexOf(issueLabel) >= 0) {
|
||||
if (a.labels.includes(issueLabel)) {
|
||||
weightA += LABEL_WEIGHTS[issueLabel];
|
||||
}
|
||||
|
||||
if (b.labels.indexOf(issueLabel) >= 0) {
|
||||
if (b.labels.includes(issueLabel)) {
|
||||
weightB += LABEL_WEIGHTS[issueLabel];
|
||||
}
|
||||
}
|
||||
@@ -372,32 +384,35 @@ export function getNextMeetingDay() {
|
||||
* @param api GitLab API to make requests with
|
||||
* @param projects List of projects
|
||||
*/
|
||||
export async function getMergeRequests(api: Api,
|
||||
projects: Project[]): Promise<MergeRequestsForProjects> {
|
||||
export async function getMergeRequests(api: Api, projects: Project[]): Promise<MergeRequestsForProjects> {
|
||||
const projectMergeRequests: MergeRequestsForProjects = {};
|
||||
|
||||
// iterate over projects
|
||||
await asyncPool(CONCURRENCY, projects, async (project) => {
|
||||
await asyncPool(CONCURRENCY, projects, async project => {
|
||||
// check if project can have merge requests
|
||||
if (!project.merge_requests_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get all merge requests for project
|
||||
const mergeRequests = await api.getMergeRequests(MembershipScope.PROJECTS, project.id, MergeRequestState.OPENED);
|
||||
const mergeRequests = await api.getMergeRequests(
|
||||
MembershipScope.PROJECTS,
|
||||
project.id,
|
||||
MergeRequestState.OPENED,
|
||||
);
|
||||
|
||||
// extract issue number from merge request
|
||||
projectMergeRequests[project.id] = mergeRequests
|
||||
.map((mergeRequest) => {
|
||||
.map(mergeRequest => {
|
||||
// keep information about web url too
|
||||
return {issue_iid: mergeRequest.source_branch.split('-')[0], web_url: mergeRequest.web_url};
|
||||
})
|
||||
.filter((branchNameStartAndUrl) => {
|
||||
.filter(branchNameStartAndUrl => {
|
||||
return branchNameStartAndUrl.issue_iid.match(/^[0-9]+$/);
|
||||
})
|
||||
.map((branchNameStartAndUrl) => {
|
||||
.map(branchNameStartAndUrl => {
|
||||
return {
|
||||
issue_iid: parseInt(branchNameStartAndUrl.issue_iid, 10),
|
||||
issue_iid: Number.parseInt(branchNameStartAndUrl.issue_iid, 10),
|
||||
web_url: branchNameStartAndUrl.web_url,
|
||||
};
|
||||
});
|
||||
@@ -419,14 +434,10 @@ export async function generateReport(api: Api, label: string, template: string):
|
||||
const structureForTemplate: StructureForTemplate = {
|
||||
issuesByAssignee: issuesGroupedByAssignee,
|
||||
meetingDay: getNextMeetingDay(),
|
||||
timestamp: moment()
|
||||
.format('LLL'),
|
||||
timestamp: moment().format('LLL'),
|
||||
};
|
||||
|
||||
return render(
|
||||
template,
|
||||
structureForTemplate,
|
||||
);
|
||||
return render(template, structureForTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -438,16 +449,17 @@ export async function generateReport(api: Api, label: string, template: string):
|
||||
export async function report(api: Api, label: string) {
|
||||
const meetingDay = getNextMeetingDay();
|
||||
|
||||
const markdown = await generateReport(
|
||||
api,
|
||||
label,
|
||||
(await readFilePromisified(resolve(__dirname, '..', '..', 'templates', 'report.md.mustache'))).toString(),
|
||||
const readReportFile = await readFilePromisified(
|
||||
// eslint-disable-next-line unicorn/prefer-module
|
||||
path.resolve(__dirname, '..', '..', 'templates', 'report.md.mustache'),
|
||||
);
|
||||
|
||||
let filename = join(cwd(), 'reports', `${meetingDay}.md`);
|
||||
const markdown = await generateReport(api, label, readReportFile.toString());
|
||||
|
||||
let filename = path.join(cwd(), 'reports', `${meetingDay}.md`);
|
||||
|
||||
if (label !== 'meeting') {
|
||||
filename = join(cwd(), 'reports', `${label}.md`);
|
||||
filename = path.join(cwd(), 'reports', `${label}.md`);
|
||||
}
|
||||
|
||||
await writeFilePromisified(filename, markdown);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018, 2019 StApps
|
||||
* Copyright (C) 2018-2022 Open StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
@@ -14,7 +14,15 @@
|
||||
*/
|
||||
import {asyncPool} from '@krlwlfrt/async-pool';
|
||||
import {Api} from '@openstapps/gitlab-api';
|
||||
import {AccessLevel, IssueState, MembershipScope, MergeRequestState, Milestone, Project, Scope} from '@openstapps/gitlab-api/lib/types';
|
||||
import {
|
||||
AccessLevel,
|
||||
IssueState,
|
||||
MembershipScope,
|
||||
MergeRequestState,
|
||||
Milestone,
|
||||
Project,
|
||||
Scope,
|
||||
} from '@openstapps/gitlab-api/lib/types';
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {flatten2dArray, getProjects} from '../common';
|
||||
import {
|
||||
@@ -36,7 +44,7 @@ import {
|
||||
*/
|
||||
export async function tidyIssuesWithoutMilestone(api: Api): Promise<void> {
|
||||
// fetch issues without milestone from all groups
|
||||
const issueResults = await asyncPool(CONCURRENCY, GROUPS, async (groupId) => {
|
||||
const issueResults = await asyncPool(CONCURRENCY, GROUPS, async groupId => {
|
||||
return api.getIssues({
|
||||
groupId: groupId,
|
||||
milestone: 'No Milestone',
|
||||
@@ -49,22 +57,22 @@ export async function tidyIssuesWithoutMilestone(api: Api): Promise<void> {
|
||||
|
||||
Logger.info(`Found '${issuesWithoutMilestone.length}' issue(s) without milestone.`);
|
||||
|
||||
const milestoneCache: { [s: number]: Milestone[]; } = {};
|
||||
const milestoneCache: {[s: number]: Milestone[]} = {};
|
||||
|
||||
await asyncPool(CONCURRENCY, issuesWithoutMilestone, async (issue) => {
|
||||
await asyncPool(CONCURRENCY, issuesWithoutMilestone, async issue => {
|
||||
if (typeof milestoneCache[issue.project_id] === 'undefined') {
|
||||
milestoneCache[issue.project_id] = await api.getMilestonesForProject(issue.project_id);
|
||||
}
|
||||
|
||||
let milestoneId = null;
|
||||
let milestoneId;
|
||||
|
||||
milestoneCache[issue.project_id].forEach((milestone) => {
|
||||
for (const milestone of milestoneCache[issue.project_id]) {
|
||||
if (milestone.title === 'Meeting') {
|
||||
milestoneId = milestone.id;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (milestoneId === null) {
|
||||
if (typeof milestoneId === 'undefined') {
|
||||
Logger.warn(`Milestone 'Meeting' was not available for issue ${issue.title} (${issue.web_url}).`);
|
||||
|
||||
return;
|
||||
@@ -94,7 +102,7 @@ export async function tidyIssuesWithoutMilestone(api: Api): Promise<void> {
|
||||
*/
|
||||
export async function tidyOpenIssuesWithoutMeetingLabel(api: Api): Promise<void> {
|
||||
// fetch all open issues
|
||||
const issueResults = await asyncPool(CONCURRENCY, GROUPS, async (groupId) => {
|
||||
const issueResults = await asyncPool(CONCURRENCY, GROUPS, async groupId => {
|
||||
return api.getIssues({
|
||||
groupId: groupId,
|
||||
state: IssueState.OPENED,
|
||||
@@ -107,13 +115,13 @@ export async function tidyOpenIssuesWithoutMeetingLabel(api: Api): Promise<void>
|
||||
Logger.info(`Found ${openIssues.length} open issue(s).`);
|
||||
|
||||
// filter issues without meeting label
|
||||
const openIssuesWithoutMeetingLabel = openIssues.filter((openIssue) => {
|
||||
return openIssue.labels.indexOf('meeting') === -1;
|
||||
const openIssuesWithoutMeetingLabel = openIssues.filter(openIssue => {
|
||||
return !openIssue.labels.includes('meeting');
|
||||
});
|
||||
|
||||
Logger.info(`Filtered ${openIssuesWithoutMeetingLabel.length} open issue(s) without label 'meeting'.`);
|
||||
|
||||
await asyncPool(CONCURRENCY, openIssuesWithoutMeetingLabel, async (issue) => {
|
||||
await asyncPool(CONCURRENCY, openIssuesWithoutMeetingLabel, async issue => {
|
||||
if (issue.milestone !== null && issue.milestone.title === 'Backlog') {
|
||||
Logger.info(`Skipping issue "${issue.title}" because it is in backlog.`);
|
||||
|
||||
@@ -124,7 +132,8 @@ export async function tidyOpenIssuesWithoutMeetingLabel(api: Api): Promise<void>
|
||||
issue.project_id,
|
||||
Scope.ISSUES,
|
||||
issue.iid,
|
||||
`${NOTE_PREFIX} Automatically adding label 'meeting'\n\n/label ~meeting`);
|
||||
`${NOTE_PREFIX} Automatically adding label 'meeting'\n\n/label ~meeting`,
|
||||
);
|
||||
});
|
||||
|
||||
Logger.ok(`Tidied open issues without label 'meeting'.`);
|
||||
@@ -137,28 +146,28 @@ export async function tidyOpenIssuesWithoutMeetingLabel(api: Api): Promise<void>
|
||||
* @param projects List of projects to tidy labels on
|
||||
*/
|
||||
export async function tidyLabels(api: Api, projects: Project[]): Promise<void> {
|
||||
await asyncPool(CONCURRENCY, projects, async (project) => {
|
||||
await asyncPool(CONCURRENCY, projects, async project => {
|
||||
const labels = await api.getLabels(project.id);
|
||||
|
||||
const neededLabels = NEEDED_LABELS.slice(0);
|
||||
const neededLabels = [...NEEDED_LABELS];
|
||||
// const extraneousLabels: Label[] = [];
|
||||
|
||||
labels.forEach((label) => {
|
||||
for (const label of labels) {
|
||||
// let needed = false;
|
||||
|
||||
neededLabels.forEach((neededLabel, neededLabelIdx) => {
|
||||
for (const [neededLabelIndex, neededLabel] of neededLabels.entries()) {
|
||||
if (neededLabel.name.toLowerCase() === label.name.toLowerCase()) {
|
||||
neededLabels.splice(neededLabelIdx, 1);
|
||||
neededLabels.splice(neededLabelIndex, 1);
|
||||
// needed = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* if (!needed) {
|
||||
extraneousLabels.push(label);
|
||||
} */
|
||||
});
|
||||
}
|
||||
|
||||
await asyncPool(CONCURRENCY, neededLabels, async (neededLabel) => {
|
||||
await asyncPool(CONCURRENCY, neededLabels, async neededLabel => {
|
||||
await api.createLabel(project.id, neededLabel.name, neededLabel.description, neededLabel.color);
|
||||
|
||||
Logger.log(`Created label '${neededLabel.name}' in '${project.name_with_namespace}'.`);
|
||||
@@ -181,20 +190,20 @@ export async function tidyLabels(api: Api, projects: Project[]): Promise<void> {
|
||||
* @param projects List of projects to tidy milestones on
|
||||
*/
|
||||
export async function tidyMilestones(api: Api, projects: Project[]): Promise<void> {
|
||||
await asyncPool(CONCURRENCY, projects, async (project) => {
|
||||
await asyncPool(CONCURRENCY, projects, async project => {
|
||||
const milestones = await api.getMilestonesForProject(project.id);
|
||||
const missingMilestones = NEEDED_MILESTONES.slice(0);
|
||||
const missingMilestones = [...NEEDED_MILESTONES];
|
||||
|
||||
milestones.forEach((milestone) => {
|
||||
const idx = missingMilestones.indexOf(milestone.title);
|
||||
for (const milestone of milestones) {
|
||||
const index = missingMilestones.indexOf(milestone.title);
|
||||
|
||||
if (idx >= 0) {
|
||||
missingMilestones.splice(idx, 1);
|
||||
if (index >= 0) {
|
||||
missingMilestones.splice(index, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (missingMilestones.length > 0 && !project.archived) {
|
||||
await asyncPool(CONCURRENCY, missingMilestones, async (milestone) => {
|
||||
await asyncPool(CONCURRENCY, missingMilestones, async milestone => {
|
||||
await api.createMilestone(project.id, milestone);
|
||||
Logger.log(`Created milestone '${milestone}' for project ${project.name_with_namespace}'.`);
|
||||
});
|
||||
@@ -211,18 +220,18 @@ export async function tidyMilestones(api: Api, projects: Project[]): Promise<voi
|
||||
* @param projects List of projects to tidy milestones on
|
||||
*/
|
||||
export async function tidyProtectedBranches(api: Api, projects: Project[]): Promise<void> {
|
||||
await asyncPool(CONCURRENCY, projects, async (project) => {
|
||||
await asyncPool(CONCURRENCY, projects, async project => {
|
||||
const branches = await api.getBranchesForProject(project.id);
|
||||
|
||||
const protectableBranches = branches.filter((branch) => {
|
||||
return PROTECTED_BRANCHES.indexOf(branch.name) >= 0;
|
||||
const protectableBranches = branches.filter(branch => {
|
||||
return PROTECTED_BRANCHES.includes(branch.name);
|
||||
});
|
||||
|
||||
const unprotectedBranches = protectableBranches.filter((branch) => {
|
||||
const unprotectedBranches = protectableBranches.filter(branch => {
|
||||
return !branch.protected;
|
||||
});
|
||||
|
||||
await asyncPool(CONCURRENCY, unprotectedBranches, async (branch) => {
|
||||
await asyncPool(CONCURRENCY, unprotectedBranches, async branch => {
|
||||
await api.protectBranch(project.id, branch.name);
|
||||
|
||||
Logger.log(`Added protected branch '${branch.name}' in project '${project.name_with_namespace}'...`);
|
||||
@@ -239,9 +248,9 @@ export async function tidyProtectedBranches(api: Api, projects: Project[]): Prom
|
||||
* @param projects List of projects to tidy protected tags on
|
||||
*/
|
||||
export async function tidyProtectedTags(api: Api, projects: Project[]): Promise<void> {
|
||||
await asyncPool(CONCURRENCY, projects, async (project) => {
|
||||
await asyncPool(CONCURRENCY, projects, async project => {
|
||||
// TODO: move this to GitLab API
|
||||
const protectedTags = await api.makeGitLabAPIRequest(`projects/${project.id}/protected_tags`) as Array<{
|
||||
const protectedTags = (await api.makeGitLabAPIRequest(`projects/${project.id}/protected_tags`)) as Array<{
|
||||
/**
|
||||
* List of access levels to create a tag
|
||||
*/
|
||||
@@ -261,9 +270,11 @@ export async function tidyProtectedTags(api: Api, projects: Project[]): Promise<
|
||||
name: string;
|
||||
}>;
|
||||
|
||||
if (protectedTags.findIndex((protectedTag) => {
|
||||
return protectedTag.name === 'v*';
|
||||
}) === -1) {
|
||||
if (
|
||||
protectedTags.findIndex(protectedTag => {
|
||||
return protectedTag.name === 'v*';
|
||||
}) === -1
|
||||
) {
|
||||
await api.makeGitLabAPIRequest(`projects/${project.id}/protected_tags`, {
|
||||
data: {
|
||||
create_access_level: AccessLevel.Maintainer,
|
||||
@@ -286,29 +297,28 @@ export async function tidyProtectedTags(api: Api, projects: Project[]): Promise<
|
||||
*/
|
||||
export async function tidySubGroupMembers(api: Api): Promise<void> {
|
||||
const stappsMembers = await api.getMembers(MembershipScope.GROUPS, GROUPS[0]);
|
||||
const stappsMemberIds = stappsMembers.map((member) => member.id);
|
||||
const stappsMemberIds = new Set(stappsMembers.map(member => member.id));
|
||||
|
||||
const groupIdsToSchool: { [id: number]: string; } = {};
|
||||
const groupIdsToSchool: {[id: number]: string} = {};
|
||||
|
||||
Object.keys(SCHOOLS)
|
||||
.map((school) => {
|
||||
groupIdsToSchool[SCHOOLS[school]] = school;
|
||||
});
|
||||
Object.keys(SCHOOLS).map(school => {
|
||||
groupIdsToSchool[SCHOOLS[school]] = school;
|
||||
});
|
||||
|
||||
await asyncPool(CONCURRENCY, GROUPS.slice(1), async (groupId) => {
|
||||
await asyncPool(CONCURRENCY, GROUPS.slice(1), async groupId => {
|
||||
const members = await api.getMembers(MembershipScope.GROUPS, groupId);
|
||||
const memberIds = members.map((member) => member.id);
|
||||
const memberIds = new Set(members.map(member => member.id));
|
||||
|
||||
await asyncPool(CONCURRENCY, stappsMembers, async (stappsMember) => {
|
||||
if (memberIds.indexOf(stappsMember.id) === -1) {
|
||||
await asyncPool(CONCURRENCY, stappsMembers, async stappsMember => {
|
||||
if (!memberIds.has(stappsMember.id)) {
|
||||
await api.addMember(MembershipScope.GROUPS, groupId, stappsMember.id, AccessLevel.Developer);
|
||||
|
||||
Logger.log(`Added '${stappsMember.name}' to group '${groupIdsToSchool[groupId]}'.`);
|
||||
}
|
||||
});
|
||||
|
||||
await asyncPool(CONCURRENCY, members, async (member) => {
|
||||
if (stappsMemberIds.indexOf(member.id) === -1) {
|
||||
await asyncPool(CONCURRENCY, members, async member => {
|
||||
if (!stappsMemberIds.has(member.id)) {
|
||||
await api.deleteMember(MembershipScope.GROUPS, groupId, member.id);
|
||||
|
||||
Logger.log(`Deleted member '${member.name}' from group '${groupIdsToSchool[groupId]}'.`);
|
||||
@@ -328,7 +338,7 @@ export async function tidySubGroupMembers(api: Api): Promise<void> {
|
||||
*/
|
||||
export async function tidyIssuesWithoutAssignee(api: Api): Promise<void> {
|
||||
// fetch issues without milestone from all groups
|
||||
const issueResults = await asyncPool(CONCURRENCY, GROUPS, async (groupId) => {
|
||||
const issueResults = await asyncPool(CONCURRENCY, GROUPS, async groupId => {
|
||||
return api.getIssues({
|
||||
groupId: groupId,
|
||||
state: IssueState.OPENED,
|
||||
@@ -338,13 +348,13 @@ export async function tidyIssuesWithoutAssignee(api: Api): Promise<void> {
|
||||
// flatten structure, e.g. put all issues in one array
|
||||
const issues = flatten2dArray(issueResults);
|
||||
|
||||
const issuesWithoutAssignee = issues.filter((issue) => {
|
||||
const issuesWithoutAssignee = issues.filter(issue => {
|
||||
return issue.assignee === null;
|
||||
});
|
||||
|
||||
Logger.info(`Found '${issuesWithoutAssignee.length}' issue(s) without assignee.`);
|
||||
|
||||
await asyncPool(CONCURRENCY, issuesWithoutAssignee, async (issue) => {
|
||||
await asyncPool(CONCURRENCY, issuesWithoutAssignee, async issue => {
|
||||
await api.setAssigneeForIssue(issue, issue.author.id);
|
||||
|
||||
Logger.log(`Set assignee for '${issue.title}' to '${issue.author.name}'.`);
|
||||
@@ -368,24 +378,20 @@ export async function tidyIssuesWithoutAssignee(api: Api): Promise<void> {
|
||||
* @param api GitLab API instance to use for the requests
|
||||
*/
|
||||
export async function tidyMergeRequestsWithoutAssignee(api: Api): Promise<void> {
|
||||
const mergeRequestResults = await asyncPool(CONCURRENCY, GROUPS, async (groupId) => {
|
||||
return api.getMergeRequests(
|
||||
MembershipScope.GROUPS,
|
||||
groupId,
|
||||
MergeRequestState.OPENED,
|
||||
);
|
||||
const mergeRequestResults = await asyncPool(CONCURRENCY, GROUPS, async groupId => {
|
||||
return api.getMergeRequests(MembershipScope.GROUPS, groupId, MergeRequestState.OPENED);
|
||||
});
|
||||
|
||||
// flatten structure, e.g. put all issues in one array
|
||||
const mergeRequests = flatten2dArray(mergeRequestResults);
|
||||
|
||||
const mergeRequestsWithoutAssignee = mergeRequests.filter((mergeRequest) => {
|
||||
const mergeRequestsWithoutAssignee = mergeRequests.filter(mergeRequest => {
|
||||
return mergeRequest.assignee === null;
|
||||
});
|
||||
|
||||
Logger.info(`Found '${mergeRequestsWithoutAssignee.length}' merge requests without assignee.`);
|
||||
|
||||
await asyncPool(CONCURRENCY, mergeRequestsWithoutAssignee, async (mergeRequest) => {
|
||||
await asyncPool(CONCURRENCY, mergeRequestsWithoutAssignee, async mergeRequest => {
|
||||
await api.setAssigneeForMergeRequest(mergeRequest, mergeRequest.author.id);
|
||||
|
||||
Logger.log(`Set assignee for '${mergeRequest.title}' to '${mergeRequest.author.name}'.`);
|
||||
@@ -408,8 +414,9 @@ export async function tidyMergeRequestsWithoutAssignee(api: Api): Promise<void>
|
||||
*/
|
||||
export async function tidy(api: Api) {
|
||||
// get first level sub groups
|
||||
const groups = GROUPS.slice();
|
||||
groups.push.apply(groups, (await api.getSubGroupsForGroup(groups[0])).map((group) => group.id));
|
||||
const groups = [...GROUPS];
|
||||
const subGroups = await api.getSubGroupsForGroup(groups[0]);
|
||||
groups.push(...groups, ...subGroups.map(group => group.id));
|
||||
|
||||
// get non archived projects of groups
|
||||
let projects = await getProjects(api, groups);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018, 2019 StApps
|
||||
* Copyright (C) 2018-2022 Open StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
@@ -26,7 +26,7 @@ import {CONCURRENCY, GROUPS, LAST_MEETING, NOTE_PREFIX} from '../configuration';
|
||||
* @param api Instance of GitLabAPI to send requests with
|
||||
*/
|
||||
export async function unlabel(api: Api) {
|
||||
const issueResults = await asyncPool(CONCURRENCY, GROUPS, async (groupId) => {
|
||||
const issueResults = await asyncPool(CONCURRENCY, GROUPS, async groupId => {
|
||||
return api.getIssues({
|
||||
groupId: groupId,
|
||||
state: IssueState.CLOSED,
|
||||
@@ -37,21 +37,21 @@ export async function unlabel(api: Api) {
|
||||
|
||||
Logger.log(`Fetched ${issues.length} closed issue(s).`);
|
||||
|
||||
await asyncPool(CONCURRENCY, issues, async (issue) => {
|
||||
if (issue.labels.indexOf('meeting') >= 0 && issue.closed_at !== null) {
|
||||
await asyncPool(CONCURRENCY, issues, async issue => {
|
||||
if (
|
||||
issue.labels.includes('meeting') &&
|
||||
issue.closed_at !== null &&
|
||||
moment(issue.closed_at).isBefore(LAST_MEETING)
|
||||
) {
|
||||
Logger.info(`Issue ${issue.title} is closed before last meeting and has label "meeting". Removing it.`);
|
||||
|
||||
if (moment(issue.closed_at)
|
||||
.isBefore(LAST_MEETING)) {
|
||||
Logger.info(`Issue ${issue.title} is closed before last meeting and has label "meeting". Removing it.`);
|
||||
|
||||
await api.createNote(
|
||||
issue.project_id,
|
||||
Scope.ISSUES,
|
||||
issue.iid,
|
||||
`${NOTE_PREFIX} Removed label \`meeting\` automatically.
|
||||
await api.createNote(
|
||||
issue.project_id,
|
||||
Scope.ISSUES,
|
||||
issue.iid,
|
||||
`${NOTE_PREFIX} Removed label \`meeting\` automatically.
|
||||
/unlabel ~meeting`,
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "./node_modules/@openstapps/configuration/tslint.json"
|
||||
}
|
||||
Reference in New Issue
Block a user