FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make all cred generators sync. by maxkorp · Pull Request #377 · nodegit/nodegit · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (2) .json  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
46 changes: 46 additions & 0 deletions examples/cloneFromGithubWith2Factor.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var nodegit = require("../");
var promisify = require("promisify-node");
var fse = promisify(require("fs-extra"));
var path = "/tmp/nodegit-github-2factor-demo";

var token = "{Your GitHub user token}";
var repoOwner = "{The orgname or username that owns the repo}";
var repoName = "{The name of the repo}";

// To clone with 2 factor auth enabled, you have to use a github oauth token
// over https, it can't be done with actual 2 factor.
// https://github.com/blog/1270-easier-builds-and-deployments-using-git-over-https-and-oauth

// The token has to be included in the URL if the repo is private.
// Otherwise, github just wont respond, so a normal credential callback
// wont work.
var repoUrl = "https://" + token +
":-oauth-basic@github.com/" +
repoOwner + "/" +
repoName + ".git";

var opts = { ignoreCertErrors: 1};

// If the repo is public, you can use a callback instead
var repoUrl = "https://github.com/" + repoOwner + "/" + repoName + ".git";

var opts = {
ignoreCertErrors: 1,
remoteCallbacks: {
credentials: function() {
return nodegit.Cred.userpassPlaintextNew (token, "x-oauth-basic");
}
}
};

fse.remove(path).then(function() {
nodegit.Clone.clone(repoUrl, path, opts)
.done(function(repo) {
if (repo instanceof nodegit.Repository) {
console.info("We cloned the repo!");
}
else {
console.error("Something borked :(");
}
});
});
8 changes: 7 additions & 1 deletion generate/input/descriptor.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -364,20 +364,26 @@
"cred": {
"cType": "git_cred",
"functions": {
"git_cred_default_new": {
"isAsync": false
},
"git_cred_ssh_custom_new": {
"ignore": true
},
"git_cred_ssh_interactive_new": {
"ignore": true
},
"git_cred_ssh_key_from_agent":{
"git_cred_ssh_key_from_agent": {
"isAsync": false
},
"git_cred_ssh_key_new": {
"isAsync": false
},
"git_cred_userpass": {
"ignore": true
},
"git_cred_userpass_plaintext_new": {
"isAsync": false
}
}
},
Expand Down
12 changes: 5 additions & 7 deletions test/tests/cred.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ describe("Cred", function() {
var sshPrivateKey = path.resolve("./id_rsa");

it("can create default credentials", function() {
NodeGit.Cred.defaultNew().then(function (defaultCreds) {
assert(defaultCreds instanceof NodeGit.Cred);
});
var defaultCreds = NodeGit.Cred.defaultNew();
assert(defaultCreds instanceof NodeGit.Cred);
});

it("can create ssh credentials using passed keys", function() {
Expand All @@ -23,9 +22,8 @@ describe("Cred", function() {
});

it("can create credentials using plaintext", function() {
NodeGit.Cred.userpassPlaintextNew("username", "password")
.then(function (plaintextCreds) {
assert(plaintextCreds instanceof NodeGit.Cred);
});
var plaintextCreds = NodeGit.Cred.userpassPlaintextNew
("username", "password");
assert(plaintextCreds instanceof NodeGit.Cred);
});
});

Back | FazBrowse Home | New Git URL