bananareporter 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +127 -0
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +5 -0
- package/bin/run.cmd +3 -0
- package/dist/commands/run/index.d.ts +17 -0
- package/dist/commands/run/index.js +162 -0
- package/dist/core/index.d.ts +140 -0
- package/dist/core/index.js +47 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/integrations/base.d.ts +19 -0
- package/dist/integrations/base.js +18 -0
- package/dist/integrations/github.d.ts +215 -0
- package/dist/integrations/github.js +140 -0
- package/dist/integrations/gitlab.d.ts +122 -0
- package/dist/integrations/gitlab.js +246 -0
- package/dist/integrations/todotxt.d.ts +51 -0
- package/dist/integrations/todotxt.js +93 -0
- package/dist/util/common.d.ts +4 -0
- package/dist/util/common.js +14 -0
- package/dist/util/logger.d.ts +2 -0
- package/dist/util/logger.js +13 -0
- package/oclif.manifest.json +92 -0
- package/package.json +88 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 nya1
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
Banana Reporter
|
2
|
+
=================
|
3
|
+
|
4
|
+
Create a report in CSV, JSON/L from multiple sources (e.g. GitLab, GitHub, todo.txt etc.)
|
5
|
+
|
6
|
+
[](https://oclif.io)
|
7
|
+
[](https://npmjs.org/package/bananareporter)
|
8
|
+
[](https://circleci.com/gh/oclif/hello-world/tree/main)
|
9
|
+
[](https://npmjs.org/package/bananareporter)
|
10
|
+
[](https://github.com/oclif/hello-world/blob/main/package.json)
|
11
|
+
|
12
|
+
<!-- toc -->
|
13
|
+
* [Features](#features)
|
14
|
+
* [Quickstart](#quickstart)
|
15
|
+
* [Usage](#usage)
|
16
|
+
* [Commands](#commands)
|
17
|
+
<!-- tocstop -->
|
18
|
+
|
19
|
+
# Features
|
20
|
+
|
21
|
+
- **Easy to use**: provide a `--from` and `--to` date range and a config file, all data will be fetched automatically
|
22
|
+
- **Multiple output formats**: output file can be a JSON, JSONL or CSV (via `--format`) _more coming soon_
|
23
|
+
- **Configurable**: data to be imported can be filtered using the configuration file and each option can be overridden per source
|
24
|
+
- **Sources Supported**: GitLab, GitHub and todo.txt files, _more coming soon_
|
25
|
+
|
26
|
+
# Quickstart
|
27
|
+
|
28
|
+
0. Install banana reporter CLI `npm i -g bananareporter`
|
29
|
+
|
30
|
+
1. Create a config file `bananareporter.yaml` with the sources that you want to fetch
|
31
|
+
|
32
|
+
```yaml
|
33
|
+
sources:
|
34
|
+
- type: 'gitlab'
|
35
|
+
committerUsername: usernameOnGitlab
|
36
|
+
token: glpat-personalaccesstoken
|
37
|
+
# filters:
|
38
|
+
# - on: '$project.path_with_namespace'
|
39
|
+
# regex: '(namespace|anotherone)'
|
40
|
+
- type: 'github'
|
41
|
+
committerUsername: usernameOnGithub
|
42
|
+
# optional, needed for commits on private repositories
|
43
|
+
token: personalaccesstoken
|
44
|
+
# filters:
|
45
|
+
# - on: 'repository.full_name'
|
46
|
+
# regex: '(namespace|anotherone)'
|
47
|
+
# - type: 'todo.txt'
|
48
|
+
# file: './todo.txt'
|
49
|
+
```
|
50
|
+
|
51
|
+
2. Run the reporter with a date range
|
52
|
+
|
53
|
+
```sh
|
54
|
+
bananareporter --from 2023-01-01 --to 2023-03-01 -c bananareporter.yaml
|
55
|
+
```
|
56
|
+
|
57
|
+
In the current directory you can find the `bananareporter.json` output
|
58
|
+
|
59
|
+
|
60
|
+
# Usage
|
61
|
+
<!-- usage -->
|
62
|
+
```sh-session
|
63
|
+
$ npm install -g bananareporter
|
64
|
+
$ bananareporter COMMAND
|
65
|
+
running command...
|
66
|
+
$ bananareporter (--version)
|
67
|
+
bananareporter/0.1.0 linux-x64 node-v18.14.2
|
68
|
+
$ bananareporter --help [COMMAND]
|
69
|
+
USAGE
|
70
|
+
$ bananareporter COMMAND
|
71
|
+
...
|
72
|
+
```
|
73
|
+
<!-- usagestop -->
|
74
|
+
# Commands
|
75
|
+
<!-- commands -->
|
76
|
+
* [`bananareporter help [COMMANDS]`](#bananareporter-help-commands)
|
77
|
+
* [`bananareporter run`](#bananareporter-run)
|
78
|
+
|
79
|
+
## `bananareporter help [COMMANDS]`
|
80
|
+
|
81
|
+
Display help for bananareporter.
|
82
|
+
|
83
|
+
```
|
84
|
+
USAGE
|
85
|
+
$ bananareporter help [COMMANDS] [-n]
|
86
|
+
|
87
|
+
ARGUMENTS
|
88
|
+
COMMANDS Command to show help for.
|
89
|
+
|
90
|
+
FLAGS
|
91
|
+
-n, --nested-commands Include all nested commands in the output.
|
92
|
+
|
93
|
+
DESCRIPTION
|
94
|
+
Display help for bananareporter.
|
95
|
+
```
|
96
|
+
|
97
|
+
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.2.7/src/commands/help.ts)_
|
98
|
+
|
99
|
+
## `bananareporter run`
|
100
|
+
|
101
|
+
Run report
|
102
|
+
|
103
|
+
```
|
104
|
+
USAGE
|
105
|
+
$ bananareporter run -o <value> --format json|jsonl|csv [-c <value>] [--to <value> --from <value>]
|
106
|
+
[--delay <value>] [--include-raw-object]
|
107
|
+
|
108
|
+
FLAGS
|
109
|
+
-c, --config=<value> config file location, by default ~/.config/bananareporter/config.yaml
|
110
|
+
-o, --out=<value> (required) [default: ./bananareporter.json] file path to save the output
|
111
|
+
--delay=<value> [default: 300] global delay in millisecons between http requests
|
112
|
+
--format=<option> (required) [default: json] output file format
|
113
|
+
<options: json|jsonl|csv>
|
114
|
+
--from=2023-03-01 from date (ISO8601)
|
115
|
+
--include-raw-object include raw object in json/jsonl reporter output
|
116
|
+
--to=2023-03-31 to date (ISO8601)
|
117
|
+
|
118
|
+
DESCRIPTION
|
119
|
+
Run report
|
120
|
+
|
121
|
+
EXAMPLES
|
122
|
+
$ banana-reporter run --from 2023-01-01 --to 2023-01-31
|
123
|
+
report with 138 entries saved to ./bananareporter.json
|
124
|
+
```
|
125
|
+
|
126
|
+
_See code: [dist/commands/run/index.ts](https://github.com/nya1/bananareporter/blob/v0.1.0/dist/commands/run/index.ts)_
|
127
|
+
<!-- commandsstop -->
|
package/bin/dev
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
const oclif = require('@oclif/core')
|
4
|
+
|
5
|
+
const path = require('path')
|
6
|
+
const project = path.join(__dirname, '..', 'tsconfig.json')
|
7
|
+
|
8
|
+
// In dev mode -> use ts-node and dev plugins
|
9
|
+
process.env.NODE_ENV = 'development'
|
10
|
+
|
11
|
+
require('ts-node').register({project})
|
12
|
+
|
13
|
+
// In dev mode, always show stack traces
|
14
|
+
oclif.settings.debug = true;
|
15
|
+
|
16
|
+
// Start the CLI
|
17
|
+
oclif.run().then(oclif.flush).catch(oclif.Errors.handle)
|
package/bin/dev.cmd
ADDED
package/bin/run
ADDED
package/bin/run.cmd
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
import { Command } from '@oclif/core';
|
2
|
+
export default class Run extends Command {
|
3
|
+
static description: string;
|
4
|
+
static dateStringValidation(input: string): string;
|
5
|
+
static examples: string[];
|
6
|
+
static flags: {
|
7
|
+
config: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
8
|
+
from: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
9
|
+
to: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
10
|
+
out: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
11
|
+
format: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
12
|
+
delay: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
13
|
+
'include-raw-object': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
14
|
+
'disable-welcome-emoji': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
15
|
+
};
|
16
|
+
run(): Promise<void>;
|
17
|
+
}
|
@@ -0,0 +1,162 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const core_1 = require("@oclif/core");
|
4
|
+
const yaml = require("js-yaml");
|
5
|
+
const node_fs_1 = require("node:fs");
|
6
|
+
const path = require("node:path");
|
7
|
+
const dayjs = require("dayjs");
|
8
|
+
const core_2 = require("../../core");
|
9
|
+
const base_1 = require("../../integrations/base");
|
10
|
+
const gitlab_1 = require("../../integrations/gitlab");
|
11
|
+
const papaparse_1 = require("papaparse");
|
12
|
+
const lodash_1 = require("lodash");
|
13
|
+
const logger_1 = require("../../util/logger");
|
14
|
+
const github_1 = require("../../integrations/github");
|
15
|
+
const todotxt_1 = require("../../integrations/todotxt");
|
16
|
+
class Run extends core_1.Command {
|
17
|
+
static dateStringValidation(input) {
|
18
|
+
if (!dayjs(input).isValid()) {
|
19
|
+
throw new Error(`provided date "${input}" is not valid, make sure it's valid ISO8601 string`);
|
20
|
+
}
|
21
|
+
return input;
|
22
|
+
}
|
23
|
+
async run() {
|
24
|
+
// this.log('🍌 Banana Reporter')
|
25
|
+
const { flags } = await this.parse(Run);
|
26
|
+
logger_1.logger.debug('run CLI flags', flags);
|
27
|
+
const configFileLocation = flags.config || path.join(this.config.configDir, 'config.yaml');
|
28
|
+
logger_1.logger.debug(`run configFileLocation: ${configFileLocation}`);
|
29
|
+
const configContent = yaml.load((0, node_fs_1.readFileSync)(configFileLocation).toString());
|
30
|
+
logger_1.logger.debug('run configContent', configContent);
|
31
|
+
const validatedConfig = (0, core_2.loadAndValidateConfig)({
|
32
|
+
...configContent,
|
33
|
+
configFileLocation,
|
34
|
+
...(0, lodash_1.omit)(flags, ['include-raw-object', 'config']),
|
35
|
+
includeRawObject: flags['include-raw-object'],
|
36
|
+
});
|
37
|
+
logger_1.logger.debug('run validatedConfig', validatedConfig);
|
38
|
+
// TODO the sources with different hosts / types can be called in parallel
|
39
|
+
let reportList = [];
|
40
|
+
for (const [i, s] of validatedConfig.sources.entries()) {
|
41
|
+
logger_1.logger.debug(`run source loop ${i}`, s);
|
42
|
+
this.log(`working on ${s.type} (${i + 1}) source`);
|
43
|
+
let res = [];
|
44
|
+
switch (s.type) {
|
45
|
+
case base_1.SourceType.Enum.gitlab: {
|
46
|
+
const integrationLoaded = new gitlab_1.GitlabIntegration(s, validatedConfig);
|
47
|
+
// eslint-disable-next-line no-await-in-loop
|
48
|
+
res = await integrationLoaded.fetchData();
|
49
|
+
break;
|
50
|
+
}
|
51
|
+
case base_1.SourceType.Enum.github: {
|
52
|
+
const integrationLoaded = new github_1.GithubIntegration(s, validatedConfig);
|
53
|
+
// eslint-disable-next-line no-await-in-loop
|
54
|
+
res = await integrationLoaded.fetchData();
|
55
|
+
break;
|
56
|
+
}
|
57
|
+
case base_1.SourceType.Enum['todo.txt']: {
|
58
|
+
const integrationLoaded = new todotxt_1.TodoTxtIntegration(s, validatedConfig);
|
59
|
+
// eslint-disable-next-line no-await-in-loop
|
60
|
+
res = await integrationLoaded.fetchData();
|
61
|
+
break;
|
62
|
+
}
|
63
|
+
default: {
|
64
|
+
this.error(`unknown source provided ${s.type}`);
|
65
|
+
}
|
66
|
+
}
|
67
|
+
logger_1.logger.debug(`run source loop integration res length ${res.length}`);
|
68
|
+
// eslint-disable-next-line unicorn/prefer-spread
|
69
|
+
reportList = reportList.concat(res);
|
70
|
+
}
|
71
|
+
if (reportList.length === 0) {
|
72
|
+
this.warn('no entries found, make sure the date range provided and the sources are correct');
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
// output
|
76
|
+
let outputStr = '';
|
77
|
+
// eslint-disable-next-line unicorn/prefer-switch
|
78
|
+
if (validatedConfig.format === core_2.BananaOutputFileFormat.Enum.csv) {
|
79
|
+
const fieldsColumns = ['date', 'type', 'username', 'projectName', 'description'];
|
80
|
+
logger_1.logger.debug('run converting json to csv');
|
81
|
+
const csvOutput = (0, papaparse_1.unparse)({
|
82
|
+
fields: fieldsColumns,
|
83
|
+
data: reportList,
|
84
|
+
});
|
85
|
+
outputStr = csvOutput;
|
86
|
+
}
|
87
|
+
else if (validatedConfig.format === core_2.BananaOutputFileFormat.Enum.json) {
|
88
|
+
outputStr = JSON.stringify(reportList, null, 2);
|
89
|
+
}
|
90
|
+
else if (validatedConfig.format === core_2.BananaOutputFileFormat.Enum.jsonl) {
|
91
|
+
logger_1.logger.debug('run converting json to jsonl');
|
92
|
+
outputStr = reportList.map(r => JSON.stringify(r)).join('\n');
|
93
|
+
}
|
94
|
+
const fileExt = `.${validatedConfig.format}`;
|
95
|
+
let outFile = validatedConfig.out;
|
96
|
+
// add file extension
|
97
|
+
if (!outFile.endsWith(fileExt)) {
|
98
|
+
if (outFile === Run.flags.out.default) {
|
99
|
+
outFile = outFile.replace(`.${Run.flags.format.default}`, fileExt);
|
100
|
+
}
|
101
|
+
else {
|
102
|
+
outFile += fileExt;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
logger_1.logger.debug(`run saving to ${outFile} with file content of size ${outputStr.length}`);
|
106
|
+
(0, node_fs_1.writeFileSync)(outFile, outputStr);
|
107
|
+
this.log(`report with ${reportList.length} entries saved to ${outFile}`);
|
108
|
+
// this.log(`run! ${flags.config} ${JSON.stringify(configContent)}`)
|
109
|
+
}
|
110
|
+
}
|
111
|
+
exports.default = Run;
|
112
|
+
Run.description = 'Run report';
|
113
|
+
Run.examples = [
|
114
|
+
`$ banana-reporter run --from 2023-01-01 --to 2023-01-31
|
115
|
+
report with 138 entries saved to ./bananareporter.json
|
116
|
+
`,
|
117
|
+
];
|
118
|
+
Run.flags = {
|
119
|
+
config: core_1.Flags.string({
|
120
|
+
char: 'c',
|
121
|
+
description: 'config file location, by default ~/.config/bananareporter/config.yaml',
|
122
|
+
required: false,
|
123
|
+
env: 'BANANAREPORTER_CONFIG_PATH',
|
124
|
+
}),
|
125
|
+
from: core_1.Flags.string({
|
126
|
+
description: 'from date (ISO8601)',
|
127
|
+
helpValue: `${dayjs().startOf('month').format('YYYY-MM-DD')}`,
|
128
|
+
required: false,
|
129
|
+
}),
|
130
|
+
to: core_1.Flags.string({
|
131
|
+
description: 'to date (ISO8601)',
|
132
|
+
helpValue: `${dayjs().endOf('month').format('YYYY-MM-DD')}`,
|
133
|
+
required: false,
|
134
|
+
dependsOn: ['from'],
|
135
|
+
}),
|
136
|
+
out: core_1.Flags.file({
|
137
|
+
char: 'o',
|
138
|
+
aliases: ['output'],
|
139
|
+
description: 'file path to save the output',
|
140
|
+
required: true,
|
141
|
+
default: './bananareporter.json',
|
142
|
+
}),
|
143
|
+
format: core_1.Flags.string({
|
144
|
+
description: 'output file format',
|
145
|
+
options: Object.values(core_2.BananaOutputFileFormat.Values),
|
146
|
+
required: true,
|
147
|
+
default: core_2.BananaOutputFileFormat.Enum.json,
|
148
|
+
}),
|
149
|
+
delay: core_1.Flags.integer({
|
150
|
+
description: 'global delay in millisecons between http requests',
|
151
|
+
default: 300,
|
152
|
+
}),
|
153
|
+
'include-raw-object': core_1.Flags.boolean({
|
154
|
+
description: 'include raw object in json/jsonl reporter output',
|
155
|
+
default: false,
|
156
|
+
}),
|
157
|
+
'disable-welcome-emoji': core_1.Flags.boolean({
|
158
|
+
description: 'disable banana welcome emoji',
|
159
|
+
default: false,
|
160
|
+
hidden: true,
|
161
|
+
}),
|
162
|
+
};
|
@@ -0,0 +1,140 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
export declare const BananaOutputFileFormat: z.ZodEnum<["json", "jsonl", "csv"]>;
|
3
|
+
export type BananaOutputFileFormat = z.infer<typeof BananaOutputFileFormat>;
|
4
|
+
export declare const BananaConfig: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
5
|
+
includeRawObject: z.ZodDefault<z.ZodBoolean>;
|
6
|
+
format: z.ZodEnum<["json", "jsonl", "csv"]>;
|
7
|
+
out: z.ZodString;
|
8
|
+
/**
|
9
|
+
* ISO8601 date range for all the sources,
|
10
|
+
* can be overridden per source
|
11
|
+
*/
|
12
|
+
from: z.ZodString;
|
13
|
+
to: z.ZodString;
|
14
|
+
/**
|
15
|
+
* banana reporter configuration file path
|
16
|
+
*/
|
17
|
+
configFileLocation: z.ZodString;
|
18
|
+
/**
|
19
|
+
* delay in seconds between every HTTP requests (sources)
|
20
|
+
*/
|
21
|
+
delay: z.ZodDefault<z.ZodNumber>;
|
22
|
+
/**
|
23
|
+
* where to fetch data
|
24
|
+
*/
|
25
|
+
sources: z.ZodArray<z.ZodObject<{
|
26
|
+
type: z.ZodEnum<["gitlab", "github", "todo.txt"]>;
|
27
|
+
}, "passthrough", z.ZodTypeAny, {
|
28
|
+
type: "gitlab" | "github" | "todo.txt";
|
29
|
+
} & {
|
30
|
+
[k: string]: unknown;
|
31
|
+
}, {
|
32
|
+
type: "gitlab" | "github" | "todo.txt";
|
33
|
+
} & {
|
34
|
+
[k: string]: unknown;
|
35
|
+
}>, "atleastone">;
|
36
|
+
}, "strip", z.ZodTypeAny, {
|
37
|
+
format: "json" | "csv" | "jsonl";
|
38
|
+
from: string;
|
39
|
+
out: string;
|
40
|
+
includeRawObject: boolean;
|
41
|
+
to: string;
|
42
|
+
configFileLocation: string;
|
43
|
+
delay: number;
|
44
|
+
sources: [{
|
45
|
+
type: "gitlab" | "github" | "todo.txt";
|
46
|
+
} & {
|
47
|
+
[k: string]: unknown;
|
48
|
+
}, ...({
|
49
|
+
type: "gitlab" | "github" | "todo.txt";
|
50
|
+
} & {
|
51
|
+
[k: string]: unknown;
|
52
|
+
})[]];
|
53
|
+
}, {
|
54
|
+
includeRawObject?: boolean | undefined;
|
55
|
+
delay?: number | undefined;
|
56
|
+
format: "json" | "csv" | "jsonl";
|
57
|
+
from: string;
|
58
|
+
out: string;
|
59
|
+
to: string;
|
60
|
+
configFileLocation: string;
|
61
|
+
sources: [{
|
62
|
+
type: "gitlab" | "github" | "todo.txt";
|
63
|
+
} & {
|
64
|
+
[k: string]: unknown;
|
65
|
+
}, ...({
|
66
|
+
type: "gitlab" | "github" | "todo.txt";
|
67
|
+
} & {
|
68
|
+
[k: string]: unknown;
|
69
|
+
})[]];
|
70
|
+
}>, {
|
71
|
+
format: "json" | "csv" | "jsonl";
|
72
|
+
from: string;
|
73
|
+
out: string;
|
74
|
+
includeRawObject: boolean;
|
75
|
+
to: string;
|
76
|
+
configFileLocation: string;
|
77
|
+
delay: number;
|
78
|
+
sources: [{
|
79
|
+
type: "gitlab" | "github" | "todo.txt";
|
80
|
+
} & {
|
81
|
+
[k: string]: unknown;
|
82
|
+
}, ...({
|
83
|
+
type: "gitlab" | "github" | "todo.txt";
|
84
|
+
} & {
|
85
|
+
[k: string]: unknown;
|
86
|
+
})[]];
|
87
|
+
}, {
|
88
|
+
includeRawObject?: boolean | undefined;
|
89
|
+
delay?: number | undefined;
|
90
|
+
format: "json" | "csv" | "jsonl";
|
91
|
+
from: string;
|
92
|
+
out: string;
|
93
|
+
to: string;
|
94
|
+
configFileLocation: string;
|
95
|
+
sources: [{
|
96
|
+
type: "gitlab" | "github" | "todo.txt";
|
97
|
+
} & {
|
98
|
+
[k: string]: unknown;
|
99
|
+
}, ...({
|
100
|
+
type: "gitlab" | "github" | "todo.txt";
|
101
|
+
} & {
|
102
|
+
[k: string]: unknown;
|
103
|
+
})[]];
|
104
|
+
}>, {
|
105
|
+
format: "json" | "csv" | "jsonl";
|
106
|
+
from: string;
|
107
|
+
out: string;
|
108
|
+
includeRawObject: boolean;
|
109
|
+
to: string;
|
110
|
+
configFileLocation: string;
|
111
|
+
delay: number;
|
112
|
+
sources: [{
|
113
|
+
type: "gitlab" | "github" | "todo.txt";
|
114
|
+
} & {
|
115
|
+
[k: string]: unknown;
|
116
|
+
}, ...({
|
117
|
+
type: "gitlab" | "github" | "todo.txt";
|
118
|
+
} & {
|
119
|
+
[k: string]: unknown;
|
120
|
+
})[]];
|
121
|
+
}, {
|
122
|
+
includeRawObject?: boolean | undefined;
|
123
|
+
delay?: number | undefined;
|
124
|
+
format: "json" | "csv" | "jsonl";
|
125
|
+
from: string;
|
126
|
+
out: string;
|
127
|
+
to: string;
|
128
|
+
configFileLocation: string;
|
129
|
+
sources: [{
|
130
|
+
type: "gitlab" | "github" | "todo.txt";
|
131
|
+
} & {
|
132
|
+
[k: string]: unknown;
|
133
|
+
}, ...({
|
134
|
+
type: "gitlab" | "github" | "todo.txt";
|
135
|
+
} & {
|
136
|
+
[k: string]: unknown;
|
137
|
+
})[]];
|
138
|
+
}>;
|
139
|
+
export type BananaConfig = z.infer<typeof BananaConfig>;
|
140
|
+
export declare function loadAndValidateConfig(input: unknown): BananaConfig;
|
@@ -0,0 +1,47 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.loadAndValidateConfig = exports.BananaConfig = exports.BananaOutputFileFormat = void 0;
|
4
|
+
const dayjs = require("dayjs");
|
5
|
+
const zod_1 = require("zod");
|
6
|
+
const base_1 = require("../integrations/base");
|
7
|
+
const common_1 = require("../util/common");
|
8
|
+
const logger_1 = require("../util/logger");
|
9
|
+
exports.BananaOutputFileFormat = zod_1.z.enum(['json', 'jsonl', 'csv']);
|
10
|
+
exports.BananaConfig = zod_1.z.object({
|
11
|
+
includeRawObject: zod_1.z.boolean().default(false),
|
12
|
+
format: exports.BananaOutputFileFormat,
|
13
|
+
out: zod_1.z.string().min(1),
|
14
|
+
/**
|
15
|
+
* ISO8601 date range for all the sources,
|
16
|
+
* can be overridden per source
|
17
|
+
*/
|
18
|
+
from: common_1.zIsoString,
|
19
|
+
to: common_1.zIsoString,
|
20
|
+
/**
|
21
|
+
* banana reporter configuration file path
|
22
|
+
*/
|
23
|
+
configFileLocation: zod_1.z.string().min(1),
|
24
|
+
/**
|
25
|
+
* delay in seconds between every HTTP requests (sources)
|
26
|
+
*/
|
27
|
+
delay: zod_1.z.number().min(0).max(5000).default(300),
|
28
|
+
/**
|
29
|
+
* where to fetch data
|
30
|
+
*/
|
31
|
+
sources: zod_1.z.array(zod_1.z.object({
|
32
|
+
type: base_1.SourceType,
|
33
|
+
}).passthrough()).nonempty(),
|
34
|
+
}).refine(schema => {
|
35
|
+
const dateFrom = dayjs(schema.from);
|
36
|
+
const dateTo = dayjs(schema.to);
|
37
|
+
return dateFrom.isSame(dateTo) || dateFrom.isBefore(dateTo);
|
38
|
+
}, "'from' date must be before 'to' date")
|
39
|
+
.refine(schema => {
|
40
|
+
return !(schema.includeRawObject && (schema.format !== exports.BananaOutputFileFormat.Enum.json && schema.format !== exports.BananaOutputFileFormat.Enum.jsonl));
|
41
|
+
}, "'include-raw-object' can only be used with json or jsonl format");
|
42
|
+
function loadAndValidateConfig(input) {
|
43
|
+
logger_1.logger.debug('loadAndValidateConfig input', input);
|
44
|
+
const validated = exports.BananaConfig.parse(input);
|
45
|
+
return validated;
|
46
|
+
}
|
47
|
+
exports.loadAndValidateConfig = loadAndValidateConfig;
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export { run } from '@oclif/core';
|
package/dist/index.js
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import { BananaConfig } from '../core';
|
3
|
+
export declare const SourceType: z.ZodEnum<["gitlab", "github", "todo.txt"]>;
|
4
|
+
export type SourceType = z.infer<typeof SourceType>;
|
5
|
+
export interface CommonBananaReporterObj {
|
6
|
+
date: string;
|
7
|
+
description: string;
|
8
|
+
username?: string;
|
9
|
+
projectId?: string;
|
10
|
+
projectName?: string;
|
11
|
+
type: SourceType;
|
12
|
+
__raw: any;
|
13
|
+
}
|
14
|
+
export declare abstract class IntegrationBase {
|
15
|
+
static type: SourceType;
|
16
|
+
constructor(_rawConfig: unknown, _bananaConfig: BananaConfig);
|
17
|
+
toBananaReporterObj(_rawData: any): Promise<CommonBananaReporterObj> | CommonBananaReporterObj;
|
18
|
+
fetchData(): Promise<CommonBananaReporterObj[]>;
|
19
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.IntegrationBase = exports.SourceType = void 0;
|
4
|
+
const zod_1 = require("zod");
|
5
|
+
exports.SourceType = zod_1.z.enum(['gitlab', 'github', 'todo.txt']);
|
6
|
+
// TODO improve base integration
|
7
|
+
class IntegrationBase {
|
8
|
+
// eslint-disable-next-line no-useless-constructor, @typescript-eslint/no-empty-function
|
9
|
+
constructor(_rawConfig, _bananaConfig) { }
|
10
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
11
|
+
toBananaReporterObj(_rawData) {
|
12
|
+
throw new Error('implement toBananaReporterObj method');
|
13
|
+
}
|
14
|
+
async fetchData() {
|
15
|
+
throw new Error('implement fetchData method');
|
16
|
+
}
|
17
|
+
}
|
18
|
+
exports.IntegrationBase = IntegrationBase;
|