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

Bring back pasted log files in bug reports #2502

Merged
merged 1 commit into from
Mar 16, 2022
Merged
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
1 change: 1 addition & 0 deletions __mocks__/axios.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const axios = {
get: jest.fn().mockResolvedValue(),
post: jest.fn().mockResolvedValue(),
create: jest.fn()
};

Expand Down
53 changes: 53 additions & 0 deletions src/lib/paste.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"use strict";

/*
* Copyright (C) 2022 UBports Foundation <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

const axios = require("axios");

/**
* paste stuff
*/
class Paste {
/**
* send paste
* @async
* @returns {String} url of the paste
*/
async paste(logfile) {
return axios
.post(
"https://snip.hxrsh.in/api/snip/new",
{
content: await logfile,
slug: `ubi-${new Date().getTime()}`,
language: "text"
},
{
headers: {
"Content-Type": "application/json"
}
}
)
.then(({ data }) =>
data.slug ? `https://snip.hxrsh.in/${data.slug}` : null
)
.catch(() => null);
}
}

module.exports = new Paste();
24 changes: 24 additions & 0 deletions src/lib/paste.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
process.argv = [null, null, "-vv"];
const axios = require("axios");
jest.mock("axios");
axios.create.mockReturnValue(axios);
const { paste } = require("./paste.js");

it("should be a singleton", () => {
expect(require("./paste.js")).toBe(require("./paste.js"));
});

describe("paste()", () => {
it("should return paste url", () => {
axios.post.mockResolvedValueOnce({ data: { slug: "asdf" } });
expect(paste()).resolves.toBe("https://snip.hxrsh.in/asdf");
});
it("should return null if slug missing", () => {
axios.post.mockResolvedValueOnce({ data: {} });
expect(paste()).resolves.toBe(null);
});
it("should return null on error", () => {
axios.post.mockRejectedValueOnce();
expect(paste()).resolves.toBe(null);
});
});
18 changes: 11 additions & 7 deletions src/lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const { OpenCutsReporter } = require("open-cuts-reporter");
const settings = require("./settings.js");
const core = require("../core/core.js");
const { prompt } = require("./prompt.js");
const { paste } = require("./paste.js");

/**
* OPEN-CUTS operating system mapping
Expand All @@ -37,6 +38,9 @@ const OPENCUTS_OS = {
win32: "Windows"
};

const MISSING_LOG =
"*N/A* <!-- Uploading logs failed. Please add them manually: https://github.com/ubports/ubports-installer#logs -->";

/**
* report errors or successes
*/
Expand Down Expand Up @@ -117,9 +121,10 @@ class Reporter {
* @async
* @param {Object} data - form data
* @param {String} runUrl - OPEN-CUTS run URL
* @param {String} logUrl - pastbin URL
* @returns {String} url-encoded string to create a GitHub issue
*/
async getDebugInfo(data, runUrl) {
async getDebugInfo(data, runUrl, logUrl) {
return encodeURIComponent(
[
`**UBports Installer \`${packageInfo.version}\` (${data.package})**`,
Expand All @@ -132,7 +137,8 @@ class Reporter {
]),
`Target OS: ${this.getTargetOsString()}`,
`Settings: \`${this.getSettingsString()}\``,
`OPEN-CUTS run: ${runUrl}`,
`OPEN-CUTS run: ${runUrl || MISSING_LOG}`,
`Pastebin: ${logUrl || MISSING_LOG}`,
"\n",
data.comment,
"\n",
Expand Down Expand Up @@ -162,14 +168,12 @@ class Reporter {
*/
async sendBugReport(data, token) {
const logfile = await log.get();
const runUrl = this.sendOpenCutsRun(token, data, logfile).catch(
() =>
"*N/A* <!-- Uploading logs failed. Please add them manually: https://github.com/ubports/ubports-installer#logs -->"
);
const runUrl = this.sendOpenCutsRun(token, data, logfile).catch(() => null);
const logUrl = paste(logfile);
shell.openExternal(
`https://github.com/ubports/ubports-installer/issues/new?title=${encodeURIComponent(
data.title
)}&body=${await this.getDebugInfo(data, await runUrl)}`
)}&body=${await this.getDebugInfo(data, await runUrl, await logUrl)}`
NeoTheThird marked this conversation as resolved.
Show resolved Hide resolved
);
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/reporter.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
process.argv = [null, null, "-vv"];
const log = require("./log.js");
jest.mock("./log.js");
const { paste } = require("./paste.js");
jest.mock("./paste.js");
const settings = require("./settings.js");
const { prompt } = require("./prompt.js");
jest.mock("./prompt.js");
Expand Down