Skip to content

Commit

Permalink
Merge pull request #354 from online-judge-tools/fix/master-main
Browse files Browse the repository at this point in the history
Add a feature to retrieve the default branch to the web installer
  • Loading branch information
kmyk committed Dec 16, 2020
2 parents 780f84b + db54b17 commit 499f3d1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions .verify-helper/docs/static/installer.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
1. <form>
<label>競プロライブラリの GitHub のレポジトリの URL を右の textbox に入力: </label>
<input type="text" id="input" placeholder="https://github.com/beet-aizu/library" value="https://github.com/beet-aizu/library" size="48">
(ブランチ: <input type="text" id="input-branch" placeholder="master" value="master" size="12">)
</form>

1. ページ <a id="output" target="_blank"></a> を開き、下の方にある緑の `Commit new file` ボタンを押す
Expand Down
31 changes: 27 additions & 4 deletions .verify-helper/docs/static/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data["example.test.cpp"] = (function () {
})();

const input = document.getElementById("input");
const inputBranch = document.getElementById("input-branch");
const output = document.getElementById("output");
const output2 = document.getElementById("output2");
const output3 = document.getElementById("output3");
Expand All @@ -27,22 +28,36 @@ const output11 = document.getElementById("output11");
const output12 = document.getElementById("output12");
const output13 = document.getElementById("output13");

function update() {
function retrieveDefaultBranch() {
const found = input.value.match(/\/github.com\/([^\/]+)\/([^\/]+)/);
if (!found) return;
const url = "https://api.github.com/repos/" + found[1] + "/" + found[2];
const req = new XMLHttpRequest();
req.open("GET", url, false);
req.send();
const resp = JSON.parse(req.responseText);
if (resp['default_branch']) {
inputBranch.value = resp['default_branch'];
}
}

function updateLinks() {
const found = input.value.match(/\/github.com\/([^\/]+)\/([^\/]+)/);
if (found) {
const url = input.value.replace(/\/$/, "");
const ghpages = "https://" + found[1] + ".github.io/" + found[2] + "/";
const branch = inputBranch.value;

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

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

// links to GitHub Actions
output3.href = input.value.replace(/\/$/, "") + "/actions";
Expand All @@ -66,6 +81,14 @@ function update() {
output13.href = url + "/commits/gh-pages";
}
}

function update() {
retrieveDefaultBranch();
updateLinks();
}

input.addEventListener('change', update);
input.addEventListener('keyup', update);
update();
inputBranch.addEventListener('change', updateLinks);
inputBranch.addEventListener('keyup', updateLinks);
updateLinks();
1 change: 1 addition & 0 deletions .verify-helper/docs/static/installer.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Steps:
1. <form>
<label>Input the URL of the library repository in the textbox on the right: </label>
<input type="text" id="input" placeholder="https://github.com/beet-aizu/library" value="https://github.com/beet-aizu/library" size="48">
(branch: <input type="text" id="input-branch" placeholder="master" value="master" size="12">)
</form>

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

0 comments on commit 499f3d1

Please sign in to comment.