Coder Social home page Coder Social logo

philschatz / octokat.js Goto Github PK

View Code? Open in Web Editor NEW
421.0 421.0 133.0 1.96 MB

:octocat: Github API Client using Promises or callbacks. Intended for the browser or NodeJS.

Home Page: http://philschatz.com/2014/05/25/octokat/

License: MIT License

CoffeeScript 8.83% JavaScript 88.50% HTML 0.92% Shell 1.75%
github-api javascript promise promise-support

octokat.js's Introduction

Octokat.js

gh-board NPM version Downloads build status dependency status dev dependency status code coverage

Try it out in your browser! (REPL)

Octokat.js provides a minimal higher-level wrapper around GitHub's API. It is being developed in the context of an EPUB3 Textbook editor for GitHub and a simple serverless kanban board (demo).

This package can be used in nodejs or in the browser as an AMD module or using browserify.

Table of Contents

Install

Octokat runs in node or a browser and is available in npm.

npm install --save octokat

Key Features

  • Works in nodejs, an AMD module in the browser, and as a bower library
  • Handles text and binary files
  • Exposes everything available via the GitHub API (repos, teams, events, hooks, emojis, etc.)
  • Supports ETag caching
  • Paged results
  • Node-style callbacks as well as optional Promises (to avoid those debates)
  • 100% of the GitHub API
    • Starring and Following repositories, users, and organizations
    • Editing Team and Organization Membership
    • User/Org/Repo events and notifications
    • Listeners for rate limit changes
    • Public Keys
    • Hooks (commit, comment, etc.)
    • Uses native Promises if available
    • Markdown generation
    • Preview APIs (Deployments, Teams, Licenses, etc)
    • Enterprise APIs

For the full list of supported methods see ./src/grammar/, ./examples/, Travis tests, or the ./test directory.

Overview

This library closely mirrors the https://developer.github.com/v3 documentation.

For example:

// `GET /repos/:owner/:repo` in the docs becomes:
octo.repos(owner, repo).fetch()

// `POST /repos/:owner/:repo/issues/:number/comments` becomes:
octo.repos(owner, repo).issues(number).comments.create(params)

The last method should be a verb method. The verb method makes the async call and should either have a callback as the last argument or it returns a Promise (see Promises or Callbacks).

The basic structure of the verb method is:

  • .foos.fetch({optionalStuff:...}) yields a list of items (possibly paginated)
  • .foos(id).fetch(...) yields a single item (issue, repo, user)
  • .foos.create(...) creates a new foo
  • .foos(id).update(...) updates an existing foo
  • .foos(id).add() adds an existing User/Repo (id) to the list
  • .foos(id).remove() removes a member from a list or deletes the object and yields a boolean indicating success
  • .foos.contains(id) tests membership in a list (yields true/false)
  • .foos(id).read() is similar to .fetch() but yields the text contents without the wrapper JSON
  • .foos(id).readBinary() is similar to .read() but yields binary data

Examples

Below are some examples for using the library. For a semi-autogenerated list of more examples see ./examples/.

Chaining

You construct the URL by chaining properties and methods together and an async call is made once a verb method is called (see below).

octo = new Octokat()
repo = octo.repos('philschatz', 'octokat.js')
// Check if the current user is a collaborator on a repo
repo.collaborators.contains(USER)
.then((isCollaborator) => {
  // If not, then star the Repo
  if (!isCollaborator) {
    repo.star.add()
    .then(() => {
      // Done!
    })
  }
})

Or, update a specific comment:

octo = new Octokat({token: ...})
octo.repos('philschatz', 'octokat.js').issues(1).comments(123123).update({body: 'Hello'})
.then(() => {
  // Done!
})

Promises or Callbacks

This library supports Node.js-style callbacks as well as Promises.

To use a callback, just specify it as the last argument to a method. To use a Promise, do not specify a callback and the return value will be a Promise.

Example (get information on a repo):

// Using callbacks
octo.repos('philschatz', 'octokat.js').fetch((err, repo) => {
  if (err) console.error(err)
  // Do fancy stuff...
})

// Using Promises
octo.repos('philschatz', 'octokat.js').fetch()
.then((repo) => {
  // Do fancy stuff
}).then(null, (err) => console.error(err))

Read/Write/Remove a File

To read the contents of a file:

var octo = new Octokat()
var repo = octo.repos('philschatz', 'octokat.js')
repo.contents('README.md').read() // Use `.read` to get the raw file.
.then((contents) => {        // `.fetch` is used for getting JSON
  console.log(contents)
});

To read the contents of a binary file:

var octo = new Octokat()
var repo = octo.repos('philschatz', 'octokat.js')
repo.contents('README.md').readBinary() // Decodes the Base64-encoded content
.then((contents) => {
  console.log(contents)
})

To read the contents of a file and JSON metadata:

var octo = new Octokat()
var repo = octo.repos('philschatz', 'octokat.js')
repo.contents('README.md').fetch()
.then((info) => {
  console.log(info.sha, info.content)
})

To update a file you need the blob SHA of the previous commit:

var octo = new Octokat({token: 'API_TOKEN'})
var repo = octo.repos('philschatz', 'octokat.js')
var config = {
  message: 'Updating file',
  content: base64encode('New file contents'),
  sha: '123456789abcdef', // the blob SHA
  // branch: 'gh-pages'
}

repo.contents('README.md').add(config)
.then((info) => {
  console.log('File Updated. new sha is ', info.commit.sha)
})

Creating a new file is the same as updating a file but the sha field in the config is omitted.

To remove a file:

var octo = new Octokat({token: 'API_TOKEN'})
var repo = octo.repos('philschatz', 'octokat.js')
var config = {
  message: 'Removing file',
  sha: '123456789abcdef',
  // branch: 'gh-pages'
}

repo.contents('README.md').remove(config)
.then(() => {
  console.log('File Updated')
});

Usage

All asynchronous methods accept a Node.js-style callback and return a Common-JS Promise.

In a Browser

Create an Octokat instance.

var octo = new Octokat({
  username: "USER_NAME",
  password: "PASSWORD"
})

var cb = function (err, val) { console.log(val) }

octo.zen.read(cb)
octo.repos('philschatz', 'octokat.js').fetch(cb) // Fetch repo info
octo.me.starred('philschatz', 'octokat.js').add(cb) // Star a repo

Or if you prefer OAuth:

var octo = new Octokat({
  token: "OAUTH_TOKEN"
})

In a browser using RequireJS

define(['octokat'], (Octokat) => {
  var octo = new Octokat({
    username: "YOU_USER",
    password: "YOUR_PASSWORD"
  })
})

In Node.js

Install instructions:

npm install octokat --save
var Octokat = require('octokat')
var octo = new Octokat({
  username: "YOU_USER",
  password: "YOUR_PASSWORD"
})

// You can omit `cb` and use Promises instead
var cb = function (err, val) { console.log(val) }

octo.zen.read(cb)
octo.repos('philschatz', 'octokat.js').fetch(cb)    // Fetch repo info
octo.me.starred('philschatz', 'octokat.js').add(cb) // Star a repo
octo.me.starred('philschatz', 'octokat.js').remove(cb) // Un-Star a repo

Using bower

This file can be included using the bower package manager:

bower install octokat --save

Setup

This is all you need to get up and running:

<script src="../dist/octokat.js"></script>
<script>
  var octo = new Octokat()
  octo.zen.read((err, message) => {
    if (err) { throw new Error(err) }
    alert(message)
  })
</script>

Advanced Uses

Hypermedia

GitHub provides URL patterns in its JSON responses. These are automatically converted into methods. You can disable this by setting disableHypermedia: true in the options when creating a new Octokat(...).

For example:

octo.repos('philschatz', 'octokat.js').fetch()
.then((repo) => {
  // GitHub returns a JSON which contains something like compare_url: 'https://..../compare/{head}...{base}
  // This is converted to a method that accepts 2 arguments
  repo.compare(sha1, sha2).fetch()
  .then((comparison) => console.log('Done!'))
})

Paged Results

If a .fetch() returns paged results then nextPage(), previousPage(), firstPage() and lastPage() are added to the returned Object. For example:

octo.repos('philschatz', 'octokat.js').commits.fetch()
.then((someCommits) => {
  someCommits.nextPage()
  .then((moreCommits) => {
    console.log('2nd page of results', moreCommits)
  })
})

As standard with the Github API, passing a per_page parameter allows you to control the number of results per page. For example:

octo.repos('philschatz', 'octokat.js').issues.fetch({per_page: 100})
  .then(...)

Preview new APIs

Octokat will send the Preview Accept header by default for several Preview APIs.

If you want to change this behavior you can force an acceptHeader when instantiating Octokat.

For example:

var octo = new Octokat({
  token: 'API_TOKEN',
  acceptHeader: 'application/vnd.github.cannonball-preview+json'
})

Enterprise APIs

To use the Enterprise APIs add the root URL when instantiating Octokat:

var octo = new Octokat({
  token: 'API_TOKEN',
  rootURL: 'https://example.com/api/v3'
})

Using EcmaScript 6 Generators

This requires Node.js 0.11 with the --harmony-generators flag:

var Octokat = require('octokat')
var octo = new Octokat()

var zen  = yield octo.zen.read()
var info = yield octo.repos('philschatz', 'octokat.js').fetch()

console.log(zen)
console.log(info)

Uploading Releases

Uploading release assets requires a slightly different syntax because it involves setting a custom contentType and providing a possibly binary payload.

To upload (tested using nodejs) you can do the following:

var contents = fs.readFileSync('./build.js')

repo.releases(123456).fetch()
.then((release) => {

  release.upload('build.js', 'application/javascript', contents)
    .then((resp) => {
      // Success!
    })
})

Parsing JSON

If you are using webhooks, the JSON returned by GitHub can be parsed using octo.parse(json) to yield a rich object with all the methods Octokat provides.

octo.parse(json) is asynchronous and can take either a callback or returns a promise.

Using URLs Directly

Instead of using Octokat to construct URLs, you can construct them yourself and still use Octokat for sending authentication information, caching, pagination, and parsing Hypermedia.

// Specify the entire URL
octo.fromUrl('https://api.github.com/repos/philschatz/octokat.js/issues/1').fetch(cb)

// Or, just the path
octo.fromUrl('/repos/philschatz/octokat.js/issues').fetch({state: 'open'}, cb)

If the URL is a Hypermedia Template then you can fill in the fields by passing them in as an additional argument.

params = {
  owner: 'philschatz'
  repo: 'octokat.js'
  name: 'dist.js'
}
octo.fromUrl('https://uploads.github.com/repos/{owner}/{repo}/releases{/id}/assets{?name}', params)
// returns https://uploads.github.com/repos/philschatz/octokat.js/releases/assets?name=dist.js

Development

  • Run npm install
  • Run npm test to run Mocha tests for Node.js and the browser
  • Run grunt dist to generate the files in the ./dist directory

The unit tests are named to illustrate examples of using the API. See Travis tests or run npm test to see them.

fetch-vcr is used to generate recorded HTTP fixtures from GitHub. If you are adding tests be sure to include the updated fixtures in the Pull Request.

Todo

  • Add Option for Two factor authentication
  • Add option to pass header as cache control: no cache

octokat.js's People

Contributors

bewest avatar cirosantilli avatar divdavem avatar exogen avatar georgemarrows avatar ghjunior avatar gr2m avatar greenkeeper[bot] avatar harlantwood avatar joshaber avatar mathieudutour avatar matthewbauer avatar mokkabonna avatar niik avatar ortham avatar peterdavehello avatar philschatz avatar prijindal avatar richardlitt avatar sanemat avatar shiftkey avatar targos avatar vimto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

octokat.js's Issues

Coffeeify imports not working in browserify

Hey again!

Trying this out, pretty excited. Didn't know you could do coffee-script/register to avoid having to compile to js, that's pretty cool.

Unfortunately doesn't seem to be working for me =P
May be the fault of my built setup. I'm using Browserify through Watchify inside of gulp, using the Coffeeify transform. Here's the error I get when trying to require octocat:

Browserify Error { [Error: Parsing file /Users/alex/mypath/node_modules/octokat/src/octokat.coffee: Line 1: Unexpected string]

Again, not sure if this is on me or what. For my purposes, I just compiled everything to js, a sibling of src, and changed index.js to match.

SearchIssues Function Replacement?

Running a script that works well with a previous iteration of Octokit,

The relevant line starts with:

searchIssues(pluginName + ' in:title repo:' + repos[gameName].owner + '/' + repos[gameName].repo).then(function(issues)

Is there a replacement function in Octokat for this, or does the current code need refactoring to suit?

Thanks :)

Understanding callbacks on `repo.contents().add()`

When I am using the callback pattern for creating a new file, what arguments should I expect to get on the callback?

When I try to add a file to an invalid repo with:

octo.repo('myuser', 'nonexistentrepo').contents('myfile.txt').add(function (err, info) {
 // err is undefined
})

BUG: Invalid Path when accessing git.refs('tags/tagname')

I get

BUG: Invalid Path. If this is actually a valid path then please update the URL_VALIDATOR. path=/repos/owner/reponame/git/refs/tags/mytag

When calling

octo.repos('owner', 'reponame').git.refs('tags/mytag')

Ideally I guess you should have been able to do:

octo.repos('owner', 'reponame').git.refs.tags('mytag')

Like if it was a branch:

octo.repos('owner', 'reponame').git.refs.heads('mybranch')

But tags is not a property of refs, so that fails.

Is it only to add tags here? https://github.com/philschatz/octokat.js/blob/master/src/grammar.coffee#L157 Or should maybe refs allow for any custom path after? Isn't that ok in git (and github). Like github itself uses with refs/pr/# (or something)

Then we could do

octo.repos('owner', 'reponame').git.refs('myrefcategory/mysomething')

Anyway for a built in feature like tags I think it should be possible to it directly like shown before with regs.tags(tagname)

npm package contains a large zip file with dev dependencies

When I do npm install octokat the resulting node module contains a 26 MB large ZIP file with all dev dependencies called node_modules.zip, which does not seem necessary for using octokat as a library. This is problematic because when I want to include octokat in my own node module for use on AWS Lambda, I need to package it with all dependencies and the resulting package file becomes hard to upload when it is larger than 10 MB.

Octocat and ember extending prototype

I have use the latest ember cli (1.13.6) to generate a default project.

Seems ember are extending array prototype. (which probably is a bad idea on their part anyway)

In my ember route I do the following:

return octo.users('mokkabonna').repos.fetch({per_page:1})

The code trips out here with maximum callstack error:
https://github.com/philschatz/octokat.js/blob/master/src/replacer.coffee#L59

In particular it seems when octokat encounters a key named " super" (notice the leading space)

Sure it shouldn't be if typeof value instead of key? Isn't key always a string? If i change it to that it seems fine.

Anyway isn't it better to use Object.keys? Or if you want to support es3, use at least use this:

for (var name in buz) {
  if (buz.hasOwnProperty(name)) {
    console.log('this is fog (' + name + ') for sure. Value: ' + buz[name]);
  }
}

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty

Example of OAuth in the browser?

I'm wondering what steps are required to use the OAuth support. I'm guessing that first one must register the app with GitHub. But in that process I didn't see an "oauth_token" presented. Is something like hello.js necessary?

I'm making an app to analyze repo management styles. Currently, it supports just unauthenticated mode and password authentication. http://repocheck.com

Release uploads don't work anymore

I use octokat.js with github enterprise.

Recently we updated from 2.3 to 2.4 and now I can't upload release assets anymore. The error I get is:

{"message":"Invalid name for request","request_id":"b419e46f-86bd-11e5-8e9a-c8998822e9ce"}

I have pinpointed the error to an change in the upload_url reported by github api:

in 2.3 it was https://developer.github.com/enterprise/2.3/v3/repos/releases/#get-a-single-release

  "upload_url": "https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name}",

in 2.4 it is https://developer.github.com/v3/repos/releases/#get-a-single-release

 "upload_url": "https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}",

This causes the templating in octokat to produce this url:
https://github.oslo.kommune.no/api/uploads/repos/pet/minside/releases/444/assets?name,label=deploy.tar.gz

when before it would have been:
https://github.oslo.kommune.no/api/uploads/repos/pet/minside/releases/444/assets?name=deploy.tar.gz

The code I have, before and now:

release.upload('deploy.tar.gz', 'application/x-gzip', grunt.file.read('dist/deploy.tar.gz', {
  encoding: null //return buffer
}));

Is there anyway I can change this to make it work still, or is this just a bug that need to be fixed? I have tried with no success:

release.upload('deploy.tar.gz', 'somelabel', 'application/x-gzip', grunt.file.read('dist/deploy.tar.gz', {
  encoding: null //return buffer
}));

Also:

release.upload({
  name: 'deploy.tar.gz',
  label: 'somelabel',
}, 'application/x-gzip', grunt.file.read('dist/deploy.tar.gz', {
  encoding: null //return buffer
}));

Does octokat.js not support multiple query params? Or is it filling it out last to first?

Auth required when using in the browser?

I'm logged into github.com in my browser. When I make an in-browser request using octokat, does my cookie get used, or do I have to explicitly supply an OAuth token?

File read doesn't work in strict mode

Hi,

I tried to run this example from README in my browser:

var octo = new Octokat();
var repo = octo.repos('philschatz', 'octokat.js');
repo.contents('README.md').read() // Use `.read` to get the raw file.
.then(function(contents) {        // `.fetch` is used for getting JSON
  console.log(contents);
});

... but it fails with following error:

verb-methods.js:76 Uncaught TypeError: Cannot create property 'url' on string '# Octokat.js

Error line is following (verb-methods.js:76):

      obj.url = path;

Somehow, obj becomes a response string, and it's forbidden to make new properties for strings in strict mode.

Patch?

How do I use a PATCH method?

Example: octo.repos(result.owner.login, result.name).update({
description: 'test'
})

Thanks.

Error with parsed json returned by gists

octo.gists(gist_id).fetch() returns incorrectly parsed json for data.files:

{
raw: 
      { [Function]
        url: 'https://gist.githubusercontent.com/..../file.txt' },
}

This should be raw_url but it looks like somehow it is getting parsed. read() returns the correct unparsed json string.

Another Invalid Path bug

Relevant code.

To reproduce: Download repo, then:

$ node cli.js test
BUG: Invalid Path. If this is actually a valid path then please update the URL_VALIDATOR. path=/users/
[@diasdavid](//github.com/diasdavid) (David Dias)
[@jbenet](//github.com/jbenet) (Juan Benet)
[@RichardLitt](//github.com/RichardLitt) (Richard Littauer)

Not sure why test is an invalid path.

Small (but annyoing) error in bower.json

The line

"main": "octokat.js",

in bower.json shoiuld read

"main": "dist/octokat.js",

otherwise tools like main-bower-files can't be used to automatically bundle octokat.

I tend to feel a tad stupid for making pull request for such tiny things, but if you want I can make on.

Gitignore or git add and grunt clean generated / modified files.

git clone; npm test; git status:

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        dist/commonjs/
        fixtures/

Normally I would just gitignore those, but I'm a Node newb and seeing that dist/octokat.js is tracked (for bower?) I'm not sure if dist/commonjs shouldn't be also (imagine not, as it is meant to be used for NPM and it is not necessary to git track it for npm publish)

grunt clean; git status: fixtures/ is still untracked. Shouldn't clean remove it?

Adding organisations endpoint

Hi @philschatz,

I was trying to use your lib for listing all organisations: https://developer.github.com/v3/orgs/#list-all-organizations but I'm having a hard time figuring out what I'm missing.

Instead of just calling the API directly I want to learn how to improve this library, so I went to grammar and added organisations as a top level path.

I didn't apply any changes to the OBJECT_MATCHER: https://github.com/philschatz/octokat.js/blob/master/src/grammar.coffee#L414

When I know how to add this one, I plan on adding a few others like adding users etc, i.e. the admin path.

Note: I'm going to try and debug your code and use a proxy to know what's coming out of my terminal and I hope to get there in the meantime.

using a 'token' in results in an error

hi @philschatz .

I'm using the web flow for retreiving a token - so eventually my app receives a code parameter in the query string after github redirects to my app.
when i use this code like so:

data.github = new Octokat({
    token: token
});

I'm trying to fetch one of my repos and i'm getting this error in the browser console:

Uncaught (in promise) Error: {
  "message": "Bad credentials",
  "documentation_url": "https://developer.github.com/v3"
}

  "message": "Bad credentials",
  "documentation_url": "https://developer.github.com/v3"
}

    at http://localhost:3000/octokat.js:1001:17
    at XMLHttpRequest.xhr.onreadystatechange (http://localhost:3000/octokat.js:835:16)

Anything i'm missing here?

Count number of issues/PRs?

I'm considering using octokat on the npmjs.com website. We currently have some spaghetti-ish browserify code that hits the github API to display issue and pull request counts for npm packages:

screen shot 2015-04-02 at 9 53 33 pm

We're using this One Weird Trickโ„ข that @pengwynn taught us to fetch the counts: We set per_page to 1, then use @thlorenz's parse-link-header to pull the last page out of the response header. Because we only asked for one result, the last page is also the number of issues. This is a nice trick because it only requires a single request, even if there are hundreds of issues on the repo.

From the octokat README, I can see that the per_page option is supported, and attaches a lastPage() function to the response object, but that doesn't solve the problem of fetching the count. Is there a way to do this with octokat?

new (require("octokat"))().repos("npm", "newww").issues.fetch({per_page: 1})
  .then(function() { console.log(arguments) })

cc @yashprit and @colegillespie, who both have an interest in making this work on the npm website. :)

Repos releases not working?

I installed version 0.4.0 with npm, and I tried running this program in Node.js:

var Octokat = require('octokat');

var octo = new Octokat();

octo.repos("philschatz", "octokat.js").releases.fetch().then(function (x) {
  console.log(x);
});

This logs an empty array [], even though the repo has multiple releases. Am I doing something wrong?

My code for current page, page count, and percent complete

Hi, I'm getting some great use out of Octokat, and thought I'd share some code โ€” these could maybe be added into the returned API result object:

  describe ".pageCount(apiResult)", ->

    it "works on the first page", ->
      result = {lastPageUrl: "https://api.github.com/repositories/771016/issues?per_page=100&state=all&since=2015-11-24&page=3"}
      expect(App.Github.pageCount(result)).toBe 3

    it "works on the last page", ->
      result = {prevPageUrl: "https://api.github.com/repositories/771016/issues?per_page=100&state=all&since=2015-11-24&page=2"}
      expect(App.Github.pageCount(result)).toBe 3

    it "works on the only page", ->
      result = {}
      expect(App.Github.pageCount(result)).toBe 1

  describe ".currentPage(apiResult)", ->

    it "works on the first page", ->
      result = {nextPageUrl: "https://api.github.com/repositories/771016/issues?per_page=100&state=all&since=2015-11-24&page=2"}
      expect(App.Github.currentPage(result)).toBe 1

    it "works on the last page", ->
      result = {prevPageUrl: "https://api.github.com/repositories/771016/issues?per_page=100&state=all&since=2015-11-24&page=2"}
      expect(App.Github.currentPage(result)).toBe 3

    it "works on the only page", ->
      result = {}
      expect(App.Github.currentPage(result)).toBe 1
  @pageCount: (apiResult) ->
    url = apiResult.lastPageUrl
    if typeof(url) is 'undefined'
      url = apiResult.prevPageUrl
      return 1 if typeof(url) is 'undefined'
      parseInt(url.match(/\d+$/)[0]) + 1
    else
      parseInt(url.match(/\d+$/)[0])


  @currentPage: (apiResult) ->
    url = apiResult.nextPageUrl
    if typeof(url) is 'undefined'
      url = apiResult.prevPageUrl
      return 1 if typeof(url) is 'undefined'
      parseInt(url.match(/\d+$/)[0]) + 1
    else
      parseInt(url.match(/\d+$/)[0]) - 1


  @percentComplete: (apiResult) ->
    parseInt(@currentPage(apiResult) / @pageCount(apiResult) * 100)

How do I use caching in Octokat.js?

Here's the script I've used:

  var octo = new Octokat({token: "<token>"});

  var cb = function(result) {
    console.log(result.length);
  };

  var repo = octo.repos("<org>", "<repo>");
  var promise = repo.issues.fetch({status: "open"});

  promise.then(cb);

  setTimeout(function() {
    promise.then(cb);
  }, 10000);

The second call to resolve the promise inside the setTimeout does not fetch a new set of issues if I add one on the repo in the 10 seconds time. It logs the same number of issues on both calls. What am I doing wrong?

I'm using the latest library under dist.

problems with releases API

I think I found two problems related to the releases API:

  • repo.releases(id).fetch() works but logs an error: BUG: Invalid Path. If this is actually a valid path then please update the URL_VALIDATOR. path=/repos/cheminfo-js/test/releases/1016794
  • repo.releases.latest does not exist

Also I do not understand how to use the release object to upload an asset.

var repo = octo.repos('cheminfo-js', 'test');
var release = yield repo.releases(1016794).fetch() // OK with first logged bug
var contents = yield fs.readFile('./test.js');
yield release.upload('test.js', contents) // what should I do here ?

[Question] How to handle a merge button?

I try to merge a pull request. But I haven't done this yet.

// GitHub API
GET /repos/:owner/:repo/pulls/:number/merge
PUT /repos/:owner/:repo/pulls/:number/merge

I tried this.

pullRequest.merge.add()
// => Cannot read property 'add' of undefined
pullRequest.merge()
// => pullRequest.merge is not a function

Both two methods bring error.
How to handle a merge button?

API documents

env

// octokat version
0.4.11

// pullRequest object
{
  "url": "https://api.github.com/repos/tachikomaio/stollen/pulls/39",
  "id": 45023867,
  "htmlUrl": "https://github.com/tachikomaio/stollen/pull/39",
  "diffUrl": "https://github.com/tachikomaio/stollen/pull/39.diff",
  "patchUrl": "https://github.com/tachikomaio/stollen/pull/39.patch",
  "issueUrl": "https://api.github.com/repos/tachikomaio/stollen/issues/39",
  "number": 39,
  "state": "open",
  "locked": false,
  "title": "Exec tachikoma update 20150915085715",
  "user": {
    "login": "togusafish",
    "id": 13007906,
    "avatarUrl": "https://avatars.githubusercontent.com/u/13007906?v=3",
    "gravatarId": "",
    "url": "https://api.github.com/users/togusafish",
    "htmlUrl": "https://github.com/togusafish",
    "followersUrl": "https://api.github.com/users/togusafish/followers",
    "subscriptionsUrl": "https://api.github.com/users/togusafish/subscriptions",
    "organizationsUrl": "https://api.github.com/users/togusafish/orgs",
    "reposUrl": "https://api.github.com/users/togusafish/repos",
    "receivedEventsUrl": "https://api.github.com/users/togusafish/received_events",
    "type": "User"
  },
  "body": ":hamster::hamster::hamster: <br /> <br /> Strategy david\nPowered by <a href=\"http://tachikoma.io/?utm_source=github&utm_medium=pull_request&utm_campaign=build6049475725670024342\">David Update as a Service - Tachikoma.io</a> <br />Announcement: <a href=\"http://tachikoma.io/2015-06-28-updated-permissions.html?utm_source=github&utm_medium=pull_request&utm_campaign=build6049475725670024342\">2015-06-28 Updated permissions - Tachikoma.io</a>\n",
  "createdAt": "2015-09-15T08:57:38.000Z",
  "updatedAt": "2015-09-15T08:57:38.000Z",
  "closedAt": null,
  "mergedAt": null,
  "mergeCommitSha": "834c330947a7b074693c7e25fbc4c7b1fa94b338",
  "assignee": null,
  "milestone": null,
  "commits": 1,
  "commitsUrl": "https://api.github.com/repos/tachikomaio/stollen/pulls/39/commits",
  "reviewComments": 0,
  "reviewCommentsUrl": "https://api.github.com/repos/tachikomaio/stollen/pulls/39/comments",
  "comments": 0,
  "commentsUrl": "https://api.github.com/repos/tachikomaio/stollen/issues/39/comments",
  "statusesUrl": "https://api.github.com/repos/tachikomaio/stollen/statuses/e02cd7cab1e364c7cf469f9d7b7114af2a66c9e7",
  "head": {
    "label": "togusafish:tachikoma/update-20150915085715",
    "ref": "tachikoma/update-20150915085715",
    "sha": "e02cd7cab1e364c7cf469f9d7b7114af2a66c9e7",
    "user": {
      "login": "togusafish",
      "id": 13007906,
      "avatarUrl": "https://avatars.githubusercontent.com/u/13007906?v=3",
      "gravatarId": "",
      "url": "https://api.github.com/users/togusafish",
      "htmlUrl": "https://github.com/togusafish",
      "followersUrl": "https://api.github.com/users/togusafish/followers",
      "subscriptionsUrl": "https://api.github.com/users/togusafish/subscriptions",
      "organizationsUrl": "https://api.github.com/users/togusafish/orgs",
      "reposUrl": "https://api.github.com/users/togusafish/repos",
      "receivedEventsUrl": "https://api.github.com/users/togusafish/received_events",
      "type": "User"
    },
    "repo": {
      "id": 38675899,
      "name": "tachikomaio-_-stollen",
      "fullName": "togusafish/tachikomaio-_-stollen",
      "owner": {
        "login": "togusafish",
        "id": 13007906,
        "avatarUrl": "https://avatars.githubusercontent.com/u/13007906?v=3",
        "gravatarId": "",
        "url": "https://api.github.com/users/togusafish",
        "htmlUrl": "https://github.com/togusafish",
        "followersUrl": "https://api.github.com/users/togusafish/followers",
        "subscriptionsUrl": "https://api.github.com/users/togusafish/subscriptions",
        "organizationsUrl": "https://api.github.com/users/togusafish/orgs",
        "reposUrl": "https://api.github.com/users/togusafish/repos",
        "receivedEventsUrl": "https://api.github.com/users/togusafish/received_events",
        "type": "User"
      },
      "private": false,
      "htmlUrl": "https://github.com/togusafish/tachikomaio-_-stollen",
      "description": "",
      "fork": true,
      "url": "https://api.github.com/repos/togusafish/tachikomaio-_-stollen",
      "forksUrl": "https://api.github.com/repos/togusafish/tachikomaio-_-stollen/forks",
      "teamsUrl": "https://api.github.com/repos/togusafish/tachikomaio-_-stollen/teams",
      "hooksUrl": "https://api.github.com/repos/togusafish/tachikomaio-_-stollen/hooks",
      "eventsUrl": "https://api.github.com/repos/togusafish/tachikomaio-_-stollen/events",
      "tagsUrl": "https://api.github.com/repos/togusafish/tachikomaio-_-stollen/tags",
      "languagesUrl": "https://api.github.com/repos/togusafish/tachikomaio-_-stollen/languages",
      "stargazersUrl": "https://api.github.com/repos/togusafish/tachikomaio-_-stollen/stargazers",
      "contributorsUrl": "https://api.github.com/repos/togusafish/tachikomaio-_-stollen/contributors",
      "subscribersUrl": "https://api.github.com/repos/togusafish/tachikomaio-_-stollen/subscribers",
      "subscriptionUrl": "https://api.github.com/repos/togusafish/tachikomaio-_-stollen/subscription",
      "mergesUrl": "https://api.github.com/repos/togusafish/tachikomaio-_-stollen/merges",
      "downloadsUrl": "https://api.github.com/repos/togusafish/tachikomaio-_-stollen/downloads",
      "createdAt": "2015-07-07T08:56:57.000Z",
      "updatedAt": "2015-07-07T08:56:57.000Z",
      "pushedAt": "2015-09-15T08:57:36.000Z",
      "gitUrl": "git://github.com/togusafish/tachikomaio-_-stollen.git",
      "sshUrl": "[email protected]:togusafish/tachikomaio-_-stollen.git",
      "cloneUrl": "https://github.com/togusafish/tachikomaio-_-stollen.git",
      "svnUrl": "https://github.com/togusafish/tachikomaio-_-stollen",
      "homepage": null,
      "size": 151,
      "stargazersCount": 0,
      "watchersCount": 0,
      "language": "CoffeeScript",
      "hasIssues": false,
      "hasDownloads": true,
      "hasWiki": true,
      "hasPages": false,
      "forksCount": 0,
      "mirrorUrl": null,
      "openIssuesCount": 0,
      "openIssues": 0,
      "watchers": 0,
      "defaultBranch": "master"
    }
  },
  "base": {
    "label": "tachikomaio:master",
    "ref": "master",
    "sha": "615663cd87e231457521a4911aa8cdfa6a083fd1",
    "user": {
      "login": "tachikomaio",
      "id": 7028851,
      "avatarUrl": "https://avatars.githubusercontent.com/u/7028851?v=3",
      "gravatarId": "",
      "url": "https://api.github.com/users/tachikomaio",
      "htmlUrl": "https://github.com/tachikomaio",
      "followersUrl": "https://api.github.com/users/tachikomaio/followers",
      "subscriptionsUrl": "https://api.github.com/users/tachikomaio/subscriptions",
      "organizationsUrl": "https://api.github.com/users/tachikomaio/orgs",
      "reposUrl": "https://api.github.com/users/tachikomaio/repos",
      "receivedEventsUrl": "https://api.github.com/users/tachikomaio/received_events",
      "type": "Organization"
    },
    "repo": {
      "id": 28075274,
      "name": "stollen",
      "fullName": "tachikomaio/stollen",
      "owner": {
        "login": "tachikomaio",
        "id": 7028851,
        "avatarUrl": "https://avatars.githubusercontent.com/u/7028851?v=3",
        "gravatarId": "",
        "url": "https://api.github.com/users/tachikomaio",
        "htmlUrl": "https://github.com/tachikomaio",
        "followersUrl": "https://api.github.com/users/tachikomaio/followers",
        "subscriptionsUrl": "https://api.github.com/users/tachikomaio/subscriptions",
        "organizationsUrl": "https://api.github.com/users/tachikomaio/orgs",
        "reposUrl": "https://api.github.com/users/tachikomaio/repos",
        "receivedEventsUrl": "https://api.github.com/users/tachikomaio/received_events",
        "type": "Organization"
      },
      "private": false,
      "htmlUrl": "https://github.com/tachikomaio/stollen",
      "description": "",
      "fork": false,
      "url": "https://api.github.com/repos/tachikomaio/stollen",
      "forksUrl": "https://api.github.com/repos/tachikomaio/stollen/forks",
      "teamsUrl": "https://api.github.com/repos/tachikomaio/stollen/teams",
      "hooksUrl": "https://api.github.com/repos/tachikomaio/stollen/hooks",
      "eventsUrl": "https://api.github.com/repos/tachikomaio/stollen/events",
      "tagsUrl": "https://api.github.com/repos/tachikomaio/stollen/tags",
      "languagesUrl": "https://api.github.com/repos/tachikomaio/stollen/languages",
      "stargazersUrl": "https://api.github.com/repos/tachikomaio/stollen/stargazers",
      "contributorsUrl": "https://api.github.com/repos/tachikomaio/stollen/contributors",
      "subscribersUrl": "https://api.github.com/repos/tachikomaio/stollen/subscribers",
      "subscriptionUrl": "https://api.github.com/repos/tachikomaio/stollen/subscription",
      "mergesUrl": "https://api.github.com/repos/tachikomaio/stollen/merges",
      "downloadsUrl": "https://api.github.com/repos/tachikomaio/stollen/downloads",
      "createdAt": "2014-12-16T07:15:46.000Z",
      "updatedAt": "2014-12-20T13:14:16.000Z",
      "pushedAt": "2015-09-15T08:57:38.000Z",
      "gitUrl": "git://github.com/tachikomaio/stollen.git",
      "sshUrl": "[email protected]:tachikomaio/stollen.git",
      "cloneUrl": "https://github.com/tachikomaio/stollen.git",
      "svnUrl": "https://github.com/tachikomaio/stollen",
      "homepage": null,
      "size": 496,
      "stargazersCount": 0,
      "watchersCount": 0,
      "language": "CoffeeScript",
      "hasIssues": true,
      "hasDownloads": true,
      "hasWiki": true,
      "hasPages": false,
      "forksCount": 1,
      "mirrorUrl": null,
      "openIssuesCount": 23,
      "openIssues": 23,
      "watchers": 0,
      "defaultBranch": "master"
    }
  },
  "Links": {
    "self": {
      "href": "https://api.github.com/repos/tachikomaio/stollen/pulls/39"
    },
    "html": {
      "href": "https://github.com/tachikomaio/stollen/pull/39"
    },
    "issue": {
      "href": "https://api.github.com/repos/tachikomaio/stollen/issues/39"
    },
    "comments": {
      "href": "https://api.github.com/repos/tachikomaio/stollen/issues/39/comments"
    },
    "reviewComments": {
      "href": "https://api.github.com/repos/tachikomaio/stollen/pulls/39/comments"
    },
    "reviewComment": {
      "href": "https://api.github.com/repos/tachikomaio/stollen/pulls/comments{/number}"
    },
    "commits": {
      "href": "https://api.github.com/repos/tachikomaio/stollen/pulls/39/commits"
    },
    "statuses": {
      "href": "https://api.github.com/repos/tachikomaio/stollen/statuses/e02cd7cab1e364c7cf469f9d7b7114af2a66c9e7"
    }
  },
  "bodyText": "Strategy david\nPowered by David Update as a Service - Tachikoma.io Announcement: 2015-06-28 Updated permissions - Tachikoma.io",
  "merged": false,
  "mergeable": true,
  "mergeableState": "clean",
  "mergedBy": null,
  "additions": 9,
  "deletions": 9,
  "changedFiles": 1
}

Use native promises before others

Now that ES 2015 is final it would be better to use native promises before any external libraries. https://github.com/philschatz/octokat.js/blob/master/src/helper-promise.coffee#L17

I happened to be using jquery promises without knowing it.

The following also didn't chain properly, it resolved with a promise not the values.. not surprising as jquery promises are very broken. It also does not allow me to use catch. Not very nice since that is a standard method on a promise now.

var staleBranchCutoff = new Date().getTime() - (1000 * 60 * 60 * 24 * 90); //90 days in milliseconds
var staleBranches = self.repository.branches.fetch().then(function(branches) {
  return Promise.all(branches.map(function(branch) {
    return self.repository.branches(branch.name).fetch().then(function(branchInfo) {
      var branchLastCommitDate = new Date(branchInfo.commit.commit.author.date).getTime();
      if (branchLastCommitDate < staleBranchCutoff) {
        return branchInfo;
      } else {
        return undefined;
      }
    });
  })).then(_.compact);
});

staleBranches.then(function(stale){
  console.log(stale) //logs a promise, not an array of branch information
})

I can either wrap this in a proper promise implementation (I use bluebird) or works if I manually edit the octokat code to not use jquery.

Basic how-to for in-browser?

Hi, I'm new to Javascript, and am trying to get a simple query running in the browser.

It looks like RequireJS is necessary because dist/octokat.js has the require statement. So I've installed octokat via bower, and downloaded requirejs. RequireJS is new to me, though, and has a ton of complexity. I'm trying to configure it, e.g.:

  <script data-main="bower_components/octokat/dist/octokat" src="require.js"></script>

and it's failing with:

Uncaught Error: Module name "plus" has not been loaded yet for context: _. Use require([])

So I see that there's plus.coffee in the src/ directory... what else should I do to simply get this working?

Thanks!

Parallel requests?

I'm wondering if there's a way to make these requests parallel instead of serial:

repo = github.repos('npm', 'newww')
repo.counts = {}
repo.pulls.fetch({per_page: 1})
  .then(function (pulls) {
    repo.counts.pulls = count(pulls)
    return repo.issues.fetch({per_page: 1})
  })
  .then(function (issues) {
    repo.counts.issues = count(issues)
    // GitHub API still includes PRs in /issues endpoints
    repo.counts.issues -= repo.counts.pulls
    return repo.contributors.fetch({per_page: 1})
  })
  .then(function (contributors) {
    repo.counts.contributors = count(contributors)
    console.log(repo.counts)
  })
  .catch(function (e) {
    console.error('oh noes', e)
  })

Run replacer on already fetched JSON data

I'm working with handling GitHub's webhooks and each payload contains JSON resource info on the resource changed by the event. It would be nice to be able to run the replacer on it without actually sending a request. Basically, I want to be able to fetch some other resources without having to construct them myself. I think this might be possible without changing anything, so any suggestions would be helpful.

Bump version to 1.0.0

This module has been around for a little while now, and people are using it. Bumping the version to 1.0.0 would help it play better with npm's semver range matchers.

Thank you!

Just wanted to say Thank you ๐Ÿ™

Your library is awesome! It's just fun to use the API with it and async await / Promise.coroutine
And the REPL link to also great!

I just finished with a flow of API calls with octocat which automate the whole pull request flow (changing, adding, removing files, forking a repo, create a new branch, apply the commits and send the pull request)

Just one thing where I'm not sure: Does the GitHub API support multiple file changes within one commit?

review_comments_url and review_comments overwrite each other

I'm not sure the best way to handle this, but pull requests have fields for both review_comments and review_comments_url. Since review_comments_url comes first, it is overwritten by review_comments. What is the best way to handle it? The same is true for comments.

The best fix I can think of is prefixing one of them with an _.

You can look at the diff here of a possible solution here: matthewbauer@c8719ab

fetch all issues

Hi,

Fetching issues is quite simple, but I cant seem to figure out how to get all (including closed) issues.
API equivalent: https://api.github.com/repos/user/repo/issues?state=all
I tried

REPO = octo.repos(repo)
REPO.issues.fetch() --> all open issues
REPO.issues.fetch({state: 'all'})
REPO.issues.fetch('state=all')
REPO.issues({state:'all'}).fetch()
REPO.issues('state=all').fetch()
REPO.issues.state('all').fetch()

Getting reference error on fetch if there is no response

I don't think this is a problem with ocotkat, but rather a problem with my implementation. But I'm not sure how else to diagnose this problem.

Here is my code, roughly:

return Promise.try(function () {
    return octo.notifications.fetch()
  }).each(function (repo) {
    // Do a lot of stuff
  }).catch(function (err) {
    console.log(err)
  })

If there are no notifications to fetch, I get this error:

/Users/richard/src/ignore-github-users/node_modules/octokat/dist/node/request.js:196
              return cb(null, jqXHR.responseText, status, jqXHR);
                                                  ^

ReferenceError: status is not defined
    at /Users/richard/src/ignore-github-users/node_modules/octokat/dist/node/request.js:196:51
    at xhr.onreadystatechange (/Users/richard/src/ignore-github-users/node_modules/octokat/dist/node/request.js:43:18)
    at dispatchEvent (/Users/richard/src/ignore-github-users/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:591:25)
    at setState (/Users/richard/src/ignore-github-users/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:610:14)
    at IncomingMessage.<anonymous> (/Users/richard/src/ignore-github-users/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:447:13)
    at emitNone (events.js:72:20)
    at IncomingMessage.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:905:12)
    at doNTCallback2 (node.js:450:9)
    at process._tickCallback (node.js:364:17)

Do you have any ideas what I might be doing wrong, here? Shouldn't the try catch the error, and log it? It doesn't. I am very confused.

Thank you so much.

Adding a member

Hey @philschatz, sorry to bug you again.

I'm trying to run PUT /teams/:id/members/:username on a GHE instance, by using:

octo.teams('153').members.add('aaa',cb) // or
octo.teams('153').members.add('aaa')

Team 153 exists and I can fetch it. I can also run the following in POSTMAN and it works if I do:

PUT https://GHEINSTANCE/api/v3/teams/153/members/aaa
DELETE https://GHEINSTANCE/api/v3/teams/153/members/aaa

I've checked the source and add maps to PUT so I'm not sure what I'm missing.

PS: All the help you give I will put back in help other octokat.js users and by providing as many PRs as I can.

Timeout large files (upstream error in xmlhttprequest?)

For large files I am getting an inconsistent uncaught error from xmlhttprequest - I can only guess that it is related to a timeout because sometimes it works, sometimes it doesn't.

See https://travis-ci.org/gmaclennan/ghfs.js/builds/52682152 failing build. Error:

/home/travis/build/gmaclennan/ghfs.js/node_modules/octokat/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:208
      && response.headers[header.toLowerCase()]
                 ^
TypeError: Cannot read property 'headers' of undefined
    at getResponseHeader (/home/travis/build/gmaclennan/ghfs.js/node_modules/octokat/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:208:18)
    at /home/travis/build/gmaclennan/ghfs.js/node_modules/octokat/dist/node/request.js:148:38
    at xhr.onreadystatechange (/home/travis/build/gmaclennan/ghfs.js/node_modules/octokat/dist/node/request.js:43:18)
    at dispatchEvent (/home/travis/build/gmaclennan/ghfs.js/node_modules/octokat/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:570:25)
    at setState (/home/travis/build/gmaclennan/ghfs.js/node_modules/octokat/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:589:14)
    at handleError (/home/travis/build/gmaclennan/ghfs.js/node_modules/octokat/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:514:5)
    at ClientRequest.errorHandler (/home/travis/build/gmaclennan/ghfs.js/node_modules/octokat/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:439:14)
    at ClientRequest.emit (events.js:95:17)
    at CleartextStream.socketErrorListener (http.js:1552:9)
    at CleartextStream.emit (events.js:95:17)

\u0000 appended in string returned from readBinary

I'm not sure if this is on GitHub's end or octokat but there is a null terminator code being appended to my content return from .readBinary(). Right now, I can just get rid of it, but I'm thinking it's an issue.

document how to specify parameters, such as when filtering repo issues

I found this clue here: #69 (comment), which got me going, but until then all my attempts were failures:

octo.repos('strongloop-internal', 'scrum-nodeops')                                             
//.issues({labels: inSprintLabels})                                                            
//.issues.parameters({labels: inSprintLabels})                                                 
//.issues.labels(inSprintLabels)                                                               
.issues.fetch({labels: inSprintLabels}, function(err, issues) { // <--- yeah!

Example request

First, let me thank you for your work here.

I was hoping you could provide an example of how to fork a repo?

I've tried:

octo.repos('OriginalOwner', 'OriginalRepo').forks('noeticpenguin').create();

issue property names don't match github API docs

I just got bit by something I mentioned in #75 (comment), and want to raise it as an issue.

octokat.js follows the github API very closely, many thumbs up, but it renames all the properties from snake case to camel case.... I just tried to filter out pull requests as stated in https://developer.github.com/v3/issues/#list-issues-for-a-repository, looking for the presence of pull_request, it didn't work. poked around a bit, saw it was called pullRequest...

Renaming seems idiosyncratic, like the github API naming or not, its still its API, and renaming things can be done in user code, if they want.

Issue on upload

When attempting to upload an asset release.upload("foo.txt", "adsfdas", "text/plain", bits), there's an issue when transfroming the url.

https://uploads.github.com/repos/chimon2000/test-hello-world/releases/1819396/assets{?name,label}

becomes

https://uploads.github.com/repos/chimon2000/test-hello-world/releases/1819396/assets?name,label=foo.txt

I'm running against the latest version of the GitHub API.

is there a way, give an issue.url, to update it?

I have an issue fetched from github, I have it's issue.url (for example, https://api.github.com/repos/some-org/a-repo/issues/990), and now I want to update it.

ATM, it looks like I need to do a url.parse(), then split the path, find some-org and a-repo by direct indexing into the path, and then I can call octo.repos('some-org', 'a-repo').issues(issue.number).update({labels: labels}, ....

I suspect that there is a better way, since I've already got the URL partially constructed, can you point me to it?

Octokat's Equivalent of Octokit's Issue Object

I've been attempting to update some code to use Octokat from Octokit and am not entirely sure how to proceed.

Right now, there's code such as this:

var issue = new Issue(repos[gameName].owner, repos[gameName].repo, issues.items[i].number);

and

issue.getComments().then(function(comments) {

and

issue.createComment(comment).then(function(data) {

Based on my understanding so far, the second one would become

issue.comments.fetch().then(function(comments) {

While the third one would become

issue.comments.create(comment).then(function(data) {

Is this correct?

Regarding the first line, where the Issue object is created, I'm not sure what that would become. I'm honestly not well versed in JavaScript.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.