From b66379a8c8fe1ca6acab260b307e6df4b05c3f0e Mon Sep 17 00:00:00 2001 From: Soumya Ray Date: Mon, 13 Nov 2017 08:10:54 +0800 Subject: [PATCH] Upcase env vars and add codeship badge --- README.md | 28 ++++++++++++++++++++ Rakefile | 4 +-- config/app.yml | 8 +++--- config/environment.rb | 2 +- config/secrets.yml.example | 4 +-- domain/blame_reporter/blame_report.rb | 2 +- domain/github_mappers/collaborator_mapper.rb | 2 +- domain/github_mappers/repo_mapper.rb | 2 +- infrastructure/github/github_api.rb | 4 +-- spec/github_spec.rb | 2 +- spec/spec_helper.rb | 2 +- 11 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..6b9c08f --- /dev/null +++ b/README.md @@ -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 git@github.com: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) diff --git a/Rakefile b/Rakefile index fa81c43..ae64615 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/config/app.yml b/config/app.yml index f6bcb71..ea145c5 100644 --- a/config/app.yml +++ b/config/app.yml @@ -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 \ No newline at end of file + DB_FILENAME: infrastructure/database/test.db + REPOSTORE_PATH: infrastructure/gitrepo/repostore \ No newline at end of file diff --git a/config/environment.rb b/config/environment.rb index da472f7..ffd1f2f 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -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 diff --git a/config/secrets.yml.example b/config/secrets.yml.example index a3034f7..6838924 100644 --- a/config/secrets.yml.example +++ b/config/secrets.yml.example @@ -1,6 +1,6 @@ --- development: - gh_token: + GH_TOKEN: test: - gh_token: \ No newline at end of file + GH_TOKEN: \ No newline at end of file diff --git a/domain/blame_reporter/blame_report.rb b/domain/blame_reporter/blame_report.rb index bce16a9..9eba5e1 100644 --- a/domain/blame_reporter/blame_report.rb +++ b/domain/blame_reporter/blame_report.rb @@ -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 diff --git a/domain/github_mappers/collaborator_mapper.rb b/domain/github_mappers/collaborator_mapper.rb index 7a9f426..77f5aa2 100644 --- a/domain/github_mappers/collaborator_mapper.rb +++ b/domain/github_mappers/collaborator_mapper.rb @@ -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) diff --git a/domain/github_mappers/repo_mapper.rb b/domain/github_mappers/repo_mapper.rb index c272130..c3cb70d 100644 --- a/domain/github_mappers/repo_mapper.rb +++ b/domain/github_mappers/repo_mapper.rb @@ -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) diff --git a/infrastructure/github/github_api.rb b/infrastructure/github/github_api.rb index fb68b96..571f9c7 100644 --- a/infrastructure/github/github_api.rb +++ b/infrastructure/github/github_api.rb @@ -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) @@ -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 diff --git a/spec/github_spec.rb b/spec/github_spec.rb index dba944f..c523099 100644 --- a/spec/github_spec.rb +++ b/spec/github_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 89c6c00..ad89c12 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 } c.filter_sensitive_data('') { CGI.escape(github_token) } end