Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FUZ-19A - Improve testcase handling in Bugzilla Template #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions server/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"handlebars": "^4.7.8",
"js-base64": "^3.7.7",
"lodash": "^4.17.21",
"mime": "^4.0.6",
"prismjs": "^1.29.0",
"sweetalert": "^2.1.2",
"vue": "^3.4.21",
Expand Down
71 changes: 64 additions & 7 deletions server/frontend/src/components/Bugs/Comments/PublicationForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@
:initial-not-attach-test="notAttachTest"
:entry="entry"
:template="template"
:file-extension="fileExtension"
:file-name="fileName"
@update-not-attach-test="notAttachTest = $event"
@update-filename="entry.testcase = $event"
@update-filename="newFileName = $event"
@update-content="testCaseContent = $event"
/>

Expand Down Expand Up @@ -227,6 +229,7 @@
<script>
import Handlebars from "handlebars";
import { Base64 } from "js-base64";
import mime from "mime";
import { defineComponent } from "vue";
import * as api from "../../../api";
import * as bugzillaApi from "../../../bugzilla_api";
Expand Down Expand Up @@ -289,6 +292,7 @@ export default defineComponent({
testCaseContent: "",
notAttachData: false,
crashData: "",
newFileName: null,
};
},

Expand Down Expand Up @@ -342,7 +346,7 @@ export default defineComponent({
if (!this.template || !this.entry) return "";
try {
const compiled = Handlebars.compile(this.template.comment);
let rendered = compiled({
const renderedData = {
summary: this.summary,
shortsig: this.entry.shortSignature,
product: this.entry.product,
Expand All @@ -359,7 +363,15 @@ export default defineComponent({
? "(Crash data not available)"
: "For detailed crash information, see attachment.",
...this.metadataExtension(this.template.comment),
});
};

if (!this.notAttachTest) {
renderedData["testcase_attachment"] = this.filenameWithExtension;
} else {
delete renderedData["testcase_attachment"];
}

let rendered = compiled(renderedData);

// Remove the specified pathPrefix from traces and assertion
if (this.entryMetadata.pathprefix) {
Expand All @@ -371,6 +383,32 @@ export default defineComponent({
return "";
}
},
fileName() {
const { attachmentFilename } = this.getFileDetails();

return this.newFileName ?? attachmentFilename;
},
fileExtension() {
const { attachmentFilenameExtension } = this.getFileDetails();

return attachmentFilenameExtension;
},
filenameWithExtension() {
return this.fileName + "." + this.fileExtension;
},
fileMimetype() {
const mimeType = mime.getType(this.filenameWithExtension);

if (mimeType) {
return mimeType;
}

if (this.entry.testcase_isbinary) {
return "application/octet-stream";
}

return "text/plain";
},
},

watch: {
Expand Down Expand Up @@ -510,11 +548,9 @@ export default defineComponent({
data: this.entry.testcase_isbinary
? Base64.fromUint8Array(content)
: Base64.encode(content),
file_name: this.entry.testcase,
file_name: this.filenameWithExtension,
summary: `Testcase for ${comment}`,
content_type: this.entry.testcase_isbinary
? "application/octet-stream"
: "text/plain",
content_type: this.fileMimetype,
};

try {
Expand All @@ -529,6 +565,27 @@ export default defineComponent({
}
}
},

getFileDetails() {
let attachmentFilename = "";
let attachmentFilenameExtension = "";
if (this.entry) {
// extract file name
const splittedAttachmentFilename = this.template?.testcase_filename
? this.template.testcase_filename
: this.entry.testcase.split("/");

const attachmentFilenameAndExtension =
splittedAttachmentFilename[
splittedAttachmentFilename?.length - 1
].split(".");

attachmentFilename = attachmentFilenameAndExtension[0];
attachmentFilenameExtension = attachmentFilenameAndExtension[1];
}

return { attachmentFilename, attachmentFilenameExtension };
},
},
});
</script>
Expand Down
78 changes: 70 additions & 8 deletions server/frontend/src/components/Bugs/PublicationForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,22 @@
>
<input
id="testcase_filename"
v-model="template.testcase_filename"
v-model="fileName"
name="testcase_filename"
type="text"
class="form-control"
/>
</div>
<div class="col-md-2">
<label for="file_extension">File extension:</label>
<input
id="file_extension"
type="text"
class="form-control"
disabled
:value="fileExtension"
/>
</div>
</div>

<hr />
Expand All @@ -545,8 +555,10 @@
:initial-not-attach-test="notAttachTest"
:entry="entry"
:template="template"
:file-extension="fileExtension"
:file-name="fileName"
@update-not-attach-test="notAttachTest = $event"
@update-filename="entry.testcase = $event"
@update-filename="fileName = $event"
@update-content="testCaseContent = $event"
/>

Expand Down Expand Up @@ -693,6 +705,8 @@ import {
watch,
} from "vue";
import * as api from "../../api";

import mime from "mime";
import * as bugzillaApi from "../../bugzilla_api";
import * as HandlebarsHelpers from "../../handlebars_helpers";
import { errorParser } from "../../helpers";
Expand Down Expand Up @@ -797,12 +811,49 @@ export default defineComponent({
fields: {},
server: null,
});
const fileExtension = ref(null);
const fileName = ref(null);
const formElement = ref(null);

const bugLink = computed(() => {
return `https://${provider.value.hostname}/${createdBugId.value}`;
});

const filenameWithExtension = computed(() => {
return `${fileName.value}.${fileExtension.value}`;
});

watch(() => {
if (entry.value) {
// extract file name
const splittedAttachmentFilename = template.value?.testcase_filename
? template.value.testcase_filename
: entry.value.testcase.split("/");

const attachmentFilenameAndExtension =
splittedAttachmentFilename[
splittedAttachmentFilename?.length - 1
].split(".");

fileName.value = attachmentFilenameAndExtension[0];
fileExtension.value = attachmentFilenameAndExtension[1];
}
});

const fileMimetype = computed(() => {
const mimeType = mime.getType(filenameWithExtension.value);

if (mimeType) {
return mimeType;
}

if (entry.value.testcase_isbinary) {
return "application/octet-stream";
}

return "text/plain";
});

const bugzillaToken = computed(() => {
return localStorage.getItem(
"provider-" + provider.value?.id + "-api-key",
Expand Down Expand Up @@ -860,7 +911,7 @@ export default defineComponent({
if (!template.value || !entry.value) return "";
try {
const compiled = Handlebars.compile(template.value.description);
let rendered = compiled({
const renderedData = {
summary: summary.value,
shortsig: entry.value.shortSignature,
product: entry.value.product,
Expand All @@ -877,7 +928,15 @@ export default defineComponent({
? "(Crash data not available)"
: "For detailed crash information, see attachment.",
...metadataExtension(template.value.description),
});
};

if (!notAttachTest.value) {
renderedData["testcase_attachment"] = filenameWithExtension.value;
} else {
delete renderedData["testcase_attachment"];
}

let rendered = compiled(renderedData);

// Remove the specified pathPrefix from traces and assertion
if (entryMetadata.value.pathprefix)
Expand Down Expand Up @@ -1071,6 +1130,7 @@ export default defineComponent({

const payload = {
...template.value,
testcase_filename: filenameWithExtension.value,
product: product.value,
component: component.value,
op_sys: opSys.value,
Expand Down Expand Up @@ -1135,11 +1195,9 @@ export default defineComponent({
data: entry.value.testcase_isbinary
? Base64.fromUint8Array(content)
: Base64.encode(content),
file_name: entry.value.testcase,
file_name: filenameWithExtension.value,
summary: "Testcase",
content_type: entry.value.testcase_isbinary
? "application/octet-stream"
: "text/plain",
content_type: fileMimetype.value,
};

await bugzillaApi.createAttachment({
Expand Down Expand Up @@ -1285,6 +1343,10 @@ export default defineComponent({
goBack,
createExternalBug,
createOrUpdateBugzillaBugTemplate,
filenameWithExtension,
fileMimetype,
fileExtension,
fileName,
};
},
});
Expand Down
Loading