Skip to content

Commit e73bc46

Browse files
author
gitstart_bot
committed
chore: preserve file name and mime type on non testcase attachment
1 parent ac0a9b9 commit e73bc46

File tree

5 files changed

+187
-27
lines changed

5 files changed

+187
-27
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

+66-7
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@
124124
:initial-not-attach-test="notAttachTest"
125125
:entry="entry"
126126
:template="template"
127+
:file-extension="fileExtension"
128+
:file-name="fileName"
127129
@update-not-attach-test="notAttachTest = $event"
128-
@update-filename="entry.testcase = $event"
130+
@update-filename="newFileName = $event"
129131
@update-content="testCaseContent = $event"
130132
/>
131133

@@ -227,6 +229,7 @@
227229
<script>
228230
import Handlebars from "handlebars";
229231
import { Base64 } from "js-base64";
232+
import mime from "mime";
230233
import { defineComponent } from "vue";
231234
import * as api from "../../../api";
232235
import * as bugzillaApi from "../../../bugzilla_api";
@@ -289,6 +292,7 @@ export default defineComponent({
289292
testCaseContent: "",
290293
notAttachData: false,
291294
crashData: "",
295+
newFileName: null,
292296
};
293297
},
294298
@@ -342,7 +346,7 @@ export default defineComponent({
342346
if (!this.template || !this.entry) return "";
343347
try {
344348
const compiled = Handlebars.compile(this.template.comment);
345-
let rendered = compiled({
349+
const renderedData = {
346350
summary: this.summary,
347351
shortsig: this.entry.shortSignature,
348352
product: this.entry.product,
@@ -359,7 +363,15 @@ export default defineComponent({
359363
? "(Crash data not available)"
360364
: "For detailed crash information, see attachment.",
361365
...this.metadataExtension(this.template.comment),
362-
});
366+
};
367+
368+
if (!this.notAttachTest) {
369+
renderedData["testcase_attachment"] = this.filenameWithExtension;
370+
} else {
371+
delete renderedData["testcase_attachment"];
372+
}
373+
374+
let rendered = compiled(renderedData);
363375
364376
// Remove the specified pathPrefix from traces and assertion
365377
if (this.entryMetadata.pathprefix) {
@@ -371,6 +383,32 @@ export default defineComponent({
371383
return "";
372384
}
373385
},
386+
fileName() {
387+
const { attachmentFilename } = this.getFileDetails();
388+
389+
return this.newFileName ?? attachmentFilename;
390+
},
391+
fileExtension() {
392+
const { attachmentFilenameExtension } = this.getFileDetails();
393+
394+
return attachmentFilenameExtension;
395+
},
396+
filenameWithExtension() {
397+
return this.fileName + "." + this.fileExtension;
398+
},
399+
fileMimetype() {
400+
const mimeType = mime.getType(this.filenameWithExtension);
401+
402+
if (mimeType) {
403+
return mimeType;
404+
}
405+
406+
if (this.entry.testcase_isbinary) {
407+
return "application/octet-stream";
408+
}
409+
410+
return "text/plain";
411+
},
374412
},
375413
376414
watch: {
@@ -440,6 +478,8 @@ export default defineComponent({
440478
is_private: this.isPrivate,
441479
};
442480
481+
await this.publishAttachments();
482+
443483
try {
444484
let data = await bugzillaApi.createComment({
445485
hostname: this.provider.hostname,
@@ -510,11 +550,9 @@ export default defineComponent({
510550
data: this.entry.testcase_isbinary
511551
? Base64.fromUint8Array(content)
512552
: Base64.encode(content),
513-
file_name: this.entry.testcase,
553+
file_name: this.filenameWithExtension,
514554
summary: `Testcase for ${comment}`,
515-
content_type: this.entry.testcase_isbinary
516-
? "application/octet-stream"
517-
: "text/plain",
555+
content_type: this.fileMimetype,
518556
};
519557
520558
try {
@@ -529,6 +567,27 @@ export default defineComponent({
529567
}
530568
}
531569
},
570+
571+
getFileDetails() {
572+
let attachmentFilename = "";
573+
let attachmentFilenameExtension = "";
574+
if (this.entry) {
575+
// extract file name
576+
const splittedAttachmentFilename = this.template?.testcase_filename
577+
? this.template.testcase_filename
578+
: this.entry.testcase.split("/");
579+
580+
const attachmentFilenameAndExtension =
581+
splittedAttachmentFilename[
582+
splittedAttachmentFilename?.length - 1
583+
].split(".");
584+
585+
attachmentFilename = attachmentFilenameAndExtension[0];
586+
attachmentFilenameExtension = attachmentFilenameAndExtension[1];
587+
}
588+
589+
return { attachmentFilename, attachmentFilenameExtension };
590+
},
532591
},
533592
});
534593
</script>

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

+72-10
Original file line numberDiff line numberDiff line change
@@ -521,12 +521,22 @@
521521
>
522522
<input
523523
id="testcase_filename"
524-
v-model="template.testcase_filename"
524+
v-model="fileName"
525525
name="testcase_filename"
526526
type="text"
527527
class="form-control"
528528
/>
529529
</div>
530+
<div class="col-md-2">
531+
<label for="file_extension">File extension:</label>
532+
<input
533+
id="file_extension"
534+
type="text"
535+
class="form-control"
536+
disabled
537+
:value="fileExtension"
538+
/>
539+
</div>
530540
</div>
531541

532542
<hr />
@@ -545,8 +555,10 @@
545555
:initial-not-attach-test="notAttachTest"
546556
:entry="entry"
547557
:template="template"
558+
:file-extension="fileExtension"
559+
:file-name="fileName"
548560
@update-not-attach-test="notAttachTest = $event"
549-
@update-filename="entry.testcase = $event"
561+
@update-filename="fileName = $event"
550562
@update-content="testCaseContent = $event"
551563
/>
552564

@@ -693,6 +705,8 @@ import {
693705
watch,
694706
} from "vue";
695707
import * as api from "../../api";
708+
709+
import mime from "mime";
696710
import * as bugzillaApi from "../../bugzilla_api";
697711
import * as HandlebarsHelpers from "../../handlebars_helpers";
698712
import { errorParser } from "../../helpers";
@@ -797,12 +811,49 @@ export default defineComponent({
797811
fields: {},
798812
server: null,
799813
});
814+
const fileExtension = ref(null);
815+
const fileName = ref(null);
800816
const formElement = ref(null);
801817
802818
const bugLink = computed(() => {
803819
return `https://${provider.value.hostname}/${createdBugId.value}`;
804820
});
805821
822+
const filenameWithExtension = computed(() => {
823+
return `${fileName.value}.${fileExtension.value}`;
824+
});
825+
826+
watch(() => {
827+
if (entry.value) {
828+
// extract file name
829+
const splittedAttachmentFilename = template.value?.testcase_filename
830+
? template.value.testcase_filename
831+
: entry.value.testcase.split("/");
832+
833+
const attachmentFilenameAndExtension =
834+
splittedAttachmentFilename[
835+
splittedAttachmentFilename?.length - 1
836+
].split(".");
837+
838+
fileName.value = attachmentFilenameAndExtension[0];
839+
fileExtension.value = attachmentFilenameAndExtension[1];
840+
}
841+
});
842+
843+
const fileMimetype = computed(() => {
844+
const mimeType = mime.getType(filenameWithExtension.value);
845+
846+
if (mimeType) {
847+
return mimeType;
848+
}
849+
850+
if (entry.value.testcase_isbinary) {
851+
return "application/octet-stream";
852+
}
853+
854+
return "text/plain";
855+
});
856+
806857
const bugzillaToken = computed(() => {
807858
return localStorage.getItem(
808859
"provider-" + provider.value?.id + "-api-key",
@@ -860,7 +911,7 @@ export default defineComponent({
860911
if (!template.value || !entry.value) return "";
861912
try {
862913
const compiled = Handlebars.compile(template.value.description);
863-
let rendered = compiled({
914+
const renderedData = {
864915
summary: summary.value,
865916
shortsig: entry.value.shortSignature,
866917
product: entry.value.product,
@@ -877,7 +928,15 @@ export default defineComponent({
877928
? "(Crash data not available)"
878929
: "For detailed crash information, see attachment.",
879930
...metadataExtension(template.value.description),
880-
});
931+
};
932+
933+
if (!notAttachTest.value) {
934+
renderedData["testcase_attachment"] = filenameWithExtension.value;
935+
} else {
936+
delete renderedData["testcase_attachment"];
937+
}
938+
939+
let rendered = compiled(renderedData);
881940
882941
// Remove the specified pathPrefix from traces and assertion
883942
if (entryMetadata.value.pathprefix)
@@ -1071,6 +1130,7 @@ export default defineComponent({
10711130
10721131
const payload = {
10731132
...template.value,
1133+
testcase_filename: filenameWithExtension.value,
10741134
product: product.value,
10751135
component: component.value,
10761136
op_sys: opSys.value,
@@ -1105,9 +1165,9 @@ export default defineComponent({
11051165
payload = {
11061166
ids: [createdBugId.value],
11071167
data: Base64.encode(crashData.value),
1108-
file_name: "crash_data.txt",
1168+
file_name: filenameWithExtension.value,
11091169
summary: "Detailed Crash Information",
1110-
content_type: "text/plain",
1170+
content_type: fileMimetype.value,
11111171
};
11121172
11131173
await bugzillaApi.createAttachment({
@@ -1135,11 +1195,9 @@ export default defineComponent({
11351195
data: entry.value.testcase_isbinary
11361196
? Base64.fromUint8Array(content)
11371197
: Base64.encode(content),
1138-
file_name: entry.value.testcase,
1198+
file_name: "crash_data.txt",
11391199
summary: "Testcase",
1140-
content_type: entry.value.testcase_isbinary
1141-
? "application/octet-stream"
1142-
: "text/plain",
1200+
content_type: "text/plain",
11431201
};
11441202
11451203
await bugzillaApi.createAttachment({
@@ -1285,6 +1343,10 @@ export default defineComponent({
12851343
goBack,
12861344
createExternalBug,
12871345
createOrUpdateBugzillaBugTemplate,
1346+
filenameWithExtension,
1347+
fileMimetype,
1348+
fileExtension,
1349+
fileName,
12881350
};
12891351
},
12901352
});

0 commit comments

Comments
 (0)