github-tools / github Goto Github PK
View Code? Open in Web Editor NEWA higher-level wrapper around the Github API. Intended for the browser.
License: BSD 3-Clause "New" or "Revised" License
A higher-level wrapper around the Github API. Intended for the browser.
License: BSD 3-Clause "New" or "Revised" License
I am just calling write on each file in the folder individually but this seems to randomly cause github to return Unprocessable Entity errors.
Is there a reliable way to write an entire folder of files?
My full code is here: https://mod.it/rSZYmsjn/dev Thanks!
PS.
This library is awesome and pulling from github is working great for me.
I'm helping clear the backlog of pull requests and issues at the moment, now about a third of the way thru them. If your issue/pull hasn't been dealt with yet, not to worry, it'll be dealt with pretty shortly.
Once these are all clear, I'll go through the readme.md file and code in general so all the whole API is spec'd and that'll probably be v0.9.
Something wrong in GitHub Page.
I try to get my file list by those api but not by jekyll's way,but Error 500.
Underscore is used all of seven times in the codebase, mostly for functions that plain JS already has. It would be incredibly nice if these seven bits were actually turned into plain JS so that github.js would just work as a standalone library
Now,
var repo = github.getRepo(reponame);
this is, maybe
var repo = github.getRepo(username, reponame);
After looking at the code, it looks like this was done intentionally, but I'm not sure why. I feel I should be able to pass the values returned by listBranches() to getRef() (appended to "heads/") without issue, but if I have a branch 'feature/foo', listBranches() will return 'foo', and getRef() will fail.
Suggesting as:
repo.branch(oldBranchName, newBranchName, cb)
I can update an existing file just using repo.write. The README says that files not existing in the repo are created on the fly. However, that doesn't seem to be working?
Looks like a path problem, because I get these 2 errors back...
OPTIONS https://api.github.com/repos//undefined/git/refs/heads/master?1345134920700 204 (No Content)
GET https://api.github.com/repos//undefined/git/refs/heads/master?1345134920700 404 (Not Found)
Notice there is no username or repo and a double slash after github.com/repos.
Can you confirm if there is a slight bug here?
@mattpass we've got a crazy crazy caching problem with our current XMLHttpRequest native implementation. I couldn't find out what's exactly happening here.
You need to use the updated github.js that I haven't commited yet because of this bug:
https://gist.github.com/3196019
The error can be reproduced like so:
var repo = github.getRepo("michael", "cmake_cdt7_stalled");
// Triggers GET: https://api.github.com/repos/michael/cmake_cdt7_stalled/git/refs/heads/prose-integration
repo.getRef('obu_cdt7_support', function(err, ref) {
// Triggers DELETE: https://api.github.com/repos/michael/cmake_cdt7_stalled/git/refs/heads/prose-integration
repo.deleteRef("heads/obu_cdt7_support", function(err) {
// For some weired reason the delete request doesn't get started, request inspection in chrome reveals
// it just returns the content from the previous GET request (from cache)
});
});
That's what the request log looks like for the DELETE request. Expected is a 204 no-content (not from cache) that actually removes the ref but we get a 200 OK (from cache). Seems like the variation of the method (GET vs. DELETE) is not considered for the caching mechanism.
Request URL:https://api.github.com/repos/michael/cmake_cdt7_stalled/git/refs/heads/prose-integration
Request Method:DELETE
Status Code:200 OK (from cache)
Request Payload
{"user":"michael","name":"cmake_cdt7_stalled"}
As of now, this needs jQuery, underscore, and an implementation of Base64.encode as well to function. Please note them down as such in the readme.
I think the Base64 should be included with it, at least.
github = new Github({ username:'username', password:'password', auth:"basic"})
user = github.getUser();
repos = ''
user.repos(function(err,r) { repos = r; })
repo = repos[0]
repoforwrite = github.getRepo('username',repo.name)
repoforwrite.write('gh-pages','test','test','test', function(err){alert(err);});
500 Server Internal Error
repo.permissions
Object {admin: true, pull: true, push: true}
repoforwrite.listBranches(function(err,branches) { console.log(branches);})
undefined
gh-pages,master
@michael - can you add a BSD license file?
Using the example from the docs, I can successfully write to my repo.
// example write
repo.write('master', 'path/to/file', 'YOUR_NEW_CONTENTS', 'YOUR_COMMIT_MESSAGE', function(err) {});
But only the first save seems to work. The others return a 422 status with the following error. I did notice this prose ticket...wondering what the workaround there was?
{
"message": "Update is not a fast forward",
"documentation_url": "http://developer.github.com/v3"
}
I just love the "authorise with github" button at prose.io
Can I create something similar just using github.js, or do I need to pull in more things from prose?
I've been trying to get github.js working, using basic authentication and things like this:
var user = github.getUser();
var gist = github.getGist(3165654);
but in my chrome console I get the following:
gist
Github.Gist {read: function, create: function, delete: function, fork: function, update: function}
gist.read(function(err, gist) {
});
TypeError: undefined is not a function
get stack: function () { [native code] }
message: "undefined is not a function"
set stack: function () { [native code] }
__proto__: Error
Any help very much appreciated ...
In order to safely transfer binary blobs/filtes, the API needs to use base64 encoding when appropriate. postBlob() however always uses "utf-8". So there needs to be either an additional argument in write() and postBlob() that specifies the encoding, or postBlob() needs to detect if the file is binary or not, and adjust the encoding automatically.
This little snippet seems to be able to detect binary data:
/[\x00-\x08\x0E-\x1F]/.test(data)
See http://stackoverflow.com/questions/1677644/detect-non-printable-characters-in-javascript
I'm currently dealing with similar issues in Prose: prose/prose#255
Hi Michael ....
How can i get this Authorization:token using access_token...can u please update the sample code for me...It helps me lot ...
Thanks in Advance..
when I call the .remove() function, I keep getting these errors:
POST https://api.github.com/repos/Pomax/gh-blog/git/trees?1393981519258 422 (Unprocessable Entity) api.github.com/repos/Pomax/gh-blog/git/trees?1393981519258:1
POST https://api.github.com/repos/Pomax/gh-blog/git/commits?1393981519451 422 (Unprocessable Entity) api.github.com/repos/Pomax/gh-blog/git/commits?1393981519451:1
Uncaught TypeError: Cannot read property 'sha' of undefined
The network responses for the failed URLs are
{
"message": "Must supply tree.sha or tree.content",
"documentation_url": "http://developer.github.com/v3/git/trees/#create-a-tree"
}
and
{
"message": "Validation Failed",
"documentation_url": "http://developer.github.com/v3/git/commits/#create-a-commit",
"errors": [
{
"value": null,
"resource": "Commit",
"field": "tree",
"code": "missing"
}
]
}
respectively.
I have the code written and can submit a patch.
Using Last-Modified``If-Modified-Since
or ETag``If-None-Match
headers http://developer.github.com/v3/#conditional-requests
I believe this is a dependency, but not listed as in package.json:
https://github.com/dankogai/js-base64
Hello,
I'm using github.js for login api for my application. It works fine for chrome, firefox and safari and IE 10. I'm facing problem with IE9 and opera.
For IE 9, it is giving below error
after executing this line - xhr.open(method, getURL());, it is saying, access denied error.(Credentials are correct).
For opera, it is giving status value as 0. Can any one help me to resolve this issue.
Thanks,
Janardhan
This used to work, many months ago when I last edited one of my repositories, but it no longer seems to. I am not sure when this broke though.
If this is going to be an long term issue, I can re-edit all my markdown, but if it is possible, I would like to know if this will be dealt with anytime soon
Thanks!
There are three methods which requests full tree hierarchy ("?recursive=true"):
Sometimes it is very heavy request to get full tree hierarchy. Is it possible to introduce an alternative methods like:
// Remove a file from the tree by sha and path
// -------
this.remove2 = function(branch, path, sha, cb) {
_request("DELETE", repoPath + "/contents/" + path, {"message": "test commit", sha: sha, branch:branch}, cb, "json");
};
2.this.getSha
It is possible to use JSON request for the "/contents/" to get more information about the it:
this.contents2 = function(branch, path, cb) {
_request("GET", repoPath + "/contents/ref=" + branch, { path: path }, cb, "json");
};
Could you please fix the package on NPM registry?
By running `npm install github-api' will install darvin's repository which is two versions old and not working properly.
Thanks
Are there any plans to support the Milestones API (http://developer.github.com/v3/issues/milestones/)?
Is no one else getting similar errors (looks like Gaubee might)?
OPTIONS https://api.github.com/repos/muffintheman/tipsy/git/refs/heads?1359485598135 500 (Internal Server Error) github.js:48
XMLHttpRequest cannot load https://api.github.com/repos/muffintheman/tipsy/git/refs/heads?1359485598135. Origin ... is not allowed by Access-Control-Allow-Origin.
all browsers, and all modern IE, come with the window.atob and window.btoa functions, and have done so for years, for base64 serialization/deserialization =)
Rather than trying to find Base64 in browser context, simply use window.atob(input) to form a base64 string.
it would be sweet if this was on NPM :D
I tried running the following simple code:
var github = new Github({ token: ".....<keyhere>.....", auth: "oauth"});
var repo = github.getRepo("Pomax", "pomax.github.io");
repo.contents("master", "gh-weblog/content", function(err, result) { console.warn(err); console.log(result); }, true);
repo.remove("master", "gh-weblog/content/2013-10-31-11-26-36.json", function(err, result) { console.log(err, result); });
But this generates one error after another. The path handling in remove is not in line with the v3 API, in browser context the global vars are getting set wrong:
var XMLHTTPRequest = (typeof XMLHTTPRequest === "undefined" ? false : XMLHTTPRequest);
)Even fixing those things, I get errors that the update call to git/trees is missing sha values; dir entires should have sha values as well, so I removed the filter that takes them out, and then the github API still throws up errors, so there are some problems here that prevent github.js from being usable with the API v3.
AFAICT everything is supported for Gists except creating a gist: http://developer.github.com/v3/gists/#create-a-gist
This might sound weird, but it helps in two ways :
As such, this would lead to losing nothing and making things a lot easier for the end users. For instance, anyone could just fork my repository, and it would automatically work for them at username.github.com/repo/ if I shift to gh-pages without them having to create an oauth application.
You can do most things to work with repos but there's no function to create them in the first place.
Would be great to have a function to create them, incl all the params (such as homepage, has wiki etc).
On the other end of the scale maybe a function to remove repos too?
Is it possible to list notifications: http://developer.github.com/v3/activity/notifications/#list-your-notifications
Or does that require another kind of authentication of the current user?
Hi
If I'm reading a file from a repo (repo.read
) and then it changes before I write back (repo.write
), the write disregards the changes and simply writes.
I would like for it to notice that the file has changed since reading and to do a merge - is that at all possible with the Github API? Is it possible with Github.js?
Thanks
This refers to yoavram/markx#34
Is there Github Enterprise support?
Is there any way for anonymous user get public repos list of some user?
Why do you need github user if you want only read content of public repository?
var github = new window.github_api({ username: "aplib", password: "xxx", auth: "basic" }); var repo = github.getRepo('aplib', 'tmp'); repo.remove('gh-pages', '1/1.dat', function(err) { if (err) console.log(err); });
it's not worked. no error messages, no remove file.
in repo only folder '1' and file '1/1.dat'.
used as a pure client side version (no nodejs):
var github = new Github({
username: "Pomax",
password: "......"
});
var repo = github.getRepo("Pomax", "bezierinfo");
repo.getTree("masster", function(err, data) { console.log(data); });
which gives me
TypeError: Cannot call method 'encode' of undefined
If there is something missing from this sequence of calls, the readme.md will need the additional information added, otherwise this is probably a bug.
This is a placeholder issue to create a version of Github.js which works with Gitlab's HTTP API. The motivation is to allow Prose.io to work with self-hosted repos using Gitlab.
Gitlab is an opensource/self-hostable alternative to Github. It has a very similar data model (users, orgs, forks, etc), and an HTTP API of similar expressivity.
There is a public service at https://gitlab.com/ for testing.
Any other interest in such a port?
It seems that repo.update is currently missing, requiring a repo.remove POST
followed by a repo.write POST
instead of the single repo.update PUT
operation. ref: http://developer.github.com/v3/repos/contents/#update-a-file
Hi there
Awesome library. I have one question though:
It seems like you're appending random query strings to the end of every API call, probably in order to make sure you get a non-cached response on every call.
However, the Gihub API implements a pretty smart HTTP caching, that is being ignored with this library. For people using it, it means that the rate-limit will get used much faster, and apps will try to reload content that is not updated.
Here's an example of what I mean:
/* Using JQuery
____________________________________________ */
$.ajax({
url:"https://user:[email protected]/repos/user/repo",
success: function(data) { console.log(data) }
});
// --> response 200 with content
$.ajax({
url:"https://user:[email protected]/repos/user/repo",
success: function(data) { console.log(data) }
});
// --> if called again within 60 seconds this call will never be made,
// as the Github API has HTTP cache of 60 seconds. If after
// 60 seconds and data is not updated, it returns an empty
// 304 not modified, which is much faster
/* Using github.js
____________________________________________ */
var github = new Github({
username: "user",
password: "pass",
auth: "basic"
});
var repo = github.getRepo(user, repo);
repo.show(function(err, repo) { console.log(repo) });
// --> response 200 with content
repo.show(function(err, repo) { console.log(repo) });
// --> response 200 with content, no caching
repo.show(function(err, repo) { console.log(repo) });
// --> response 200 with content, no caching
I saw that you have "implemented smart caching" in a commit, so I'm not sure exactly what's going on. How is this library caching stuff?
While call write/read methods it show error like: Uncaught TypeError: undefined is not a function in github.js:32
i try like this bellow...
repo.read('master', 'README.md', function(err, data) {});
repo.write('master', ' Test/README.md ', 'This is my New comment', '1st commit', function(err) {});
i'm trying to upload file to my repo
github = new Github
username: "zh99998",
password: <hidden>,
auth: "basic"
repo = github.getRepo('zh99998', 'test')
repo.write 'master', '/README.markdown', 'test1', 'test2', (err)->
console.log err
then it logs out null, and see Network, all are 200 OK / 201 Created, seems all well, when i go to github and see that repo, the commit is successful, but there's nothing in this commit, and file is not modified.
like this:
zh99998/test@d292be1
github ignores per_page values larger than 100. So your get repos call only returns the first 100 repos.
Hi everyone. I only do JS for a couple of weeks now and could not find out, why the code
this.show = function(username, cb) {
var command = username ? "/users/"+username : "/user";
_request("GET", command, null, function(err, res) {
cb(err, res);
});
};
Works with
....show('dctr', myFunc);
and with
....show(myFunc);
Why doesn't command evaluate to something absurd and cb fails but myFunc is called in both cases? At least i would have expected something like
cb = username ? cb : username;
Thanks in advance for anwers...
when using repo.remove('gh-pages', 'file that exists', function(err) { console.error(err); });
I get the following error and callstack:
Uncaught TypeError: Cannot call method 'reject' of undefined -- github.js:532
(anonymous function) -- github.js:532
(anonymous function) -- github.js:347
I was trying to effect a "repo.replace" by first removing a file I know exists in the tree using repo.remove
and then calling repo.write
to put in a new copy with updated information, but the remove throws this error.
It appears that the _
var in https://github.com/michael/github/blob/master/github.js#L532 does not actually point to anything.
@michael thanks for the great module. :)
What is the current status of AMD support with this module? I can't find anything as to where things stand for it atm.
In the project history, the only mention I can dig up so far is this: https://github.com/michael/github/pull/44/files.
Any reason as to when/why it was removed? Is there anything currently in the way of bring AMD support back?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.