tl;dr
isomorphic-git の README には、 GitHub の push は cors を認めていないのでブラウザから git push できないとある。サーバー経由でcorsを迂回した。できた。
やり方
- cors-buster を使って無理矢理 cors を迂回する https://cors-buster-tbgktfqyku.now.sh/
- git プロトコルではなく https を使う
remote に cors-buster 経由の github のhttps アドレスを登録する。
こんな感じ
.git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://github.com/mizchi-sandbox/igit-playground.git
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "origin-proxied"]
url = https://cors-buster-tbgktfqyku.now.sh/github.com/mizchi-sandbox/igit-playground
fetch = +refs/heads/*:refs/remotes/origin/*
origin がいつもの。 origin-proxied が今回使う URL
main.js
const git = require("isomorphic-git");
const path = require("path");
const fs = require("fs");
const repo = {
dir: ".",
fs
};
const main = async () => {
console.log("start");
let pushResponse = await git.push({
...repo,
remote: "origin-proxied",
ref: "master",
authUsername: process.env.GITHUB_TOKEN,
authPassword: process.env.GITHUB_TOKEN
});
console.log(pushResponse);
console.log("done");
};
main();
GitHubの Personal Access Token を取ってくる。ググれば出るので略。
GITHUB_TOKEN を与えて実行する
> ~/s/igit-playground on master env GITHUB_TOKEN=<your-toke> node main.js
start
{ ok: [ 'unpack', 'refs/heads/master' ] }
done
できた。
実際に push されたリポジトリがこちら https://github.com/mizchi-sandbox/igit-playground