blob: e32d2d5d47be82a2e9a38f933e23b1839d191714 [file] [log] [blame]
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +02001// Copyright 2022 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import {LABELS_PREFIX} from "./IssueWizardConfig.ts";
6
7// Chromium project component prefix
8const CR_PREFIX = 'Cr-';
9
10// customized function for add additoinal data base on different categories.
11export function expandDescriptions(
12 category: string,
13 customQuestionsAnswers: Array<string>,
14 isRegression: boolean,
15 description: string,
16 labels: Array<any>,
17 component?: string,
18 ): {expandDescription:string, expandLabels:Array<any>, compVal:string} {
19 let expandDescription = "";
20 let expandLabels = labels;
21 let compVal = component || '';
22 let typeLabel = isRegression ? 'Type-Bug-Regression' : 'Type-Bug';
23
24 customQuestionsAnswers.forEach((ans) => {
25 if (ans.startsWith(LABELS_PREFIX)) {
26 const currentAnswer = ans.substring(LABELS_PREFIX.length);
27 switch (category) {
28 case 'Content':
29 if (currentAnswer.split(' - ')[0] === 'Yes') {
30 compVal = 'Cr-Blink';
31 typeLabel = 'Type-Bug';
32 } else {
33 compVal = '';
34 typeLabel = 'Type-Compat';
35 }
36 break;
37 case 'Extensions / Themes':
38 if (currentAnswer.split(' - ')[0] === 'Chrome Extension') {
39 compVal = 'Cr-Platform-Extensions';
40 } else {
41 compVal = 'Cr-UI-Browser-Themes';
42 }
43 break;
44 case 'Security':
45 if (typeLabel === '') {
46 typeLabel = 'Type-Bug-Security';
47 }
48 case 'Other':
49 typeLabel = "Type-Bug";
50 const issueType = currentAnswer.split(' - ')[0];
51 if (issueType !== 'Not sure'){
52 typeLabel = issueType;
53 }
54 if (issueType === 'Cr-UI-I18N') {
55 compVal = 'Cr-UI-I18N';
56 }
57 break;
58 case 'API':
59 compVal = currentAnswer;
60 if (compVal === "Not sure - I don't know") {
61 compVal = '';
62 }
63 break;
64 }
65 } else {
66 expandDescription = expandDescription + ans + "\n\n";
67 }
68 });
69
70 expandDescription = expandDescription + description;
71
72 if (typeLabel.length > 0) {
73 expandLabels.push({
74 label: typeLabel
75 });
76 }
77
78 if (compVal.length > 0) {
79 if (compVal.startsWith(CR_PREFIX)) {
80 compVal = compVal.substring(CR_PREFIX.length);
81 compVal = compVal.replace(/-/g, '>');
82 }
83 }
84 return {expandDescription, expandLabels, compVal};
85 }