 module.exports = class Github extends Base
 
   OAUTH_PROVIDER = 'github'
+  USER_AGENT     = 'Koding-Bridge'
 
   @trait __dirname, '../traits/protected'
 


  , (client, options, callback) ->

    { oauth: {foreignId}, user: {username} } = client.r

    gh = new GithubAPI
      version        : '3.0.0'
      debug          : true
      timeout        : 5000
      headers        :
        'user-agent' : 'Koding-Bridge'

    gh.authenticate
      type           : 'oauth'
      token          : foreignId

    gh.repos.getAll {}, (err, res) ->
      callback err, res


  @fetchContent = permit 'fetch content', success: revive

        fetchContent      :
          (signature Object, Function)

  initGithubFor = (client) ->

    { oauth: {token} } = client.r

    gh = new GithubAPI
      version        : '3.0.0'
      debug          : true
      timeout        : 5000
      headers        :
        'user-agent' : USER_AGENT

    gh.authenticate { type: 'oauth', token }

    return gh


  @listRepos = permit 'list repos', success: revive

