Skip to content

Commit db54b17

Browse files
committed
Add a feature to retrieve the default branch to the web installer
because GitHub made the breaking change about the default branch. Now we cannot use any fixed branch name for our purpose.
1 parent 780f84b commit db54b17

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

.verify-helper/docs/static/installer.ja.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
1. <form>
1010
<label>競プロライブラリの GitHub のレポジトリの URL を右の textbox に入力: </label>
1111
<input type="text" id="input" placeholder="https://github.com/beet-aizu/library" value="https://github.com/beet-aizu/library" size="48">
12+
(ブランチ: <input type="text" id="input-branch" placeholder="master" value="master" size="12">)
1213
</form>
1314

1415
1. ページ <a id="output" target="_blank"></a> を開き、下の方にある緑の `Commit new file` ボタンを押す

.verify-helper/docs/static/installer.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ data["example.test.cpp"] = (function () {
1313
})();
1414

1515
const input = document.getElementById("input");
16+
const inputBranch = document.getElementById("input-branch");
1617
const output = document.getElementById("output");
1718
const output2 = document.getElementById("output2");
1819
const output3 = document.getElementById("output3");
@@ -27,22 +28,36 @@ const output11 = document.getElementById("output11");
2728
const output12 = document.getElementById("output12");
2829
const output13 = document.getElementById("output13");
2930

30-
function update() {
31+
function retrieveDefaultBranch() {
32+
const found = input.value.match(/\/github.com\/([^\/]+)\/([^\/]+)/);
33+
if (!found) return;
34+
const url = "https://api.github.com/repos/" + found[1] + "/" + found[2];
35+
const req = new XMLHttpRequest();
36+
req.open("GET", url, false);
37+
req.send();
38+
const resp = JSON.parse(req.responseText);
39+
if (resp['default_branch']) {
40+
inputBranch.value = resp['default_branch'];
41+
}
42+
}
43+
44+
function updateLinks() {
3145
const found = input.value.match(/\/github.com\/([^\/]+)\/([^\/]+)/);
3246
if (found) {
3347
const url = input.value.replace(/\/$/, "");
3448
const ghpages = "https://" + found[1] + ".github.io/" + found[2] + "/";
49+
const branch = inputBranch.value;
3550

3651
// adding verify.yml
3752
const filename = ".github%2Fworkflows%2Fverify.yml"
3853
const value = encodeURIComponent(data["verify.yml"].replace("git+https://github.com/online-judge-tools/verification-helper.git@master", "online-judge-verify-helper"));
39-
output.href = url + "/new/master?filename=" + filename + "&value=" + value;
54+
output.href = url + "/new/" + branch + "?filename=" + filename + "&value=" + value;
4055
output.textContent = url + "&value=...";
4156

4257
// adding example.text.cpp
4358
const filename2 = "example.test.cpp";
4459
const value2 = encodeURIComponent(data["example.test.cpp"]);
45-
output2.href = url + "/new/master?filename=" + filename2 + "&value=" + value2;
60+
output2.href = url + "/new/" + branch + "?filename=" + filename2 + "&value=" + value2;
4661

4762
// links to GitHub Actions
4863
output3.href = input.value.replace(/\/$/, "") + "/actions";
@@ -66,6 +81,14 @@ function update() {
6681
output13.href = url + "/commits/gh-pages";
6782
}
6883
}
84+
85+
function update() {
86+
retrieveDefaultBranch();
87+
updateLinks();
88+
}
89+
6990
input.addEventListener('change', update);
7091
input.addEventListener('keyup', update);
71-
update();
92+
inputBranch.addEventListener('change', updateLinks);
93+
inputBranch.addEventListener('keyup', updateLinks);
94+
updateLinks();

.verify-helper/docs/static/installer.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Steps:
99
1. <form>
1010
<label>Input the URL of the library repository in the textbox on the right: </label>
1111
<input type="text" id="input" placeholder="https://github.com/beet-aizu/library" value="https://github.com/beet-aizu/library" size="48">
12+
(branch: <input type="text" id="input-branch" placeholder="master" value="master" size="12">)
1213
</form>
1314

1415
1. Open <a id="output" target="_blank"></a> and click the green `Commit new file` button.

0 commit comments

Comments
 (0)