allure 3.0.0-beta.2 → 3.0.0-beta.21

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.
Files changed (70) hide show
  1. package/README.md +148 -16
  2. package/dist/commands/allure2.d.ts +15 -0
  3. package/dist/commands/allure2.js +77 -0
  4. package/dist/commands/awesome.d.ts +18 -12
  5. package/dist/commands/awesome.js +83 -75
  6. package/dist/commands/classic.d.ts +15 -11
  7. package/dist/commands/classic.js +71 -63
  8. package/dist/commands/csv.d.ts +13 -9
  9. package/dist/commands/csv.js +63 -45
  10. package/dist/commands/dashboard.d.ts +15 -0
  11. package/dist/commands/dashboard.js +77 -0
  12. package/dist/commands/generate.d.ts +12 -9
  13. package/dist/commands/generate.js +98 -26
  14. package/dist/commands/history.d.ts +9 -7
  15. package/dist/commands/history.js +32 -29
  16. package/dist/commands/index.d.ts +8 -0
  17. package/dist/commands/index.js +8 -0
  18. package/dist/commands/jira/clear.d.ts +16 -0
  19. package/dist/commands/jira/clear.js +113 -0
  20. package/dist/commands/jira/index.d.ts +1 -0
  21. package/dist/commands/jira/index.js +1 -0
  22. package/dist/commands/knownIssue.d.ts +8 -6
  23. package/dist/commands/knownIssue.js +31 -20
  24. package/dist/commands/log.d.ts +12 -7
  25. package/dist/commands/log.js +58 -40
  26. package/dist/commands/login.d.ts +8 -0
  27. package/dist/commands/login.js +50 -0
  28. package/dist/commands/logout.d.ts +8 -0
  29. package/dist/commands/logout.js +50 -0
  30. package/dist/commands/open.d.ts +11 -8
  31. package/dist/commands/open.js +36 -36
  32. package/dist/commands/projects/create.d.ts +9 -0
  33. package/dist/commands/projects/create.js +83 -0
  34. package/dist/commands/projects/delete.d.ts +10 -0
  35. package/dist/commands/projects/delete.js +68 -0
  36. package/dist/commands/projects/index.d.ts +3 -0
  37. package/dist/commands/projects/index.js +3 -0
  38. package/dist/commands/projects/list.d.ts +8 -0
  39. package/dist/commands/projects/list.js +75 -0
  40. package/dist/commands/qualityGate.d.ts +14 -6
  41. package/dist/commands/qualityGate.js +125 -39
  42. package/dist/commands/results/index.d.ts +2 -0
  43. package/dist/commands/results/index.js +2 -0
  44. package/dist/commands/results/pack.d.ts +10 -0
  45. package/dist/commands/results/pack.js +106 -0
  46. package/dist/commands/results/unpack.d.ts +9 -0
  47. package/dist/commands/results/unpack.js +79 -0
  48. package/dist/commands/run.d.ts +24 -10
  49. package/dist/commands/run.js +279 -109
  50. package/dist/commands/slack.d.ts +9 -5
  51. package/dist/commands/slack.js +55 -31
  52. package/dist/commands/testplan.d.ts +8 -6
  53. package/dist/commands/testplan.js +38 -30
  54. package/dist/commands/watch.d.ts +12 -10
  55. package/dist/commands/watch.js +110 -106
  56. package/dist/commands/whoami.d.ts +8 -0
  57. package/dist/commands/whoami.js +57 -0
  58. package/dist/index.d.ts +2 -2
  59. package/dist/index.js +36 -28
  60. package/dist/utils/index.d.ts +1 -0
  61. package/dist/utils/index.js +1 -0
  62. package/dist/utils/logs.d.ts +3 -0
  63. package/dist/utils/logs.js +32 -0
  64. package/dist/utils/process.d.ts +8 -2
  65. package/dist/utils/process.js +17 -6
  66. package/dist/utils/terminal.d.ts +1 -1
  67. package/dist/utils/terminal.js +1 -1
  68. package/package.json +35 -15
  69. package/dist/utils/commands.d.ts +0 -16
  70. package/dist/utils/commands.js +0 -14
@@ -1,9 +1,13 @@
1
- type CsvCommandOptions = {
2
- separator?: string;
3
- disableHeaders?: boolean;
4
- output?: string;
5
- knownIssues?: string;
6
- };
7
- export declare const CsvCommandAction: (resultsDir: string, options: CsvCommandOptions) => Promise<void>;
8
- export declare const CsvCommand: (cli: import("cac").CAC) => void;
9
- export {};
1
+ import { Command } from "clipanion";
2
+ export declare class CsvCommand extends Command {
3
+ static paths: string[][];
4
+ static usage: import("clipanion").Usage;
5
+ resultsDir: string;
6
+ config: string | undefined;
7
+ cwd: string | undefined;
8
+ output: string | undefined;
9
+ disableHeaders: boolean | undefined;
10
+ separator: string | undefined;
11
+ knownIssues: string | undefined;
12
+ execute(): Promise<void>;
13
+ }
@@ -1,51 +1,69 @@
1
- import { AllureReport, resolveConfig } from "@allure/core";
2
- import { createCommand } from "../utils/commands.js";
3
- export const CsvCommandAction = async (resultsDir, options) => {
4
- const before = new Date().getTime();
5
- const config = await resolveConfig({
6
- plugins: {
7
- "@allure/plugin-csv": {
8
- options,
9
- },
10
- },
11
- });
12
- const allureReport = new AllureReport(config);
13
- await allureReport.start();
14
- await allureReport.readDirectory(resultsDir);
15
- await allureReport.done();
16
- const after = new Date().getTime();
17
- console.log(`the report successfully generated (${after - before}ms)`);
18
- };
19
- export const CsvCommand = createCommand({
20
- name: "csv <resultsDir>",
21
- description: "Generates CSV report based on provided Allure Results",
22
- options: [
23
- [
24
- "--output, -o <file>",
25
- {
26
- description: "The output file name. Absolute paths are accepted as well",
27
- default: "allure.csv",
28
- },
29
- ],
30
- [
31
- "--disable-headers",
1
+ import { AllureReport, readConfig } from "@allurereport/core";
2
+ import CsvPlugin from "@allurereport/plugin-csv";
3
+ import { Command, Option } from "clipanion";
4
+ import * as console from "node:console";
5
+ import { realpath } from "node:fs/promises";
6
+ import process from "node:process";
7
+ export class CsvCommand extends Command {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.resultsDir = Option.String({ required: true, name: "The directory with Allure results" });
11
+ this.config = Option.String("--config,-c", {
12
+ description: "The path Allure config file",
13
+ });
14
+ this.cwd = Option.String("--cwd", {
15
+ description: "The working directory for the command to run (default: current working directory)",
16
+ });
17
+ this.output = Option.String("--output,-o", {
18
+ description: "The output file name. Absolute paths are accepted as well",
19
+ });
20
+ this.disableHeaders = Option.Boolean("--disable-headers", {
21
+ description: "Specify, to disable CSV headers",
22
+ });
23
+ this.separator = Option.String("--separator", {
24
+ description: "The csv separator",
25
+ });
26
+ this.knownIssues = Option.String("--known-issues", {
27
+ description: "Path to the known issues file. Updates the file and quarantines failed tests when specified",
28
+ });
29
+ }
30
+ async execute() {
31
+ const cwd = await realpath(this.cwd ?? process.cwd());
32
+ const before = new Date().getTime();
33
+ const defaultCsvOptions = {
34
+ separator: this.separator ?? ",",
35
+ disableHeaders: this.disableHeaders ?? false,
36
+ };
37
+ const config = await readConfig(cwd, this.config, {
38
+ output: this.output ?? "allure.csv",
39
+ knownIssuesPath: this.knownIssues,
40
+ });
41
+ config.plugins = [
32
42
  {
33
- description: "Specify, to disable CSV headers",
43
+ id: "csv",
44
+ enabled: true,
45
+ options: defaultCsvOptions,
46
+ plugin: new CsvPlugin(defaultCsvOptions),
34
47
  },
35
- ],
36
- [
37
- "--separator <string>",
38
- {
39
- description: "The csv separator",
40
- default: ",",
41
- },
42
- ],
48
+ ];
49
+ const allureReport = new AllureReport(config);
50
+ await allureReport.start();
51
+ await allureReport.readDirectory(this.resultsDir);
52
+ await allureReport.done();
53
+ const after = new Date().getTime();
54
+ console.log(`the report successfully generated (${after - before}ms)`);
55
+ }
56
+ }
57
+ CsvCommand.paths = [["csv"]];
58
+ CsvCommand.usage = Command.Usage({
59
+ category: "Reports",
60
+ description: "Generates CSV report based on provided Allure Results",
61
+ details: "This command generates a CSV report from the provided Allure Results directory.",
62
+ examples: [
63
+ ["csv ./allure-results", "Generate a report from the ./allure-results directory"],
43
64
  [
44
- "--known-issues <file>",
45
- {
46
- description: "Path to the known issues file. Updates the file and quarantines failed tests when specified",
47
- },
65
+ "csv ./allure-results --output custom-report.csv",
66
+ "Generate a report from the ./allure-results directory to the custom-report.csv file",
48
67
  ],
49
68
  ],
50
- action: CsvCommandAction,
51
69
  });
@@ -0,0 +1,15 @@
1
+ import { Command } from "clipanion";
2
+ export declare class DashboardCommand extends Command {
3
+ static paths: string[][];
4
+ static usage: import("clipanion").Usage;
5
+ resultsDir: string;
6
+ config: string | undefined;
7
+ cwd: string | undefined;
8
+ output: string | undefined;
9
+ reportName: string | undefined;
10
+ singleFile: boolean | undefined;
11
+ logo: string | undefined;
12
+ theme: string | undefined;
13
+ reportLanguage: string | undefined;
14
+ execute(): Promise<void>;
15
+ }
@@ -0,0 +1,77 @@
1
+ import { AllureReport, readConfig } from "@allurereport/core";
2
+ import DashboardPlugin from "@allurereport/plugin-dashboard";
3
+ import { Command, Option } from "clipanion";
4
+ import * as console from "node:console";
5
+ import { realpath } from "node:fs/promises";
6
+ import process from "node:process";
7
+ export class DashboardCommand extends Command {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.resultsDir = Option.String({ required: true, name: "The directory with Allure results" });
11
+ this.config = Option.String("--config,-c", {
12
+ description: "The path Allure config file",
13
+ });
14
+ this.cwd = Option.String("--cwd", {
15
+ description: "The working directory for the command to run (default: current working directory)",
16
+ });
17
+ this.output = Option.String("--output,-o", {
18
+ description: "The output directory name. Absolute paths are accepted as well",
19
+ });
20
+ this.reportName = Option.String("--report-name,--name", {
21
+ description: "The report name",
22
+ });
23
+ this.singleFile = Option.Boolean("--single-file", {
24
+ description: "Generate single file report",
25
+ });
26
+ this.logo = Option.String("--logo", {
27
+ description: "Path to the report logo which will be displayed in the header",
28
+ });
29
+ this.theme = Option.String("--theme", {
30
+ description: "Default theme of the report (default: OS theme)",
31
+ });
32
+ this.reportLanguage = Option.String("--report-language,--lang", {
33
+ description: "Default language of the report (default: OS language)",
34
+ });
35
+ }
36
+ async execute() {
37
+ const cwd = await realpath(this.cwd ?? process.cwd());
38
+ const before = new Date().getTime();
39
+ const defaultDashboardOptions = {
40
+ singleFile: this.singleFile ?? false,
41
+ logo: this.logo,
42
+ theme: this.theme,
43
+ reportLanguage: this.reportLanguage ?? "en",
44
+ };
45
+ const config = await readConfig(cwd, this.config, {
46
+ output: this.output ?? "allure-report",
47
+ name: this.reportName ?? "Allure Report",
48
+ });
49
+ config.plugins = [
50
+ {
51
+ id: "dashboard",
52
+ enabled: true,
53
+ options: defaultDashboardOptions,
54
+ plugin: new DashboardPlugin(defaultDashboardOptions),
55
+ },
56
+ ];
57
+ const allureReport = new AllureReport(config);
58
+ await allureReport.start();
59
+ await allureReport.readDirectory(this.resultsDir);
60
+ await allureReport.done();
61
+ const after = new Date().getTime();
62
+ console.log(`the report successfully generated (${after - before}ms)`);
63
+ }
64
+ }
65
+ DashboardCommand.paths = [["dashboard"]];
66
+ DashboardCommand.usage = Command.Usage({
67
+ category: "Reports",
68
+ description: "Generates Allure Dashboard report based on provided Allure Results",
69
+ details: "This command generates an Allure Dashboard report from the provided Allure Results directory.",
70
+ examples: [
71
+ ["dashboard ./allure-results", "Generate a report from the ./allure-results directory"],
72
+ [
73
+ "dashboard ./allure-results --output custom-report",
74
+ "Generate a report from the ./allure-results directory to the custom-report directory",
75
+ ],
76
+ ],
77
+ });
@@ -1,9 +1,12 @@
1
- type CommandOptions = {
2
- config?: string;
3
- output?: string;
4
- cwd?: string;
5
- reportName?: string;
6
- };
7
- export declare const GenerateCommandAction: (resultsDir: string, options: CommandOptions) => Promise<void>;
8
- export declare const GenerateCommand: (cli: import("cac").CAC) => void;
9
- export {};
1
+ import { Command } from "clipanion";
2
+ export declare class GenerateCommand extends Command {
3
+ static paths: string[][];
4
+ static usage: import("clipanion").Usage;
5
+ resultsDir: string | undefined;
6
+ config: string | undefined;
7
+ output: string | undefined;
8
+ cwd: string | undefined;
9
+ reportName: string | undefined;
10
+ stage: string[] | undefined;
11
+ execute(): Promise<void>;
12
+ }
@@ -1,35 +1,107 @@
1
- import { AllureReport, readRuntimeConfig } from "@allure/core";
2
- import { createCommand } from "../utils/commands.js";
3
- export const GenerateCommandAction = async (resultsDir, options) => {
4
- const { config: configPath, output, cwd, reportName } = options;
5
- const config = await readRuntimeConfig(configPath, cwd, output, reportName);
6
- const allureReport = new AllureReport(config);
7
- await allureReport.start();
8
- await allureReport.readDirectory(resultsDir);
9
- await allureReport.done();
10
- };
11
- export const GenerateCommand = createCommand({
12
- name: "generate <resultsDir>",
1
+ import { AllureReport, readConfig } from "@allurereport/core";
2
+ import { KnownError } from "@allurereport/service";
3
+ import { Command, Option } from "clipanion";
4
+ import { glob } from "glob";
5
+ import * as console from "node:console";
6
+ import { exit, cwd as processCwd } from "node:process";
7
+ import { red } from "yoctocolors";
8
+ import { logError } from "../utils/logs.js";
9
+ export class GenerateCommand extends Command {
10
+ constructor() {
11
+ super(...arguments);
12
+ this.resultsDir = Option.String({
13
+ required: false,
14
+ name: "Pattern to match test results directories in the current working directory (default: ./**/allure-results)",
15
+ });
16
+ this.config = Option.String("--config,-c", {
17
+ description: "The path Allure config file",
18
+ });
19
+ this.output = Option.String("--output,-o", {
20
+ description: "The output directory name. Absolute paths are accepted as well (default: allure-report)",
21
+ });
22
+ this.cwd = Option.String("--cwd", {
23
+ description: "The working directory for the command to run (default: current working directory)",
24
+ });
25
+ this.reportName = Option.String("--report-name,--name", {
26
+ description: "The report name (default: Allure Report)",
27
+ });
28
+ this.stage = Option.Array("--stage", {
29
+ description: "Stages archives to restore state from (default: empty string)",
30
+ });
31
+ }
32
+ async execute() {
33
+ const cwd = this.cwd ?? processCwd();
34
+ const resultsDir = (this.resultsDir ?? "./**/allure-results").replace(/[\\/]$/, "");
35
+ const config = await readConfig(cwd, this.config, {
36
+ name: this.reportName,
37
+ output: this.output ?? "allure-report",
38
+ });
39
+ const stageDumpFiles = [];
40
+ const resultsDirectories = [];
41
+ if (this.stage?.length) {
42
+ for (const stage of this.stage) {
43
+ const matchedFiles = await glob(stage, {
44
+ nodir: true,
45
+ dot: true,
46
+ absolute: true,
47
+ windowsPathsNoEscape: true,
48
+ cwd,
49
+ });
50
+ stageDumpFiles.push(...matchedFiles);
51
+ }
52
+ }
53
+ if (!!this.resultsDir || stageDumpFiles.length === 0) {
54
+ const matchedDirs = (await glob(resultsDir, {
55
+ mark: true,
56
+ nodir: false,
57
+ absolute: true,
58
+ dot: true,
59
+ windowsPathsNoEscape: true,
60
+ cwd,
61
+ })).filter((p) => /(\/|\\)$/.test(p));
62
+ resultsDirectories.push(...matchedDirs);
63
+ }
64
+ if (resultsDirectories.length === 0 && stageDumpFiles.length === 0) {
65
+ console.log(red(`No test results directories found matching pattern: ${resultsDir}`));
66
+ return;
67
+ }
68
+ try {
69
+ const allureReport = new AllureReport(config);
70
+ await allureReport.restoreState(Array.from(stageDumpFiles));
71
+ await allureReport.start();
72
+ for (const dir of resultsDirectories) {
73
+ await allureReport.readDirectory(dir);
74
+ }
75
+ await allureReport.done();
76
+ }
77
+ catch (error) {
78
+ if (error instanceof KnownError) {
79
+ console.error(red(error.message));
80
+ exit(1);
81
+ return;
82
+ }
83
+ await logError("Failed to generate report due to unexpected error", error);
84
+ exit(1);
85
+ }
86
+ }
87
+ }
88
+ GenerateCommand.paths = [["generate"]];
89
+ GenerateCommand.usage = Command.Usage({
13
90
  description: "Generates the report to specified directory",
14
- options: [
91
+ details: "This command generates a report from the provided Allure Results directory.",
92
+ examples: [
93
+ ["generate ./allure-results", "Generate a report from the ./allure-results directory"],
15
94
  [
16
- "--config, -c <file>",
17
- {
18
- description: "The path Allure config file",
19
- },
95
+ "generate ./allure-results --output custom-report",
96
+ "Generate a report from the ./allure-results directory to the custom-report directory",
20
97
  ],
21
98
  [
22
- "--output, -o <file>",
23
- {
24
- description: "The output directory name. Absolute paths are accepted as well (default: allure-report)",
25
- },
99
+ "generate --stage=windows.zip --stage=macos.zip ./allure-results",
100
+ "Generate a report using data from windows.zip and macos.zip archives and using results from the ./allure-results directory",
26
101
  ],
27
102
  [
28
- "--cwd <cwd>",
29
- {
30
- description: "The working directory for the command to run (default: current working directory)",
31
- },
103
+ "generate --stage=allure-*.zip",
104
+ "Generate a report using data from any stage archive that matches the given pattern only (ignoring results directories)",
32
105
  ],
33
106
  ],
34
- action: GenerateCommandAction,
35
107
  });
@@ -1,7 +1,9 @@
1
- type CommandOptions = {
2
- historyPath?: string;
3
- reportName?: string;
4
- };
5
- export declare const HistoryCommandAction: (resultsDir: string, options: CommandOptions) => Promise<void>;
6
- export declare const HistoryCommand: (cli: import("cac").CAC) => void;
7
- export {};
1
+ import { Command } from "clipanion";
2
+ export declare class HistoryCommand extends Command {
3
+ static paths: string[][];
4
+ static usage: import("clipanion").Usage;
5
+ resultsDir: string;
6
+ historyPath: string | undefined;
7
+ reportName: string | undefined;
8
+ execute(): Promise<void>;
9
+ }
@@ -1,34 +1,37 @@
1
- import { AllureReport, resolveConfig } from "@allure/core";
2
- import { createCommand } from "../utils/commands.js";
3
- export const HistoryCommandAction = async (resultsDir, options) => {
4
- const config = await resolveConfig({
5
- historyPath: options.historyPath,
6
- name: options.reportName,
7
- plugins: {},
8
- });
9
- const allureReport = new AllureReport(config);
10
- await allureReport.start();
11
- await allureReport.readDirectory(resultsDir);
12
- await allureReport.done();
13
- };
14
- export const HistoryCommand = createCommand({
15
- name: "history <resultsDir>",
1
+ import { AllureReport, resolveConfig } from "@allurereport/core";
2
+ import { Command, Option } from "clipanion";
3
+ export class HistoryCommand extends Command {
4
+ constructor() {
5
+ super(...arguments);
6
+ this.resultsDir = Option.String({ required: true, name: "The directory with Allure results" });
7
+ this.historyPath = Option.String("--history-path,-h", {
8
+ description: "The path to history file",
9
+ });
10
+ this.reportName = Option.String("--report-name,--name", {
11
+ description: "The report name",
12
+ });
13
+ }
14
+ async execute() {
15
+ const config = await resolveConfig({
16
+ historyPath: this.historyPath ?? "history.jsonl",
17
+ name: this.reportName ?? "Allure Report",
18
+ plugins: {},
19
+ });
20
+ const allureReport = new AllureReport(config);
21
+ await allureReport.start();
22
+ await allureReport.readDirectory(this.resultsDir);
23
+ await allureReport.done();
24
+ }
25
+ }
26
+ HistoryCommand.paths = [["history"]];
27
+ HistoryCommand.usage = Command.Usage({
16
28
  description: "Generates the history to specified folder",
17
- options: [
29
+ details: "This command generates history from the provided Allure Results directory.",
30
+ examples: [
31
+ ["history ./allure-results", "Generate history from the ./allure-results directory"],
18
32
  [
19
- "--history-path, -h <file>",
20
- {
21
- description: "The path to history file",
22
- default: "history.jsonl",
23
- },
24
- ],
25
- [
26
- "--report-name, --name <string>",
27
- {
28
- description: "The report name",
29
- default: "Allure Report",
30
- },
33
+ "history ./allure-results --history-path custom-history.jsonl",
34
+ "Generate history from the ./allure-results directory to the custom-history.jsonl file",
31
35
  ],
32
36
  ],
33
- action: HistoryCommandAction,
34
37
  });
@@ -1,6 +1,7 @@
1
1
  export * from "./history.js";
2
2
  export * from "./testplan.js";
3
3
  export * from "./classic.js";
4
+ export * from "./allure2.js";
4
5
  export * from "./awesome.js";
5
6
  export * from "./csv.js";
6
7
  export * from "./history.js";
@@ -13,3 +14,10 @@ export * from "./open.js";
13
14
  export * from "./qualityGate.js";
14
15
  export * from "./log.js";
15
16
  export * from "./generate.js";
17
+ export * from "./dashboard.js";
18
+ export * from "./login.js";
19
+ export * from "./logout.js";
20
+ export * from "./whoami.js";
21
+ export * from "./projects/index.js";
22
+ export * from "./results/index.js";
23
+ export * from "./jira/index.js";
@@ -1,6 +1,7 @@
1
1
  export * from "./history.js";
2
2
  export * from "./testplan.js";
3
3
  export * from "./classic.js";
4
+ export * from "./allure2.js";
4
5
  export * from "./awesome.js";
5
6
  export * from "./csv.js";
6
7
  export * from "./history.js";
@@ -13,3 +14,10 @@ export * from "./open.js";
13
14
  export * from "./qualityGate.js";
14
15
  export * from "./log.js";
15
16
  export * from "./generate.js";
17
+ export * from "./dashboard.js";
18
+ export * from "./login.js";
19
+ export * from "./logout.js";
20
+ export * from "./whoami.js";
21
+ export * from "./projects/index.js";
22
+ export * from "./results/index.js";
23
+ export * from "./jira/index.js";
@@ -0,0 +1,16 @@
1
+ import { Command } from "clipanion";
2
+ declare abstract class BaseJiraCommand extends Command {
3
+ config: string | undefined;
4
+ cwd: string | undefined;
5
+ token: string | undefined;
6
+ webhook: string | undefined;
7
+ }
8
+ export declare class JiraClearCommand extends BaseJiraCommand {
9
+ static paths: string[][];
10
+ static usage: import("clipanion").Usage;
11
+ issues: string[];
12
+ clearReports: boolean | undefined;
13
+ clearResults: boolean | undefined;
14
+ execute(): Promise<void>;
15
+ }
16
+ export {};
@@ -0,0 +1,113 @@
1
+ import { getPluginInstance, readConfig } from "@allurereport/core";
2
+ import JiraPlugin from "@allurereport/plugin-jira";
3
+ import { Command, Option, UsageError } from "clipanion";
4
+ import { realpath } from "node:fs/promises";
5
+ import process, { exit } from "node:process";
6
+ import { green, red } from "yoctocolors";
7
+ class BaseJiraCommand extends Command {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.config = Option.String("--config,-c", {
11
+ description: "The path Allure config file",
12
+ });
13
+ this.cwd = Option.String("--cwd", {
14
+ description: "The working directory for the command to run (default: current working directory)",
15
+ });
16
+ this.token = Option.String("--token,-t", {
17
+ description: "Atlassian User OAuth Token (default: ALLURE_JIRA_TOKEN environment variable)",
18
+ required: false,
19
+ });
20
+ this.webhook = Option.String("--webhook", {
21
+ description: "Allure Jira Integration Webhook URL (default: ALLURE_JIRA_WEBHOOK environment variable)",
22
+ required: false,
23
+ });
24
+ }
25
+ }
26
+ export class JiraClearCommand extends BaseJiraCommand {
27
+ constructor() {
28
+ super(...arguments);
29
+ this.issues = Option.Array("--issue", {
30
+ description: "Jira issue key(s)",
31
+ required: true,
32
+ arity: 1,
33
+ });
34
+ this.clearReports = Option.Boolean("--reports", {
35
+ description: "Unlink reports from the specified Jira issue",
36
+ required: false,
37
+ });
38
+ this.clearResults = Option.Boolean("--results", {
39
+ description: "Unlink results from the specified Jira issue",
40
+ required: false,
41
+ });
42
+ }
43
+ async execute() {
44
+ const cwd = await realpath(this.cwd ?? process.cwd());
45
+ const config = await readConfig(cwd, this.config);
46
+ const pluginFromConfig = getPluginInstance(config, ({ plugin }) => plugin instanceof JiraPlugin);
47
+ const jiraPlugin = new JiraPlugin({
48
+ token: this.token ?? pluginFromConfig?.options?.token,
49
+ webhook: this.webhook ?? pluginFromConfig?.options?.webhook,
50
+ });
51
+ if (!jiraPlugin.options.token) {
52
+ throw new UsageError("Token is not provided");
53
+ }
54
+ if (!jiraPlugin.options.webhook) {
55
+ throw new UsageError("Webhook url is not provided");
56
+ }
57
+ if (!this.clearReports && !this.clearResults) {
58
+ throw new UsageError("Either --reports or --results must be provided");
59
+ }
60
+ const operation = this.clearReports && this.clearResults ? "clearAll" : this.clearReports ? "clearReports" : "clearResults";
61
+ if (operation === "clearAll") {
62
+ try {
63
+ await jiraPlugin.clearAll(this.issues);
64
+ this.context.stdout.write(green("All reports and test results have been unlinked from the specified Jira issue"));
65
+ }
66
+ catch (error) {
67
+ this.context.stderr.write(red("Failed to unlink reports and test results from the specified Jira issue"));
68
+ exit(1);
69
+ }
70
+ }
71
+ if (operation === "clearReports") {
72
+ try {
73
+ await jiraPlugin.clearReports(this.issues);
74
+ this.context.stdout.write(green("All reports have been unlinked from the specified Jira issue"));
75
+ }
76
+ catch (error) {
77
+ this.context.stderr.write(red("Failed to unlink reports from the specified Jira issue"));
78
+ exit(1);
79
+ }
80
+ }
81
+ if (operation === "clearResults") {
82
+ try {
83
+ await jiraPlugin.clearResults(this.issues);
84
+ this.context.stdout.write(green("All test results have been unlinked from the specified Jira issue"));
85
+ }
86
+ catch (error) {
87
+ this.context.stderr.write(red("Failed to unlink test results from the specified Jira issue"));
88
+ exit(1);
89
+ }
90
+ }
91
+ }
92
+ }
93
+ JiraClearCommand.paths = [["jira", "clear"]];
94
+ JiraClearCommand.usage = Command.Usage({
95
+ category: "Integrations",
96
+ description: "Unlink test results or reports in Jira",
97
+ details: "This command posts test results from the provided Allure Results directory to a Jira.",
98
+ examples: [
99
+ [
100
+ "Clear linked test results for the specified Jira issue",
101
+ "jira clear --token xoxb-token --webhook C12345 --issue JIRA-123 --results",
102
+ ],
103
+ [
104
+ "Clear linked reports for the specified Jira issue",
105
+ "jira clear --token xoxb-token --webhook C12345 --issue JIRA-123 --reports",
106
+ ],
107
+ [
108
+ "Clear linked test results and reports for the specified Jira issue",
109
+ "jira clear --token xoxb-token --webhook C12345 --issue JIRA-123 --results --reports",
110
+ ],
111
+ ["Clear from multiple Jira issues", "jira clear --issue JIRA-123 --issue JIRA-456 ..."],
112
+ ],
113
+ });
@@ -0,0 +1 @@
1
+ export * from "./clear.js";
@@ -0,0 +1 @@
1
+ export * from "./clear.js";