diff --git a/README.md b/README.md index 045a66bf..25f99375 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,12 @@ bower install github-api [](https://saucelabs.com/u/githubjs) -**Note**: Starting from version 0.10.8, Github.js supports **Internet Explorer 9**. However, the underlying +**Note**: Starting from version 0.10.8, Github.js supports **Internet Explorer 9**. However, the underlying methodology used under the hood to perform CORS requests (the `XDomainRequest` object), [has limitations](http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx). -In particular, requests must be targeted to the same scheme as the hosting page. This means that if a page is at +In particular, requests must be targeted to the same scheme as the hosting page. This means that if a page is at http://example.com, your target URL must also begin with HTTP. Similarly, if your page is at https://example.com, then -your target URL must also begin with HTTPS. For this reason, if your requests are sent to the GitHub API (the default), +your target URL must also begin with HTTPS. For this reason, if your requests are sent to the GitHub API (the default), which are served via HTTPS, your page must use HTTPS too. ## GitHub Tools @@ -264,6 +264,20 @@ Unstar a repository. repo.unstar(owner, repository, function(err) {}); ``` +## Organization API + + +```js +var organization = github.getOrg(); +``` + +Create a new organization repository for the authenticated user + +```js +organization.createRepo({"orgname":"github-api-tests","name": "test"}, function(err, res) {}); +``` +Repo description, homepage, private/public can also be set. For a full list of options see the docs [here](https://developer.github.com/v3/repos/#create) + ## User API diff --git a/src/github.js b/src/github.js index cb6546a5..9bee922a 100644 --- a/src/github.js +++ b/src/github.js @@ -317,6 +317,14 @@ }; }; + Github.Organization = function () { + // Create an Organization repo + // ------- + this.createRepo = function (options, cb) { + _request('POST', '/orgs/' + options.orgname + '/repos', options, cb); + }; + }; + // Repository API // ======= @@ -1102,6 +1110,10 @@ return new Github.User(); }; + Github.getOrg = function () { + return new Github.Organization(); + }; + Github.getGist = function (id) { return new Github.Gist({ id: id diff --git a/test/test.org.js b/test/test.org.js new file mode 100644 index 00000000..f80de42c --- /dev/null +++ b/test/test.org.js @@ -0,0 +1,39 @@ +'use strict'; + +var Github = require('../src/github.js'); +var testUser = require('./user.json'); +var github, organization; + +describe('Github.Organization', function() { + before(function() { + github = new Github({ + username: testUser.USERNAME, + password: testUser.PASSWORD, + auth: 'basic' + }); + organization = github.getOrg(); + }); + + it('should create an organisation repo', function(done) { + var repoTest = Math.floor(Math.random() * (100000 - 0)) + 0; + var options = { + orgname: testUser.ORGANIZATION, + name: repoTest, + description: 'test create organization repo', + homepage: 'https://github.com/', + private: false, + has_issues: true, + has_wiki: true, + has_downloads: true + }; + + organization.createRepo(options, function(err, res, xhr) { + should.not.exist(err); + xhr.should.be.instanceof(XMLHttpRequest); + res.name.should.equal(repoTest.toString()); + res.full_name.should.equal(testUser.ORGANIZATION + '/' + repoTest.toString()); + + done(); + }); + }); +}); diff --git a/test/user.json b/test/user.json index 5fdc8e86..33479bef 100644 --- a/test/user.json +++ b/test/user.json @@ -1,5 +1,6 @@ { "USERNAME": "mikedeboertest", "PASSWORD": "test1324", - "REPO": "github" -} \ No newline at end of file + "REPO": "github", + "ORGANIZATION": "github-api-tests" +}
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: