mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 00:23:03 +00:00
feat: add batch processing of issues
This commit is contained in:
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
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
@@ -12,6 +12,7 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {asyncPool} from '@krlwlfrt/async-pool';
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {AddLogLevel} from '@openstapps/logger/lib/transformations/add-log-level';
|
||||
import {Colorize} from '@openstapps/logger/lib/transformations/colorize';
|
||||
@@ -19,6 +20,7 @@ import * as commander from 'commander';
|
||||
import {readFileSync} from 'fs';
|
||||
import {join} from 'path';
|
||||
import {Api, ApiRequestOptions} from './api';
|
||||
import {Issue} from './types';
|
||||
|
||||
Logger.setTransformations([
|
||||
new AddLogLevel(),
|
||||
@@ -48,14 +50,49 @@ commander
|
||||
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
|
||||
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
|
||||
.parse(process.argv);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user