Skip to content

Commit

Permalink
use github access token for github import
Browse files Browse the repository at this point in the history
  • Loading branch information
yann300 committed Mar 1, 2019
1 parent ab29cfe commit 6f630a8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class App {
executionContext.init(self._components.config)
executionContext.listenOnLastBlock()

self._components.compilerImport = new CompilerImport()
self._components.compilerImport = new CompilerImport(() => { return self._components.config.get('settings/gist-access-token') })
registry.put({api: self._components.compilerImport, name: 'compilerimport'})
self._components.gistHandler = new GistHandler()

Expand Down
6 changes: 4 additions & 2 deletions src/app/compiler/compiler-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ var swarmgw = require('swarmgw')()
var request = require('request')

module.exports = class CompilerImports {
constructor () {
constructor (githubAccessToken) {
this.githubAccessToken = githubAccessToken || (() => {})
this.previouslyHandled = {} // cache import so we don't make the request at each compilation.
}

handleGithubCall (root, path, cb) {
var accessToken = this.githubAccessToken() ? '?access_token=' + this.githubAccessToken() : ''
return request.get(
{
url: 'https://api.github.com/repos/' + root + '/contents/' + path,
url: 'https://api.github.com/repos/' + root + '/contents/' + path + accessToken,
json: true
},
(err, r, data) => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/tabs/settings-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ module.exports = class SettingsTab {
self._view.gistToken = yo`
<div class="${css.info}">
<div class=${css.title}>Gist Access Token</div>
<div class="${css.crowNoFlex}">Manage the access token used to publish to Gist.</div>
<div class="${css.crowNoFlex}">Manage the access token used to publish to Gist and retrieve Github contents.</div>
<div class="${css.crowNoFlex}">Go to github token page (link below) to create a new token and save it in Remix. Make sure this token has only 'create gist' permission.</div>
<div class="${css.crowNoFlex}"><a target="_blank" href="https://github.com/settings/tokens">https://github.com/settings/tokens</a></div>
<div class="${css.crowNoFlex}">${self._view.gistToken}</div>
Expand Down

0 comments on commit 6f630a8

Please sign in to comment.