Skip to content

Organization API / createRepo() #296

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

Closed
wants to merge 12 commits into from
Closed
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
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ bower install github-api

[![Sauce Test Status](https://saucelabs.com/browser-matrix/githubjs.svg)](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
Expand Down Expand Up @@ -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


Expand Down
12 changes: 12 additions & 0 deletions src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
// =======

Expand Down Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions test/test.org.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
5 changes: 3 additions & 2 deletions test/user.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"USERNAME": "mikedeboertest",
"PASSWORD": "test1324",
"REPO": "github"
}
"REPO": "github",
"ORGANIZATION": "github-api-tests"
}