Skip to content
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
32 changes: 30 additions & 2 deletions src/core/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ const localizationStrings = {
file_a_bug: "Nota un bug",
participate: "Participe:",
},
fr: {
file_a_bug: "Signaler un problème",
participate: "Participer :",
commit_history: "Historique des modifications",
},
de: {
commit_history: "Revisionen",
file_a_bug: "Fehler melden",
Expand Down Expand Up @@ -100,7 +105,27 @@ export async function run(conf) {
}
const branch = ghConf.branch || "gh-pages";
const issueBase = new URL("./issues/", ghURL).href;
const newIssuesURL = new URL("./new/choose", issueBase).href;
let newIssuesURL;
if (
typeof conf.github === "object" &&
conf.github.hasOwnProperty("newIssuesURL")
) {
try {
const url = new URL(String(conf.github.newIssuesURL));
if (url.protocol !== "https:") {
const msg = docLink`${"[github.newIssuesURL]"} must use HTTPS. (${String(conf.github.newIssuesURL)}).`;
rejectGithubPromise(msg);
return;
}
newIssuesURL = url.href;
Comment thread
marcoscaceres marked this conversation as resolved.
} catch {
const msg = docLink`${"[github.newIssuesURL]"} is not a valid URL. (${String(conf.github.newIssuesURL)}).`;
rejectGithubPromise(msg);
return;
}
} else {
newIssuesURL = new URL("./new/choose", issueBase).href;
}

// Allow custom pullsURL and commitHistoryURL for monorepo scenarios
let pullsURL;
Expand Down Expand Up @@ -166,8 +191,8 @@ export async function run(conf) {
}
}

/** @type {Record<string, any>} */
const newProps = {
edDraftURI: `https://${org.toLowerCase()}.github.io/${repo}/`,
githubToken: undefined,
githubUser: undefined,
issueBase,
Expand All @@ -176,6 +201,9 @@ export async function run(conf) {
pullBase: pullsURL,
shortName: repo,
};
if (!conf.hasOwnProperty("edDraftURI")) {
newProps.edDraftURI = `https://${org.toLowerCase()}.github.io/${repo}/`;
Comment thread
marcoscaceres marked this conversation as resolved.
}
// Assign new properties, but retain existing ones
let githubAPI = "https://respec.org/github";
if (conf.githubAPI) {
Expand Down
50 changes: 50 additions & 0 deletions tests/spec/core/github-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,56 @@ describe("Core - Github", () => {
const doc = await makeRSDoc(opts);
doesntOverrideTest(doc);
});
it("does not generate edDraftURI when explicitly set to null", async () => {
const opts = {
config: Object.assign(makeBasicConfig(), {
github: "speced/respec",
edDraftURI: null,
}),
body: makeDefaultBody(),
};
const doc = await makeRSDoc(opts);
const { respecConfig: conf } = doc.defaultView;
expect(conf.edDraftURI).toBeNull();
});
it("does not generate edDraftURI when explicitly set to empty string", async () => {
const opts = {
config: Object.assign(makeBasicConfig(), {
github: "speced/respec",
edDraftURI: "",
}),
body: makeDefaultBody(),
};
const doc = await makeRSDoc(opts);
const { respecConfig: conf } = doc.defaultView;
expect(conf.edDraftURI).toBe("");
});
it("supports custom newIssuesURL", async () => {
const opts = {
config: Object.assign(makeBasicConfig(), {
github: {
repoURL: "https://github.com/speced/respec/",
newIssuesURL: "https://github.com/speced/respec/issues/new",
},
excludeGithubLinks: false,
}),
body: makeDefaultBody(),
};
delete opts.config.edDraftURI;
const doc = await makeRSDoc(opts);
const { respecConfig: conf } = doc.defaultView;
expect(conf.github.newIssuesURL).toBe(
"https://github.com/speced/respec/issues/new"
);
Comment thread
marcoscaceres marked this conversation as resolved.
// Also verify the rendered feedback link in the DOM uses the custom URL
const fileABug = Array.from(doc.querySelectorAll("dd")).find(
elem => elem.textContent.trim() === "File an issue"
);
expect(fileABug).toBeTruthy();
expect(fileABug.querySelector("a").href).toBe(
"https://github.com/speced/respec/issues/new"
);
});
it("normalizes github object with custom pullsURL and commitHistoryURL", async () => {
const opts = {
config: Object.assign(makeBasicConfig(), {
Expand Down
Loading