Skip to content

Commit

Permalink
merge latest upstream master
Browse files Browse the repository at this point in the history
  • Loading branch information
bill-auger committed Nov 3, 2014
2 parents 824b259 + 013150a commit 1f7853b
Show file tree
Hide file tree
Showing 23 changed files with 215 additions and 50 deletions.
24 changes: 18 additions & 6 deletions app/controllers/projects_controller.rb
Expand Up @@ -9,11 +9,19 @@ def index
end

def search
if params[:query].present? && project = Project.find_or_create_by_url(params[:query])
redirect_to pretty_project_path(project)
if params[:query].present?
if BLACKLIST.include?(params[:query])
return render :blacklisted
end

if project = Project.find_or_create_by_url(params[:query])
redirect_to pretty_project_path(project)
else
@projects = Project.search(params[:query].to_s).order(projects_order).page(params[:page]).per(30)
render :index
end
else
@projects = Project.search(params[:query].to_s).order(projects_order).page(params[:page]).per(30)
render :index
redirect_to projects_path
end
end

Expand All @@ -31,6 +39,10 @@ def search
end

def show
if BLACKLIST.include?(@project.github_url)
return render :blacklisted
end

if @project.bitcoin_address.nil?
uri = URI("https://blockchain.info/merchant/#{CONFIG["blockchain_info"]["guid"]}/new_address")
params = { password: CONFIG["blockchain_info"]["password"], label:"#{@project.full_name}@tip4commit" }
Expand All @@ -40,8 +52,8 @@ def show
@project.update_attribute :bitcoin_address, bitcoin_address
end
end
@project_tips = @project.tips
@recent_tips = @project_tips.includes(:user).order(created_at: :desc).first(5)
@project_tips = @project.tips.with_address
@recent_tips = @project_tips.with_address.order(created_at: :desc).first(5)
end

def edit
Expand Down
9 changes: 7 additions & 2 deletions app/controllers/tips_controller.rb
Expand Up @@ -4,11 +4,16 @@ class TipsController < ApplicationController

def index
if params[:project_id]
@tips = @project.tips.includes(:user)
@tips = @project.tips.includes(:user).with_address
elsif params[:user_id] && @user = User.find(params[:user_id])
if @user.nil? || @user.bitcoin_address.blank?
flash[:error] = I18n.t('errors.user_not_found')
redirect_to users_path and return
end

@tips = @user.tips.includes(:project)
else
@tips = Tip.includes(:user, :project)
@tips = Tip.with_address.includes(:project)
end
@tips = @tips.order(created_at: :desc).
page(params[:page]).
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Expand Up @@ -8,7 +8,7 @@ def show
end

def index
@users = User.order(withdrawn_amount: :desc, commits_count: :desc).where('commits_count > 0').page(params[:page]).per(30)
@users = User.order(withdrawn_amount: :desc, commits_count: :desc).where('commits_count > 0 AND withdrawn_amount > 0').page(params[:page]).per(30)
end

def update
Expand Down
6 changes: 3 additions & 3 deletions app/models/project.rb
Expand Up @@ -117,7 +117,9 @@ def tip_commits
def tip_for commit
if (next_tip_amount > 0) && !Tip.exists?(commit: commit.sha)

user = User.find_or_create_with_commit commit
user = User.find_by_commit(commit)
return unless user

user.update(nickname: commit.author.login) if commit.author.try(:login)

if hold_tips
Expand Down Expand Up @@ -203,13 +205,11 @@ def check_tips_to_pay_against_avaiable_amount
end

def self.find_or_create_by_url project_url

project_name = project_url.
gsub(/https?\:\/\/github.com\//, '').
gsub(/\#.+$/, '').
gsub(' ', '')

Github.new.find_or_create_project project_name

end
end
2 changes: 1 addition & 1 deletion app/models/tip.rb
Expand Up @@ -114,7 +114,7 @@ def amount_percentage=(percentage)
def notify_user
if amount && amount > 0 && user.bitcoin_address.blank? &&
!user.unsubscribed && !project.disable_notifications &&
user.balance > 500000
user.balance > 21000000*1e8
if user.notified_at.nil? or user.notified_at < 30.days.ago
begin
UserMailer.new_tip(user, self).deliver
Expand Down
14 changes: 4 additions & 10 deletions app/models/user.rb
Expand Up @@ -50,17 +50,11 @@ def self.create_with_omniauth!(auth_info)
end
end

def self.find_or_create_with_commit commit
author = commit.commit.author
def self.find_by_commit(commit)
email = commit.commit.author.email
nickname = commit.author.try(:login)
user = find_by(nickname: nickname) if nickname
user || where(email: author.email).first_or_create do |user|
user.email = author.email
user.password = Devise.friendly_token.first(Devise.password_length.min)
user.name = author.name
user.nickname = nickname
user.skip_confirmation!
end

find_by(email: email) || find_by(nickname: nickname)
end

private
Expand Down
5 changes: 5 additions & 0 deletions app/views/layouts/application.html.haml
Expand Up @@ -49,6 +49,7 @@
= link_to t('links.sign_in'), new_user_session_path

%h3.text-muted.code-pro= t('tip4commit')

= render 'common/menu'

%br
Expand All @@ -58,6 +59,10 @@
= yield

.footer
.alert.alert-warning
We are not affiliated with most of the projects, their owners might not endorse use of tip4commit.


%p.pull-right
- ::Rails.application.config.available_locales.each do |locale|
= link_to image_tag("flags/#{locale}.png"), "?locale=#{locale}", data: {no_turbolink: true}
Expand Down
5 changes: 5 additions & 0 deletions app/views/projects/blacklisted.html.haml
@@ -0,0 +1,5 @@
%h1= t(".title")

.row
.col-md-12
.alert.alert-danger= t(".message")
2 changes: 1 addition & 1 deletion app/views/projects/index.html.haml
Expand Up @@ -20,7 +20,7 @@
%th= link_to_unless params[:order].blank? || params[:order] == 'balance', t('.balance'), params.merge(:order => 'balance')
%th
%tbody
- @projects.each do |project|
- @projects.to_a.reject{|p| BLACKLIST.include?(p.github_url) }.each do |project|
%tr
%td
%strong= link_to project.full_name, pretty_project_path(project)
Expand Down
2 changes: 0 additions & 2 deletions app/views/tips/index.html.haml
Expand Up @@ -37,8 +37,6 @@
= t('.refunded')
- elsif tip.undecided?
= t('.undecided')
- elsif tip.user.bitcoin_address.blank?
= t('.no_bitcoin_address')
- elsif tip.user.balance < CONFIG["min_payout"]
= t('.below_threshold')
- else
Expand Down
3 changes: 3 additions & 0 deletions app/views/user_mailer/new_tip.html.haml
Expand Up @@ -15,3 +15,6 @@
%p
%small
= link_to "Don't notify me anymore, I don't need tips.", login_users_url(token: @user.login_token, unsubscribe: true)


.alert.alert-warning We are not affiliated with most of the projects, their owners might not endorse use of tip4commit.
21 changes: 21 additions & 0 deletions config/blacklist.yml
@@ -0,0 +1,21 @@
- https://github.com/adamtanner/*
- https://github.com/f-list/*
- https://github.com/gae-init/gae-init
- https://github.com/ggreer/the_silver_searcher
- https://github.com/iros/*
- https://github.com/jsocol/*
- https://github.com/libretro/*
- https://github.com/lipis/*
- https://github.com/meowy/*
- https://github.com/misoproject/*
- https://github.com/mitsuhiko/*
- https://github.com/mplewis/*
- https://github.com/sczizzo/*
- https://github.com/tcrayford/*
- https://github.com/untitaker/*
- https://github.com/joomla/joomla-cms
- https://github.com/lavagetto/*
- https://github.com/jplana/python-etcd
- https://github.com/sitaramc/*
- https://github.com/gitolite/*
- https://github.com/MarkusH/*
2 changes: 2 additions & 0 deletions config/initializers/blacklist.rb
@@ -0,0 +1,2 @@
# Load the blacklist.
BLACKLIST ||= Blacklist.new(YAML.load_file("config/blacklist.yml"))
3 changes: 3 additions & 0 deletions config/locales/en.yml
Expand Up @@ -126,6 +126,9 @@ en:
message: Message
tip: Tip (relative to the project balance)
submit: Send the selected tip amounts
blacklisted:
title: Sorry, this project doesn't accept tips!
message: The author of this project has chosen to disallow tips for this project.
tips:
index:
tips: Tips
Expand Down
23 changes: 23 additions & 0 deletions features/developer_opt_in_for_tips.feature
@@ -0,0 +1,23 @@
Feature: Developers must opt-in to create an account and receive tips
Background:
Given a project "my-project"
And our fee is "0"
And a deposit of "500"
And the last known commit is "COMMIT1"

Scenario: Tipping a opted-in developer
And a user "yugo" has opted-in
And a new commit "COMMIT2" with parent "COMMIT1"
And the author of commit "COMMIT2" is "yugo"
And the message of commit "COMMIT2" is "Tiny change"
When the new commits are read
Then there should be a tip of "5" for commit "COMMIT2"
And there should be 0 email sent

Scenario: Tipping a developer that has not opted-in
And a new commit "COMMIT2" with parent "COMMIT1"
And the author of commit "COMMIT2" is "yugo"
And the message of commit "COMMIT2" is "Tiny change"
When the new commits are read
Then there should be no tip for commit "COMMIT2"
And there should be 0 email sent
19 changes: 0 additions & 19 deletions features/notification_threshold.feature

This file was deleted.

17 changes: 17 additions & 0 deletions features/step_definitions/common.rb
Expand Up @@ -29,6 +29,15 @@
@project = Project.create!(full_name: "example/#{arg1}", github_id: Digest::SHA1.hexdigest(arg1), bitcoin_address: 'mq4NtnmQoQoPfNWEPbhSvxvncgtGo6L8WY')
end

Given(/^a user "(.*?)" has opted\-in$/) do |arg1|
User.find_or_create_by!(nickname: arg1) do |user|
user.nickname = arg1
user.password = "password"
user.email = "#{arg1.parameterize}@example.com"
user.skip_confirmation!
end
end

Given(/^a deposit of "(.*?)"$/) do |arg1|
Deposit.create!(project: @project, amount: arg1.to_d * 1e8, confirmations: 2)
end
Expand All @@ -48,6 +57,14 @@ def add_new_commit(id, params = {})
},
},
}

User.find_or_create_by(email: "anonymous@example.com") do |user|
user.nickname = "anonymous"
user.email = "anonymous@example.com"
user.password = "password"
user.skip_confirmation!
end

@new_commits[id] = defaults.deep_merge(params)
end

Expand Down
6 changes: 4 additions & 2 deletions features/step_definitions/web.rb
@@ -1,10 +1,12 @@
Given(/^I'm logged in as "(.*?)"$/) do |arg1|
email = "#{arg1.parameterize}@example.com"

OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:github] = {
"info" => {
"nickname" => arg1,
"primary_email" => "#{arg1.gsub(/\s+/,'')}@example.com",
"verified_emails" => [],
"primary_email" => email,
"verified_emails" => [email],
},
}.to_ostruct
visit root_path
Expand Down
6 changes: 4 additions & 2 deletions features/tip_modifier_interface.feature
@@ -1,6 +1,8 @@
Feature: A project collaborator can change the tips of commits
Background:
Given a project "a"
And a user "yugo" has opted-in
And a user "gaal" has opted-in
And the project collaborators are:
| seldon |
| daneel |
Expand All @@ -17,7 +19,7 @@ Feature: A project collaborator can change the tips of commits
When the new commits are read
Then there should be a tip of "5" for commit "BBB"
And there should be a tip of "4.95" for commit "CCC"
And there should be 2 email sent
And there should be 0 email sent

Scenario: A collaborator wants to alter the tips
Given I'm logged in as "seldon"
Expand All @@ -43,7 +45,7 @@ Feature: A project collaborator can change the tips of commits
And I click on "Send the selected tip amounts"
Then there should be a tip of "0.5" for commit "BBB"
And the tip amount for commit "CCC" should be undecided
And there should be 1 email sent
And there should be 0 email sent

When the email counters are reset
And I choose the amount "Free: 0%" on commit "CCC"
Expand Down
42 changes: 42 additions & 0 deletions lib/blacklist.rb
@@ -0,0 +1,42 @@
require "set"

class Blacklist
def initialize(urls)
urls = urls.map {|u| normalize_url(u) }

@urls = Set.new(urls)
end

def include?(url)
url = normalize_url(url)

if @urls.include?(url)
return true
end

# Check for the author path.
# https://github.com/author/*
url[url.rindex("/")..-1] = "/*"

@urls.include?(url)
end

private
def normalize_url(url)
url = url.clone

if !url.start_with?("http://", "https://", "//")
if !url.start_with?("github.com", "bitbucket.org")
# Assume it is a shortened "author/project" path and
# default to Github.
url.prepend("github.com/")
end
url.prepend("https://")
end

uri = URI.parse(url)

# Ignore irrelevant differences such as HTTP/HTTPS.
[uri.host, uri.path].join
end
end

0 comments on commit 1f7853b

Please sign in to comment.