mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-05-02 05:20:18 +00:00
165 lines
4.1 KiB
JavaScript
165 lines
4.1 KiB
JavaScript
const test = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
|
|
const triage = require("./issue-version-triage.cjs");
|
|
|
|
function createGithub({
|
|
latestVersion = "6.0.1",
|
|
existingLabels = new Set(),
|
|
existingComments = [],
|
|
} = {}) {
|
|
const calls = {
|
|
createComment: [],
|
|
createLabel: [],
|
|
getLabel: [],
|
|
getLatestRelease: [],
|
|
paginate: [],
|
|
setLabels: [],
|
|
};
|
|
|
|
const github = {
|
|
rest: {
|
|
issues: {
|
|
async getLabel({ name }) {
|
|
calls.getLabel.push(name);
|
|
if (existingLabels.has(name)) {
|
|
return { data: { name } };
|
|
}
|
|
const error = new Error("Not Found");
|
|
error.status = 404;
|
|
throw error;
|
|
},
|
|
async createLabel(payload) {
|
|
calls.createLabel.push(payload);
|
|
existingLabels.add(payload.name);
|
|
return { data: payload };
|
|
},
|
|
async setLabels(payload) {
|
|
calls.setLabels.push(payload);
|
|
return { data: payload };
|
|
},
|
|
async createComment(payload) {
|
|
calls.createComment.push(payload);
|
|
return { data: payload };
|
|
},
|
|
listComments: Symbol("listComments"),
|
|
},
|
|
repos: {
|
|
async getLatestRelease() {
|
|
calls.getLatestRelease.push(true);
|
|
return { data: { tag_name: `v${latestVersion}` } };
|
|
},
|
|
},
|
|
},
|
|
async paginate() {
|
|
calls.paginate.push(true);
|
|
return existingComments;
|
|
},
|
|
};
|
|
|
|
return { github, calls };
|
|
}
|
|
|
|
function createContext({ action = "opened", issue }) {
|
|
return {
|
|
payload: {
|
|
action,
|
|
issue,
|
|
},
|
|
repo: {
|
|
owner: "rcourtman",
|
|
repo: "Pulse",
|
|
},
|
|
};
|
|
}
|
|
|
|
function createCore() {
|
|
return {
|
|
info() {},
|
|
warning() {},
|
|
};
|
|
}
|
|
|
|
test("syncLabels adds affects and retest labels for older bug reports", async () => {
|
|
const { github, calls } = createGithub({ latestVersion: "6.0.1" });
|
|
const issue = {
|
|
number: 1402,
|
|
title: "Standalone hosts disappear after upgrade",
|
|
body: "## Feedback type\nBug / regression\n\n## Pulse version\n6.0.0-rc.1\n",
|
|
labels: [],
|
|
};
|
|
|
|
await triage.syncLabels({
|
|
github,
|
|
context: createContext({ issue }),
|
|
core: createCore(),
|
|
});
|
|
|
|
assert.equal(calls.setLabels.length, 1);
|
|
assert.deepEqual(calls.setLabels[0].labels, [
|
|
"affects-6.0.0-rc.1",
|
|
"bug",
|
|
"needs-retest-on-latest",
|
|
]);
|
|
});
|
|
|
|
test("syncLabels only adds documentation classification for non-bug v6 feedback", async () => {
|
|
const { github, calls } = createGithub({ latestVersion: "6.0.1" });
|
|
const issue = {
|
|
number: 1415,
|
|
title: "Docs path is wrong",
|
|
body: "## Feedback type\nDocumentation issue\n\n## Pulse version\n6.0.0-rc.1\n",
|
|
labels: [],
|
|
};
|
|
|
|
await triage.syncLabels({
|
|
github,
|
|
context: createContext({ issue }),
|
|
core: createCore(),
|
|
});
|
|
|
|
assert.equal(calls.setLabels.length, 1);
|
|
assert.deepEqual(calls.setLabels[0].labels, ["documentation"]);
|
|
});
|
|
|
|
test("postRetestComment comments once for older non-maintainer bug reports", async () => {
|
|
const { github, calls } = createGithub({ latestVersion: "6.0.1" });
|
|
const issue = {
|
|
number: 1200,
|
|
title: "Upgrade regression",
|
|
body: "## Feedback type\nRegression\n\n## Pulse version\n5.1.9\n",
|
|
labels: [],
|
|
author_association: "NONE",
|
|
};
|
|
|
|
await triage.postRetestComment({
|
|
github,
|
|
context: createContext({ action: "opened", issue }),
|
|
core: createCore(),
|
|
});
|
|
|
|
assert.equal(calls.createComment.length, 1);
|
|
assert.match(
|
|
calls.createComment[0].body,
|
|
/<!-- issue-version-triage:v1 -->/
|
|
);
|
|
});
|
|
|
|
test("postRetestComment skips maintainer-authored issues", async () => {
|
|
const { github, calls } = createGithub({ latestVersion: "6.0.1" });
|
|
const issue = {
|
|
number: 1300,
|
|
title: "Maintainer split issue on 5.1.9",
|
|
body: "## Feedback type\nBug / regression\n\n## Pulse version\n5.1.9\n",
|
|
labels: [],
|
|
author_association: "OWNER",
|
|
};
|
|
|
|
await triage.postRetestComment({
|
|
github,
|
|
context: createContext({ action: "opened", issue }),
|
|
core: createCore(),
|
|
});
|
|
|
|
assert.equal(calls.createComment.length, 0);
|
|
});
|