mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-11 12:12:55 +00:00
feat: add batch processing of issues
This commit is contained in:
5
package-lock.json
generated
5
package-lock.json
generated
@@ -33,6 +33,11 @@
|
|||||||
"regenerator-runtime": "^0.13.2"
|
"regenerator-runtime": "^0.13.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@krlwlfrt/async-pool": {
|
||||||
|
"version": "0.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@krlwlfrt/async-pool/-/async-pool-0.1.0.tgz",
|
||||||
|
"integrity": "sha512-PbDyjVme3HR8CrMI04SokU97Enq/+txP5fS2O0XYVSmMYteJ7Q9CLO2y0t8PmNZkt4YCxmHgaNEdMs+/Ki+PAA=="
|
||||||
|
},
|
||||||
"@openstapps/configuration": {
|
"@openstapps/configuration": {
|
||||||
"version": "0.21.1",
|
"version": "0.21.1",
|
||||||
"resolved": "https://registry.npmjs.org/@openstapps/configuration/-/configuration-0.21.1.tgz",
|
"resolved": "https://registry.npmjs.org/@openstapps/configuration/-/configuration-0.21.1.tgz",
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
"author": "Karl-Philipp Wulfert <krlwlfrt@gmail.com>",
|
"author": "Karl-Philipp Wulfert <krlwlfrt@gmail.com>",
|
||||||
"license": "GPL-3.0-only",
|
"license": "GPL-3.0-only",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@krlwlfrt/async-pool": "0.1.0",
|
||||||
"@openstapps/logger": "0.4.0",
|
"@openstapps/logger": "0.4.0",
|
||||||
"@types/node": "10.17.5",
|
"@types/node": "10.17.5",
|
||||||
"@types/request": "2.48.3",
|
"@types/request": "2.48.3",
|
||||||
|
|||||||
43
src/cli.ts
43
src/cli.ts
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 StApps
|
* Copyright (C) 2018, 2019 StApps
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
* 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
|
* under the terms of the GNU General Public License as published by the Free
|
||||||
* Software Foundation, version 3.
|
* Software Foundation, version 3.
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License along with
|
* You should have received a copy of the GNU General Public License along with
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
import {asyncPool} from '@krlwlfrt/async-pool';
|
||||||
import {Logger} from '@openstapps/logger';
|
import {Logger} from '@openstapps/logger';
|
||||||
import {AddLogLevel} from '@openstapps/logger/lib/transformations/add-log-level';
|
import {AddLogLevel} from '@openstapps/logger/lib/transformations/add-log-level';
|
||||||
import {Colorize} from '@openstapps/logger/lib/transformations/colorize';
|
import {Colorize} from '@openstapps/logger/lib/transformations/colorize';
|
||||||
@@ -19,6 +20,7 @@ import * as commander from 'commander';
|
|||||||
import {readFileSync} from 'fs';
|
import {readFileSync} from 'fs';
|
||||||
import {join} from 'path';
|
import {join} from 'path';
|
||||||
import {Api, ApiRequestOptions} from './api';
|
import {Api, ApiRequestOptions} from './api';
|
||||||
|
import {Issue} from './types';
|
||||||
|
|
||||||
Logger.setTransformations([
|
Logger.setTransformations([
|
||||||
new AddLogLevel(),
|
new AddLogLevel(),
|
||||||
@@ -48,14 +50,49 @@ commander
|
|||||||
options.data = JSON.parse(data);
|
options.data = JSON.parse(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const gitLabApi = new Api(commander.url, commander.token);
|
const api = new Api(commander.url, commander.token);
|
||||||
|
|
||||||
const result = await gitLabApi.makeGitLabAPIRequest(call, options);
|
const result = await api.makeGitLabAPIRequest(call, options);
|
||||||
|
|
||||||
// tslint:disable-next-line:no-console
|
// tslint:disable-next-line:no-console
|
||||||
console.log(result);
|
console.log(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
commander
|
||||||
|
.command('batch-process <projectId> <action>')
|
||||||
|
.action(async (projectId, action) => {
|
||||||
|
if (!['close'].includes(action)) {
|
||||||
|
await Logger.error('Only "close" is supported as action.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const api = new Api(commander.url, commander.token);
|
||||||
|
|
||||||
|
const issues = await api.makeGitLabAPIRequest(`/projects/${projectId}/issues?state=opened`, {
|
||||||
|
retryOnAnyError: true,
|
||||||
|
tries: 10,
|
||||||
|
}) as Issue[];
|
||||||
|
|
||||||
|
Logger.log(`Fetched ${issues.length} issue(s).`);
|
||||||
|
|
||||||
|
// tslint:disable-next-line:no-magic-numbers
|
||||||
|
await asyncPool(5, issues, async (issue) => {
|
||||||
|
if (action === 'close') {
|
||||||
|
await api.makeGitLabAPIRequest(`/projects/${projectId}/issues/${issue.iid}`, {
|
||||||
|
data: {
|
||||||
|
state_event: 'close',
|
||||||
|
},
|
||||||
|
method: 'PUT',
|
||||||
|
retryOnAnyError: true,
|
||||||
|
tries: 10,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// tslint:disable-next-line:no-console
|
||||||
|
Logger.info(`Processed issue #${issue.iid} of project '${projectId}': ${issue.title}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
Logger.ok('Processed all issues.');
|
||||||
|
});
|
||||||
|
|
||||||
commander
|
commander
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user