Skip to content
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

Small fixes #36

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ So, here the story begins...
- Rest a little and feel proud of yourself that you've done your first open-source contribution!

### Want to join us?
[Join us in slack!](https://join.slack.com/t/findopensourc-prt7834/shared_invite/enQtNzQ5MTIyMzU4NTgzLTg5MGYwMTdhYWIzMGE4ZDc5ZWRlMWI1YTEyNjAzN2ZjNTc4NmMzMjI2NmYzM2U5NTEyMDI2ZTk0MGVhNWU1ZDk)
Join us in Slack and let us know what you would like to work on (even if there's no issue for that!):
[Join us in slack!](https://join.slack.com/t/open-source-mentor/shared_invite/enQtODAwOTkzODcxOTA1LTllODUyMzcxZTk4MmZjZWFhM2IxOTUzYTU5N2UwNmFlNDhmY2MxOGM0NjA3OTBlMzIxNTYzNGJiYzU0ODQzZjE)

41 changes: 11 additions & 30 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class ProjectsController < ApplicationController
before_action :authenticate_user!
before_action :authorize!, only: %i[edit update destroy]
before_action :current_project, only: %i[show edit update destroy]
# before_action :repo, only: %i[edit update destroy]
# before_action :repos, only: %i[edit update destroy]
before_action :fetch_repo_by_name, only: %i[new edit create]
after_action :fetch_repos, only: %i[new edit create]

def index
@projects = Project.all
Expand All @@ -17,44 +17,18 @@ def show; end

def new
@project = Project.new
@repos = repos
@repo = repo
end

def repos
@client = Octokit::Client.new
@github_user = @client.user(current_user.nickname)
@repos = @client.repos(@github_user.login, query: { type: 'owner', sort: 'asc' })
end

def repo
@repos.map(&:name)
end

def edit
current_project
@repos = repos
@repo = repo
end

def repo
@repos.map {|r| r.name }
end

def edit; end

def create
@project = Project.new(project_params)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some variables are initalized inside the method, some of them outside?
Keep one style:

@project =
@repos =

Instead of doing a mix

@project =
fetch_repos

It will make it easier to read your code

@repos = repos
@repo = repo

respond_to do |format|
if @project.save
format.html { redirect_to @project, notice: 'Project was successfully created.' }
format.json { render :show, status: :created, location: @project }
else
format.html { render :new }
format.json { render json: @project.errors, status: :unprocessable_entity }
end
end
end
Expand All @@ -73,20 +47,27 @@ def destroy
@project.destroy
respond_to do |format|
format.html { redirect_to projects_url, notice: 'Project was successfully destroyed.' }
format.json { head :no_content }
end
end

private

def fetch_repos
@repos = ::Project::FetchRepos.call(current_user)
end

def fetch_repo_by_name
@repo = fetch_repos.map(&:name)
end

def current_project
@project = Project.find(params[:id])
end

def project_params
params.require(:project).permit!
end

def authorize!
current_project
authorize(@project || Project)
Expand Down
10 changes: 10 additions & 0 deletions app/helpers/callable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module Callable
extend ActiveSupport::Concern
class_methods do
def call(*args)
new(*args).call
end
end
end
27 changes: 27 additions & 0 deletions app/services/project/fetch_repos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

class Project
class FetchRepos
include Callable

attr_reader :current_user

def initialize(current_user)
@current_user = current_user
end

def call
client.repos(github_user.login, query: { type: 'owner', sort: 'asc' })
end

private

def client
Octokit::Client.new
end

def github_user
client.user(current_user.nickname)
end
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<% if user_signed_in? %>
<%= link_to 'Sign Out', destroy_user_session_path, method: :delete, class: "nav-link" %>
<% else %>
<%= link_to "Sign in with Github", user_github_omniauth_authorize_path, class: "nav-link" %>
<%= link_to "Sign in with Github", root_path, class: "nav-link" %>
<% end %>
</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/views/welcome/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<main role="main">
<main role="main">
<section class="jumbotron text-center">
<div class="container">
<h1 class="jumbotron-heading">Find OpenSource Mentor</h1>
Expand Down