Skip to content

use follow-redirects #284

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 1 commit into from
May 29, 2016
Merged

Conversation

jamestalmage
Copy link

Swaps vanilla http / https for follow-redirets.

Tests appear to be about the same amount of broken with/without my changes.

Fixes #257

People can install this modified version via:

$ npm install jamestalmage/node-github#follow-redirects

@paazmaya
Copy link

I tried to use this PR in my setup which tries to fetch a file from a moved GitHub repository, but the behaviour is the same as before, there is no redirection.
Are there some specific headers that needs to be set or am I missing something else?

@paazmaya
Copy link

var GitHub = require('github'); // https://github.com/mikedeboer/node-github
// please note that using https://github.com/jamestalmage/node-github
// until https://github.com/mikedeboer/node-github/issues/257 gets fixed

var GH_TOKEN = process.env.GP_GH_TOKEN;

var gh = new GitHub({
  version: '3.0.0',
  protocol: 'https',
  host: 'api.github.com',
  timeout: 2000,
  headers: {
    'user-agent': 'FORK WHEN NO LICENSE - Agent'
  }
});

gh.authenticate({
  type: 'oauth',
  token: GH_TOKEN
});

gh.repos.getContent({
  user: 'mikeal',
  repo: 'forever-agent',
  path: 'package.json'
}, function(error, result) {
  if (error) {
    console.log(error);
  }
  else {
    if (result.content) {
      var json = new Buffer(result.content, 'base64');

      var data = null;
      try {
        data = JSON.parse(json.toString());
      }
      catch (error) {
        console.error('Failed to parse the received JSON. ' + error);
      }
      console.log(data);
    }
    else if (result.meta && result.meta.location) {
      console.log('This project seems to have been moved to ' + result.meta.location);
    }
  }
});

The given repository mikeal/forever-agent seems to have been moved to request/forever-agent.

@jamestalmage
Copy link
Author

@paazmaya I just ran your code, and got the following:

Using npm install github@latest:

This project seems to have been moved to https://api.github.com/repositories/8509819/contents/package.json?access_token=REDACTED

using npm install jamestalmage/node-github#follow-redirects

{ author: 'Mikeal Rogers <[email protected]> (http://www.futurealoof.com)',
  name: 'forever-agent',
  description: 'HTTP Agent that keeps socket connections alive between keep-alive requests. Formerly part of mikeal/request, now a standalone module.',
  version: '0.6.1',
  license: 'Apache-2.0',
  repository: { url: 'https://github.com/mikeal/forever-agent' },
  main: 'index.js',
  dependencies: {},
  devDependencies: {},
  optionalDependencies: {},
  engines: { node: '*' } }

I noticed this comment in your code:

using https://github.com/jamestalmage/node-github until ...

Just want to make sure you are installing the correct branch (you need to add #follow-redirects suffix).

$ npm install jamestalmage/node-github#follow-redirects

@paazmaya
Copy link

@jamestalmage thank you for finding the reason why it did not work. I was indeed using the masterbranch

@tarmolov
Copy link

your branch works fine for me. Any news where the pull will be merged?

@tarmolov
Copy link

🆙

@kaizensoze kaizensoze merged commit 552a4a3 into octokit:master May 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants