Skip to content

Commit 7f31d5f

Browse files
committed
fix(core/github): edDraftURI opt-out and custom newIssuesURL
Closes #5103 Closes #4317
1 parent a3d08f9 commit 7f31d5f

2 files changed

Lines changed: 71 additions & 2 deletions

File tree

src/core/github.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ const localizationStrings = {
4949
file_a_bug: "Nota un bug",
5050
participate: "Participe:",
5151
},
52+
fr: {
53+
file_a_bug: "Signaler un problème",
54+
participate: "Participer :",
55+
commit_history: "Historique des modifications",
56+
},
5257
de: {
5358
commit_history: "Revisionen",
5459
file_a_bug: "Fehler melden",
@@ -100,7 +105,27 @@ export async function run(conf) {
100105
}
101106
const branch = ghConf.branch || "gh-pages";
102107
const issueBase = new URL("./issues/", ghURL).href;
103-
const newIssuesURL = new URL("./new/choose", issueBase).href;
108+
let newIssuesURL;
109+
if (
110+
typeof conf.github === "object" &&
111+
conf.github.hasOwnProperty("newIssuesURL")
112+
) {
113+
try {
114+
const url = new URL(String(conf.github.newIssuesURL));
115+
if (url.protocol !== "https:") {
116+
const msg = docLink`${"[github.newIssuesURL]"} must use HTTPS. (${String(conf.github.newIssuesURL)}).`;
117+
rejectGithubPromise(msg);
118+
return;
119+
}
120+
newIssuesURL = url.href;
121+
} catch {
122+
const msg = docLink`${"[github.newIssuesURL]"} is not a valid URL. (${String(conf.github.newIssuesURL)}).`;
123+
rejectGithubPromise(msg);
124+
return;
125+
}
126+
} else {
127+
newIssuesURL = new URL("./new/choose", issueBase).href;
128+
}
104129

105130
// Allow custom pullsURL and commitHistoryURL for monorepo scenarios
106131
let pullsURL;
@@ -166,8 +191,8 @@ export async function run(conf) {
166191
}
167192
}
168193

194+
/** @type {Record<string, any>} */
169195
const newProps = {
170-
edDraftURI: `https://${org.toLowerCase()}.github.io/${repo}/`,
171196
githubToken: undefined,
172197
githubUser: undefined,
173198
issueBase,
@@ -176,6 +201,9 @@ export async function run(conf) {
176201
pullBase: pullsURL,
177202
shortName: repo,
178203
};
204+
if (!conf.hasOwnProperty("edDraftURI")) {
205+
newProps.edDraftURI = `https://${org.toLowerCase()}.github.io/${repo}/`;
206+
}
179207
// Assign new properties, but retain existing ones
180208
let githubAPI = "https://respec.org/github";
181209
if (conf.githubAPI) {

tests/spec/core/github-spec.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,47 @@ describe("Core - Github", () => {
8181
const doc = await makeRSDoc(opts);
8282
doesntOverrideTest(doc);
8383
});
84+
it("does not generate edDraftURI when explicitly set to null", async () => {
85+
const opts = {
86+
config: Object.assign(makeBasicConfig(), {
87+
github: "speced/respec",
88+
edDraftURI: null,
89+
}),
90+
body: makeDefaultBody(),
91+
};
92+
const doc = await makeRSDoc(opts);
93+
const { respecConfig: conf } = doc.defaultView;
94+
expect(conf.edDraftURI).toBeNull();
95+
});
96+
it("does not generate edDraftURI when explicitly set to empty string", async () => {
97+
const opts = {
98+
config: Object.assign(makeBasicConfig(), {
99+
github: "speced/respec",
100+
edDraftURI: "",
101+
}),
102+
body: makeDefaultBody(),
103+
};
104+
const doc = await makeRSDoc(opts);
105+
const { respecConfig: conf } = doc.defaultView;
106+
expect(conf.edDraftURI).toBe("");
107+
});
108+
it("supports custom newIssuesURL", async () => {
109+
const opts = {
110+
config: Object.assign(makeBasicConfig(), {
111+
github: {
112+
repoURL: "https://github.com/speced/respec/",
113+
newIssuesURL: "https://github.com/speced/respec/issues/new",
114+
},
115+
}),
116+
body: makeDefaultBody(),
117+
};
118+
delete opts.config.edDraftURI;
119+
const doc = await makeRSDoc(opts);
120+
const { respecConfig: conf } = doc.defaultView;
121+
expect(conf.github.newIssuesURL).toBe(
122+
"https://github.com/speced/respec/issues/new"
123+
);
124+
});
84125
it("normalizes github object with custom pullsURL and commitHistoryURL", async () => {
85126
const opts = {
86127
config: Object.assign(makeBasicConfig(), {

0 commit comments

Comments
 (0)