Skip to content

Commit ade2bf6

Browse files
marcosommaAurelioDeRosa
authored andcommitted
Added Organization API
Closes github-toolsgh-296
1 parent b29e1f4 commit ade2bf6

File tree

8 files changed

+82
-10
lines changed

8 files changed

+82
-10
lines changed

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ bower install github-api
2222

2323
[![Sauce Test Status](https://saucelabs.com/browser-matrix/githubjs.svg)](https://saucelabs.com/u/githubjs)
2424

25-
**Note**: Starting from version 0.10.8, Github.js supports **Internet Explorer 9**. However, the underlying
25+
**Note**: Starting from version 0.10.8, Github.js supports **Internet Explorer 9**. However, the underlying
2626
methodology used under the hood to perform CORS requests (the `XDomainRequest` object),
2727
[has limitations](http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx).
28-
In particular, requests must be targeted to the same scheme as the hosting page. This means that if a page is at
28+
In particular, requests must be targeted to the same scheme as the hosting page. This means that if a page is at
2929
http://example.com, your target URL must also begin with HTTP. Similarly, if your page is at https://example.com, then
30-
your target URL must also begin with HTTPS. For this reason, if your requests are sent to the GitHub API (the default),
30+
your target URL must also begin with HTTPS. For this reason, if your requests are sent to the GitHub API (the default),
3131
which are served via HTTPS, your page must use HTTPS too.
3232

3333
## GitHub Tools
@@ -264,6 +264,26 @@ Unstar a repository.
264264
repo.unstar(owner, repository, function(err) {});
265265
```
266266

267+
## Organization API
268+
269+
270+
```js
271+
var organization = github.getOrg();
272+
```
273+
274+
Create a new organization repository for the authenticated user
275+
276+
```js
277+
var repo = {
278+
orgname: 'github-api-tests',
279+
name: 'test'
280+
};
281+
282+
organization.createRepo(repo, function(err, res) {});
283+
```
284+
285+
The repository description, homepage, private/public can also be set. [For a full list of options see the documentation](https://developer.github.com/v3/repos/#create).
286+
267287
## User API
268288

269289

dist/github.bundle.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/github.bundle.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/github.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/github.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/github.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,14 @@
317317
};
318318
};
319319

320+
Github.Organization = function () {
321+
// Create an Organization repo
322+
// -------
323+
this.createRepo = function (options, cb) {
324+
_request('POST', '/orgs/' + options.orgname + '/repos', options, cb);
325+
};
326+
};
327+
320328
// Repository API
321329
// =======
322330

@@ -1130,6 +1138,10 @@
11301138
return new Github.User();
11311139
};
11321140

1141+
Github.getOrg = function () {
1142+
return new Github.Organization();
1143+
};
1144+
11331145
Github.getGist = function (id) {
11341146
return new Github.Gist({
11351147
id: id

test/test.org.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
3+
var Github = require('../src/github.js');
4+
var testUser = require('./user.json');
5+
var github, organization;
6+
7+
describe('Github.Organization', function() {
8+
before(function() {
9+
github = new Github({
10+
username: testUser.USERNAME,
11+
password: testUser.PASSWORD,
12+
auth: 'basic'
13+
});
14+
organization = github.getOrg();
15+
});
16+
17+
it('should create an organisation repo', function(done) {
18+
var repoTest = Math.floor(Math.random() * 100000);
19+
var options = {
20+
orgname: testUser.ORGANIZATION,
21+
name: repoTest,
22+
description: 'test create organization repo',
23+
homepage: 'https://github.com/',
24+
private: false,
25+
has_issues: true,
26+
has_wiki: true,
27+
has_downloads: true
28+
};
29+
30+
organization.createRepo(options, function(err, res, xhr) {
31+
should.not.exist(err);
32+
xhr.should.be.instanceof(XMLHttpRequest);
33+
res.name.should.equal(repoTest.toString());
34+
res.full_name.should.equal(testUser.ORGANIZATION + '/' + repoTest.toString());
35+
36+
done();
37+
});
38+
});
39+
});

test/user.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"USERNAME": "mikedeboertest",
33
"PASSWORD": "test1324",
4-
"REPO": "github"
5-
}
4+
"REPO": "github",
5+
"ORGANIZATION": "github-api-tests"
6+
}

0 commit comments

Comments
 (0)