Skip to content

Commit 143aba5

Browse files
author
gitstart_bot
committed
Improve testcase handling in Bugzilla Template
1 parent c929cef commit 143aba5

File tree

5 files changed

+189
-30
lines changed

5 files changed

+189
-30
lines changed

server/frontend/package-lock.json

+20-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/frontend/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"handlebars": "^4.7.8",
2020
"js-base64": "^3.7.7",
2121
"lodash": "^4.17.21",
22+
"mime": "^4.0.6",
2223
"prismjs": "^1.29.0",
2324
"sweetalert": "^2.1.2",
2425
"vue": "^3.4.21",

server/frontend/src/components/Bugs/Comments/PublicationForm.vue

+68-10
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,16 @@
117117
@update-not-attach-data="notAttachData = $event"
118118
@update-data="crashData = $event"
119119
/>
120-
121120
<TestCaseSection
122121
v-if="entry.testcase"
123122
mode="comment"
124123
:initial-not-attach-test="notAttachTest"
125124
:entry="entry"
126125
:template="template"
126+
:file-extension="fileExtension"
127+
:file-name="fileName"
127128
@update-not-attach-test="notAttachTest = $event"
128-
@update-filename="entry.testcase = $event"
129+
@update-filename="newFileName = $event"
129130
@update-content="testCaseContent = $event"
130131
/>
131132

@@ -227,6 +228,7 @@
227228
<script>
228229
import Handlebars from "handlebars";
229230
import { Base64 } from "js-base64";
231+
import mime from "mime";
230232
import { defineComponent } from "vue";
231233
import * as api from "../../../api";
232234
import * as bugzillaApi from "../../../bugzilla_api";
@@ -289,6 +291,7 @@ export default defineComponent({
289291
testCaseContent: "",
290292
notAttachData: false,
291293
crashData: "",
294+
newFileName: null,
292295
};
293296
},
294297
@@ -342,7 +345,7 @@ export default defineComponent({
342345
if (!this.template || !this.entry) return "";
343346
try {
344347
const compiled = Handlebars.compile(this.template.comment);
345-
let rendered = compiled({
348+
const renderedData = {
346349
summary: this.summary,
347350
shortsig: this.entry.shortSignature,
348351
product: this.entry.product,
@@ -359,7 +362,15 @@ export default defineComponent({
359362
? "(Crash data not available)"
360363
: "For detailed crash information, see attachment.",
361364
...this.metadataExtension(this.template.comment),
362-
});
365+
};
366+
367+
if (!this.notAttachTest) {
368+
renderedData["testcase_attachment"] = this.filenameWithExtension;
369+
} else {
370+
delete renderedData["testcase_attachment"];
371+
}
372+
373+
let rendered = compiled(renderedData);
363374
364375
// Remove the specified pathPrefix from traces and assertion
365376
if (this.entryMetadata.pathprefix) {
@@ -371,6 +382,32 @@ export default defineComponent({
371382
return "";
372383
}
373384
},
385+
fileName() {
386+
const { attachmentFilename } = this.getFileDetails();
387+
388+
return this.newFileName ?? attachmentFilename;
389+
},
390+
fileExtension() {
391+
const { attachmentFilenameExtension } = this.getFileDetails();
392+
393+
return attachmentFilenameExtension;
394+
},
395+
filenameWithExtension() {
396+
return this.fileName + "." + this.fileExtension;
397+
},
398+
fileMimetype() {
399+
const mimeType = mime.getType(this.filenameWithExtension);
400+
401+
if (mimeType) {
402+
return mimeType;
403+
}
404+
405+
if (this.entry.testcase_isbinary) {
406+
return "application/octet-stream";
407+
}
408+
409+
return "text/plain";
410+
},
374411
},
375412
376413
watch: {
@@ -440,6 +477,8 @@ export default defineComponent({
440477
is_private: this.isPrivate,
441478
};
442479
480+
await this.publishAttachments();
481+
443482
try {
444483
let data = await bugzillaApi.createComment({
445484
hostname: this.provider.hostname,
@@ -471,9 +510,9 @@ export default defineComponent({
471510
const payload = {
472511
ids: [this.externalBugId],
473512
data: Base64.encode(this.crashData),
474-
file_name: "crash_data.txt",
513+
file_name: this.filenameWithExtension,
475514
summary: "Detailed Crash Information",
476-
content_type: "text/plain",
515+
content_type: this.fileMimetype,
477516
};
478517
479518
try {
@@ -510,11 +549,9 @@ export default defineComponent({
510549
data: this.entry.testcase_isbinary
511550
? Base64.fromUint8Array(content)
512551
: Base64.encode(content),
513-
file_name: this.entry.testcase,
552+
file_name: this.filenameWithExtension,
514553
summary: `Testcase for ${comment}`,
515-
content_type: this.entry.testcase_isbinary
516-
? "application/octet-stream"
517-
: "text/plain",
554+
content_type: this.fileMimetype,
518555
};
519556
520557
try {
@@ -529,6 +566,27 @@ export default defineComponent({
529566
}
530567
}
531568
},
569+
570+
getFileDetails() {
571+
let attachmentFilename = "";
572+
let attachmentFilenameExtension = "";
573+
if (this.entry) {
574+
// extract file name
575+
const splittedAttachmentFilename = this.template?.testcase_filename
576+
? this.template.testcase_filename
577+
: this.entry.testcase.split("/");
578+
579+
const attachmentFilenameAndExtension =
580+
splittedAttachmentFilename[
581+
splittedAttachmentFilename?.length - 1
582+
].split(".");
583+
584+
attachmentFilename = attachmentFilenameAndExtension[0];
585+
attachmentFilenameExtension = attachmentFilenameAndExtension[1];
586+
}
587+
588+
return { attachmentFilename, attachmentFilenameExtension };
589+
},
532590
},
533591
});
534592
</script>

server/frontend/src/components/Bugs/PublicationForm.vue

+72-10
Original file line numberDiff line numberDiff line change
@@ -519,12 +519,22 @@
519519
>
520520
<input
521521
id="testcase_filename"
522-
v-model="template.testcase_filename"
522+
v-model="fileName"
523523
name="testcase_filename"
524524
type="text"
525525
class="form-control"
526526
/>
527527
</div>
528+
<div class="col-md-2">
529+
<label for="file_extension">File extension:</label>
530+
<input
531+
id="file_extension"
532+
type="text"
533+
class="form-control"
534+
disabled
535+
:value="fileExtension"
536+
/>
537+
</div>
528538
</div>
529539

530540
<hr />
@@ -543,8 +553,10 @@
543553
:initial-not-attach-test="notAttachTest"
544554
:entry="entry"
545555
:template="template"
556+
:file-extension="fileExtension"
557+
:file-name="fileName"
546558
@update-not-attach-test="notAttachTest = $event"
547-
@update-filename="entry.testcase = $event"
559+
@update-filename="fileName = $event"
548560
@update-content="testCaseContent = $event"
549561
/>
550562

@@ -691,6 +703,8 @@ import {
691703
watch,
692704
} from "vue";
693705
import * as api from "../../api";
706+
707+
import mime from "mime";
694708
import * as bugzillaApi from "../../bugzilla_api";
695709
import * as HandlebarsHelpers from "../../handlebars_helpers";
696710
import { errorParser } from "../../helpers";
@@ -793,11 +807,48 @@ export default defineComponent({
793807
const bugzillaTemplateFieldErrors = ref({});
794808
const bugZillaTemplateError = ref(null);
795809
const formElement = ref(null);
810+
const fileExtension = ref(null);
811+
const fileName = ref(null);
796812
797813
const bugLink = computed(() => {
798814
return `https://${provider.value.hostname}/${createdBugId.value}`;
799815
});
800816
817+
const filenameWithExtension = computed(() => {
818+
return `${fileName.value}.${fileExtension.value}`;
819+
});
820+
821+
watch(() => {
822+
if (entry.value) {
823+
// extract file name
824+
const splittedAttachmentFilename = template.value?.testcase_filename
825+
? template.value.testcase_filename
826+
: entry.value.testcase.split("/");
827+
828+
const attachmentFilenameAndExtension =
829+
splittedAttachmentFilename[
830+
splittedAttachmentFilename?.length - 1
831+
].split(".");
832+
833+
fileName.value = attachmentFilenameAndExtension[0];
834+
fileExtension.value = attachmentFilenameAndExtension[1];
835+
}
836+
});
837+
838+
const fileMimetype = computed(() => {
839+
const mimeType = mime.getType(filenameWithExtension.value);
840+
841+
if (mimeType) {
842+
return mimeType;
843+
}
844+
845+
if (entry.value.testcase_isbinary) {
846+
return "application/octet-stream";
847+
}
848+
849+
return "text/plain";
850+
});
851+
801852
const bugzillaToken = computed(() => {
802853
return localStorage.getItem(
803854
"provider-" + provider.value?.id + "-api-key",
@@ -855,7 +906,7 @@ export default defineComponent({
855906
if (!template.value || !entry.value) return "";
856907
try {
857908
const compiled = Handlebars.compile(template.value.description);
858-
let rendered = compiled({
909+
const renderedData = {
859910
summary: summary.value,
860911
shortsig: entry.value.shortSignature,
861912
product: entry.value.product,
@@ -872,7 +923,15 @@ export default defineComponent({
872923
? "(Crash data not available)"
873924
: "For detailed crash information, see attachment.",
874925
...metadataExtension(template.value.description),
875-
});
926+
};
927+
928+
if (!notAttachTest.value) {
929+
renderedData["testcase_attachment"] = filenameWithExtension.value;
930+
} else {
931+
delete renderedData["testcase_attachment"];
932+
}
933+
934+
let rendered = compiled(renderedData);
876935
877936
// Remove the specified pathPrefix from traces and assertion
878937
if (entryMetadata.value.pathprefix)
@@ -1053,6 +1112,7 @@ export default defineComponent({
10531112
} else {
10541113
const payload = {
10551114
...template.value,
1115+
testcase_filename: filenameWithExtension.value,
10561116
product: product.value,
10571117
component: component.value,
10581118
op_sys: opSys.value,
@@ -1089,9 +1149,9 @@ export default defineComponent({
10891149
payload = {
10901150
ids: [createdBugId.value],
10911151
data: Base64.encode(crashData.value),
1092-
file_name: "crash_data.txt",
1152+
file_name: filenameWithExtension.value,
10931153
summary: "Detailed Crash Information",
1094-
content_type: "text/plain",
1154+
content_type: fileMimetype.value,
10951155
};
10961156
10971157
await bugzillaApi.createAttachment({
@@ -1119,11 +1179,9 @@ export default defineComponent({
11191179
data: entry.value.testcase_isbinary
11201180
? Base64.fromUint8Array(content)
11211181
: Base64.encode(content),
1122-
file_name: entry.value.testcase,
1182+
file_name: filenameWithExtension.value,
11231183
summary: "Testcase",
1124-
content_type: entry.value.testcase_isbinary
1125-
? "application/octet-stream"
1126-
: "text/plain",
1184+
content_type: fileMimetype.value,
11271185
};
11281186
11291187
await bugzillaApi.createAttachment({
@@ -1232,9 +1290,13 @@ export default defineComponent({
12321290
renderedWhiteboard,
12331291
renderedKeywords,
12341292
renderedAttrs,
1293+
filenameWithExtension,
1294+
fileMimetype,
12351295
bugZillaTemplateError,
12361296
bugzillaTemplateFieldErrors,
12371297
formElement,
1298+
fileExtension,
1299+
fileName,
12381300
goBack,
12391301
createExternalBug,
12401302
createOrUpdateBugzillabugTemplate,

0 commit comments

Comments
 (0)