| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,44 @@ | |||
| 1 | + var nodegit = require("../"); | ||
| 2 | + var promisify = require("promisify-node"); | ||
| 3 | + var fse = promisify(require("fs-extra")); | ||
| 4 | + var path = "/tmp/nodegit-github-2factor-demo"; | ||
| 5 | + | ||
| 6 | + var token = "{Your GitHub user token}"; | ||
| 7 | + var repoOwner = "{The orgname or username that owns the repo}"; | ||
| 8 | + var repoName = "{The name of the repo}"; | ||
| 9 | + | ||
| 10 | + // The token has to be included in the URL if the repo is private. | ||
| 11 | + // Otherwise, github just wont respond, so a normal credential callback | ||
| 12 | + // wont work. | ||
| 13 | + var repoUrl = "https://" + token + | ||
| 14 | + ":-oauth-basic@github.com/" + | ||
| 15 | + repoOwner + "/" + | ||
| 16 | + repoName + ".git"; | ||
| 17 | + | ||
| 18 | + var opts = { ignoreCertErrors: 1}; | ||
| 19 | + | ||
| 20 | + // If the repo is public, you can use a callback instead | ||
| 21 | + var repoUrl = "https://github.com/" + repoOwner + "/" + repoName + ".git"; | ||
| 22 | + | ||
| 23 | + var opts = { | ||
| 24 | + ignoreCertErrors: 1, | ||
| 25 | + remoteCallbacks: { | ||
| 26 | + credentials: function() { | ||
| 27 | + return NodeGit.Cred.userpassPlaintextNew (token, "x-oauth-basic"); | ||
| 28 | + } | ||
| 29 | + } | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + fse.remove(path).then(function() { | ||
| 33 | + var entry; | ||
| 34 | + | ||
| 35 | + nodegit.Clone.clone(repoUrl, path, opts) | ||
| 36 | + .done(function(repo) { | ||
| 37 | + if (repo instanceof nodegit.Repository) { | ||
| 38 | + console.info("We cloned the repo!"); | ||
| 39 | + } | ||
| 40 | + else { | ||
| 41 | + console.error("Something borked :("); | ||
| 42 | + } | ||
| 43 | + }); | ||
| 44 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments