Skip to content

Commit

Permalink
rename pull requests to proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
Floppy committed Jul 26, 2016
1 parent f5cfae5 commit 60336a1
Show file tree
Hide file tree
Showing 25 changed files with 962 additions and 92 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end
task :update do
require_relative 'votebot'
User.update_all_from_github!
PullRequest.recreate_all_from_github!
Proposal.recreate_all_from_github!
end

unless ENV['RACK_ENV'] == 'production'
Expand Down
2 changes: 1 addition & 1 deletion app/models.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative 'models/user'
require_relative 'models/vote_counter'
require_relative 'models/pull_request'
require_relative 'models/proposal'
require_relative 'models/interaction'
4 changes: 2 additions & 2 deletions app/models/interaction.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class Interaction < ActiveRecord::Base

belongs_to :user
belongs_to :pull_request
belongs_to :proposal

validates :user, presence: true
validates :pull_request, presence: true
validates :proposal, presence: true

validates :last_vote, inclusion: {in: %w(agree disagree abstain), allow_nil: true}

Expand Down
6 changes: 3 additions & 3 deletions app/models/pull_request.rb → app/models/proposal.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'octokit'
require 'json'

class PullRequest < ActiveRecord::Base
class Proposal < ActiveRecord::Base

include VoteCounter

Expand All @@ -19,14 +19,14 @@ class PullRequest < ActiveRecord::Base
end

def self.recreate_all_from_github!
PullRequest.delete_all
Proposal.delete_all
Octokit.pull_requests(ENV['GITHUB_REPO'], state: "all").each do |pr|
create_from_github!(pr["number"])
end
end

def self.create_from_github!(number)
pr = PullRequest.find_or_create_by!(number: number)
pr = Proposal.find_or_create_by!(number: number)
pr.count_votes!
pr
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class User < ActiveRecord::Base

has_many :interactions, dependent: :destroy
has_many :participating, through: :interactions, source: :pull_request
has_many :participating, through: :interactions, source: :proposal

validates :login, presence: true, uniqueness: true
validates :avatar_url, presence: true
Expand All @@ -23,8 +23,8 @@ def update_github_contributor_status
self.contributor = !@contributors.find{|x| x.login == login}.nil?
end

def state(pr)
interactions.find_by(pull_request: pr).try(:state)
def state(proposal)
interactions.find_by(proposal: proposal).try(:state)
end

def self.update_all_from_github!
Expand Down
26 changes: 0 additions & 26 deletions app/views/_pr_list.erb

This file was deleted.

26 changes: 26 additions & 0 deletions app/views/_proposal_list.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<table class='table vote-list'>
<tr>
<th class="text-center">State</th>
<th>Title</th>
<th>View</th>
<th class="text-center">Participants</th>
<th class="text-center">Age</th>
<th class="text-center"><%= state_image('agree')%></th>
<th class="text-center"><%= state_image('abstain')%></th>
<th class="text-center"><%= state_image('disagree')%></th>
<th class="text-center">Proposer</th>
</tr>
<% proposals.each do |proposal| %>
<tr class='<%= row_class(proposal) %>'>
<td class="text-center"><span class='label label-<%= row_class(proposal) %>'><%= proposal.state.capitalize %></span></td>
<td><a href='/<%= proposal.number %>'><%= proposal.title %></a></td>
<td class="text-center"><a href='http://github.com/openpolitics/manifesto/pull/<%= proposal.number %>'>#<%= proposal.number %></a></td>
<td class="text-center"><%= proposal.participants.count %></td>
<td class="text-center"><%= proposal.age %> days</td>
<td class="text-center"><%= proposal.agree.count %></td>
<td class="text-center"><%= proposal.abstain.count %></td>
<td class="text-center"><%= proposal.disagree.count %></td>
<td class="proposer text-center"><%= partial :person, locals: {person: proposal.proposer } %></td>
</tr>
<% end %>
</table>
8 changes: 4 additions & 4 deletions app/views/index.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1>Open Votes</h1>
<h1>Open Proposals</h1>

<%= partial :pr_list, locals: {pull_requests: @pull_requests} %>
<%= partial :proposal_list, locals: {proposals: @open_proposals} %>

<h1>Closed Votes</h1>
<h1>Closed Proposals</h1>

<%= partial :pr_list, locals: {pull_requests: @closed} %>
<%= partial :proposal_list, locals: {proposals: @closed_proposals} %>
32 changes: 16 additions & 16 deletions app/views/show.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<ol class="breadcrumb">
<li><a href="/">All Votes</a></li>
<li class="active">#<%= @pull_request.number %></li>
<li><a href="/">All Proposals</a></li>
<li class="active">#<%= @proposal.number %></li>
</ol>

<h1><%= @pull_request.title %> <a href='http://github.com/openpolitics/manifesto/pull/<%= @pull_request.number %>'><i class='fa fa-github'></i></a></h1>
<h1><%= @proposal.title %> <a href='http://github.com/openpolitics/manifesto/pull/<%= @proposal.number %>'><i class='fa fa-github'></i></a></h1>

<div class='row'>
<div class='col-md-12'>
<p>
by <a href='/users/<%= @pull_request.proposer %>'><%= @pull_request.proposer.login %></a>
by <a href='/users/<%= @proposal.proposer %>'><%= @proposal.proposer.login %></a>
</p>
<h2><span class='label label-<%= row_class(@pull_request) %>'><%= @pull_request.state.capitalize %></span></h2>
<h2><span class='label label-<%= row_class(@proposal) %>'><%= @proposal.state.capitalize %></span></h2>
</div>
</div>

Expand All @@ -20,8 +20,8 @@
<p>
This page is currently just a utility page for showing a summary of voting
activity. To read change details, comment, or vote, please
<a href='http://github.com/openpolitics/manifesto/pull/<%= @pull_request.number %>'>
visit the GitHub pull request page.
<a href='http://github.com/openpolitics/manifesto/pull/<%= @proposal.number %>'>
visit the GitHub page for this proposal.
</a>
</p>
</div>
Expand All @@ -32,10 +32,10 @@
<div class='panel panel-success agree'>
<div class="panel-heading">
<%= state_image('agree')%>
Agree: <%= @pull_request.agree.count %>
Agree: <%= @proposal.agree.count %>
</div>
<div class='panel-body'>
<%= partial :person, collection: @pull_request.agree.map{|v| v.user} %>
<%= partial :person, collection: @proposal.agree.map{|v| v.user} %>
</div>
</div>
</div>
Expand All @@ -44,10 +44,10 @@
<div class='panel panel-info abstain'>
<div class="panel-heading">
<%= state_image('abstain')%>
Abstaining: <%= @pull_request.abstain.count %>
Abstaining: <%= @proposal.abstain.count %>
</div>
<div class='panel-body'>
<%= partial :person, collection: @pull_request.abstain.map{|v| v.user} %>
<%= partial :person, collection: @proposal.abstain.map{|v| v.user} %>
</div>
</div>
</div>
Expand All @@ -56,10 +56,10 @@
<div class='panel panel-danger disagree'>
<div class="panel-heading">
<%= state_image('disagree')%>
Disagree: <%= @pull_request.disagree.count %>
Disagree: <%= @proposal.disagree.count %>
</div>
<div class='panel-body'>
<%= partial :person, collection: @pull_request.disagree.map{|v| v.user} %>
<%= partial :person, collection: @proposal.disagree.map{|v| v.user} %>
</div>
</div>
</div>
Expand All @@ -70,17 +70,17 @@
<div class='col-md-12'>
<div class='panel panel-default participants'>
<div class="panel-heading">
Participants: <%= @pull_request.participants.count %>
Participants: <%= @proposal.participants.count %>
</div>
<div class='panel-body'>
<%= partial :person, collection: @pull_request.participants %>
<%= partial :person, collection: @proposal.participants %>
<div>
</div>
</div>
</div>

<div style='margin-top: 30px'>
<form action='/<%= @pull_request.number %>/update' method='POST'>
<form action='/<%= @proposal.number %>/update' method='POST'>
<button type='submit' class='btn btn-warning'>Update</button>
</form>
</div>
4 changes: 2 additions & 2 deletions app/views/user.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ title='<%= @user.login %>' />

<h2 style='clear: right'>Not voted on yet:</h2>

<%= partial :pr_list, locals: {pull_requests: @not_voted} %>
<%= partial :proposal_list, locals: {proposals: @not_voted} %>

<h2>Voted on (<%= @voted.count %>):</h2>

Expand All @@ -40,4 +40,4 @@ title='<%= @user.login %>' />

<h2>Proposed (<%= @proposed.count %>):</h2>

<%= partial :pr_list, locals: {pull_requests: @proposed} %>
<%= partial :proposal_list, locals: {proposals: @proposed} %>
2 changes: 1 addition & 1 deletion db/migrate/20160725063104_create_pull_requests.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreatePullRequests < ActiveRecord::Migration[5.0]
class CreateProposals < ActiveRecord::Migration[5.0]
def change
create_table :pull_requests do |t|
t.integer :number, null: false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class RenamePullRequestsToProposals < ActiveRecord::Migration
def change
rename_table :pull_requests, :proposals
rename_column :interactions, :pull_request_id, :proposal_id
end
end
16 changes: 8 additions & 8 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160726133704) do
ActiveRecord::Schema.define(version: 20160726142431) do

create_table "interactions", force: :cascade do |t|
t.integer "user_id", null: false
t.integer "pull_request_id", null: false
t.integer "user_id", null: false
t.integer "proposal_id", null: false
t.string "last_vote"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["pull_request_id"], name: "index_interactions_on_pull_request_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["proposal_id"], name: "index_interactions_on_proposal_id"
t.index ["user_id"], name: "index_interactions_on_user_id"
end

create_table "pull_requests", force: :cascade do |t|
create_table "proposals", force: :cascade do |t|
t.integer "number", null: false
t.string "state", null: false
t.string "title", null: false
t.integer "proposer_id", null: false
t.datetime "opened_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["proposer_id"], name: "index_pull_requests_on_proposer_id"
t.index ["proposer_id"], name: "index_proposals_on_proposer_id"
end

create_table "users", force: :cascade do |t|
Expand Down
Loading

0 comments on commit 60336a1

Please sign in to comment.