+
Skip to content

Adding repo.getCommit method + tests, fixes #168. #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ repo.remove('master', 'path/to/file', function(err) {});

Exploring files of a repository is easy too by accessing the top level tree object.

```js
repo.getCommit('master', sha, function(err, commit) {});
```

Get information about a particular commit.

```js
repo.getTree('master', function(err, tree) {});
```
Expand Down Expand Up @@ -304,6 +310,7 @@ Include these before github.js :
### 0.10.X

Create and delete repositories
Repos - getCommit

### 0.9.X

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "github-api",
"main": "github.js",
"version": "0.10.3",
"version": "0.10.5",
"homepage": "https://github.com/michael/github",
"authors": [
"Sergey Klimov <sergey.v.klimov@gmail.com> (http://darvin.github.com/)"
Expand Down
10 changes: 10 additions & 0 deletions github.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,16 @@
// For a given file path, get the corresponding sha (blob for files, tree for dirs)
// -------

this.getCommit = function(branch, sha, cb) {
_request("GET", repoPath + "/git/commits/"+sha, null, function(err, commit) {
if (err) return cb(err);
cb(null, commit);
});
};

// For a given file path, get the corresponding sha (blob for files, tree for dirs)
// -------

this.getSha = function(branch, path, cb) {
if (!path || path === "") return that.getRef("heads/"+branch, cb);
_request("GET", repoPath + "/contents/"+path, {ref: branch}, function(err, pathContent) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "github-api",
"version": "0.10.4",
"version": "0.10.5",
"description": "A higher-level wrapper around the Github API.",
"main": "github.js",
"dependencies": {
Expand Down
9 changes: 9 additions & 0 deletions test/test.repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ test("Repo API", function(t) {
});
});

t.test('repo.getCommit', function(q) {
repo.getCommit('master', '20fcff9129005d14cc97b9d59b8a3d37f4fb633b', function(err, commit) {
q.error(err, 'get commit' + err);
q.ok(commit.message, 'v0.10.4', 'Returned commit message.');
q.ok(commit.author.date, '2015-03-20T17:01:42Z', 'Got correct date.');
q.end();
});
});

clearTimeout(timeout);
t.end();

Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载