Skip to content

Commit

Permalink
Upcase env vars and add codeship badge
Browse files Browse the repository at this point in the history
  • Loading branch information
soumyaray committed Nov 13, 2017
1 parent 6ee6a62 commit b66379a
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 16 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# CodePraise

Web API for the CodePraise application

[ ![Codeship Status for soumyaray/code_praise](https://app.codeship.com/projects/b454db90-a9c0-0135-3b68-622b0705736a/status?branch=master)](https://app.codeship.com/projects/256400)
---

## Routes

Our API is rooted at `/api/v0.1/` and has the following subroutes:
- `GET repo` – Index of all repos stored
- `GET repo/ownername/reponame` - Fetch metadata of a previously stored repo
- `POST repo/ownername/reponame` - Load a repo from Github and store metadata in API

## Setup

To setup and test this API on your own machine:

```
$ git clone [email protected]:soumyaray/code_praise.git
$ cd code_praise
$ bundle install
$ bundle exec rake db:migrate
$ RACK_ENV=test bundle exec rake db:migrate
$ bundle exec rake spec
```

You may have to add your Github developer token to `config/secrets.yml` (see example in folder)
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace :db do
return
end

FileUtils.rm(app.config.db_filename)
puts "Deleted #{app.config.db_filename}"
FileUtils.rm(app.config.DB_FILENAME)
puts "Deleted #{app.config.DB_FILENAME}"
end
end
8 changes: 4 additions & 4 deletions config/app.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
development:
db_filename: infrastructure/database/dev.db
repostore_path: infrastructure/gitrepo/repostore
DB_FILENAME: infrastructure/database/dev.db
REPOSTORE_PATH: infrastructure/gitrepo/repostore

test:
db_filename: infrastructure/database/test.db
repostore_path: infrastructure/gitrepo/repostore
DB_FILENAME: infrastructure/database/test.db
REPOSTORE_PATH: infrastructure/gitrepo/repostore
2 changes: 1 addition & 1 deletion config/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def self.reload!
end

configure :development, :test do
ENV['DATABASE_URL'] = 'sqlite://' + config.db_filename
ENV['DATABASE_URL'] = 'sqlite://' + config.DB_FILENAME
end

configure :production do
Expand Down
4 changes: 2 additions & 2 deletions config/secrets.yml.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
development:
gh_token: <personal token for Github API>
GH_TOKEN: <personal token for Github API>

test:
gh_token: <personal token for Github API>
GH_TOKEN: <personal token for Github API>
2 changes: 1 addition & 1 deletion domain/blame_reporter/blame_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Summary

def initialize(repo, config = CodePraise::Api.config)
origin = Git::RemoteRepo.new(repo.git_url)
@local = Git::LocalRepo.new(origin, config.repostore_path)
@local = Git::LocalRepo.new(origin, config.REPOSTORE_PATH)
@blame_reports = Blame::Report.new(@local)
end

Expand Down
2 changes: 1 addition & 1 deletion domain/github_mappers/collaborator_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CollaboratorMapper
def initialize(config, gateway_class = Github::Api)
@config = config
@gateway_class = gateway_class
@gateway = @gateway_class.new(@config.gh_token)
@gateway = @gateway_class.new(@config.GH_TOKEN)
end

def load_several(url)
Expand Down
2 changes: 1 addition & 1 deletion domain/github_mappers/repo_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RepoMapper
def initialize(config, gateway_class = Github::Api)
@config = config
@gateway_class = gateway_class
@gateway = @gateway_class.new(@config.gh_token)
@gateway = @gateway_class.new(@config.GH_TOKEN)
end

def find(owner_name, repo_name)
Expand Down
4 changes: 2 additions & 2 deletions infrastructure/github/github_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def response_or_error
end

def initialize(token)
@gh_token = token
@GH_TOKEN = token
end

def repo_data(username, repo_name)
Expand All @@ -54,7 +54,7 @@ def self.repo_path(path)

def call_gh_url(url)
response = HTTP.headers('Accept' => 'application/vnd.github.v3+json',
'Authorization' => "token #{@gh_token}")
'Authorization' => "token #{@GH_TOKEN}")
.get(url)
Response.new(response).response_or_error
end
Expand Down
2 changes: 1 addition & 1 deletion spec/github_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
it 'SAD: should raise exception when unauthorized' do
proc do
require 'ostruct'
sad_config = OpenStruct.new(gh_token: 'sad_token')
sad_config = OpenStruct.new(GH_TOKEN: 'sad_token')
repo_mapper = CodePraise::Github::RepoMapper.new(sad_config)
repo_mapper.find(USERNAME, REPO_NAME)
end.must_raise CodePraise::Github::Api::Errors::Unauthorized
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
c.cassette_library_dir = CASSETTES_FOLDER
c.hook_into :webmock

github_token = app.config.gh_token
github_token = app.config.GH_TOKEN
c.filter_sensitive_data('<GITHUB_TOKEN>') { github_token }
c.filter_sensitive_data('<GITHUB_TOKEN_ESC>') { CGI.escape(github_token) }
end
Expand Down

0 comments on commit b66379a

Please sign in to comment.