Skip to content

Commit

Permalink
Add CLA support
Browse files Browse the repository at this point in the history
Signed-off-by: James Taylor <[email protected]>
  • Loading branch information
jt-nti committed Feb 16, 2021
1 parent a129823 commit 6585613
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/edit_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def commit
pull_from = forked ? "#{@current_user.login}:#{new_branch}" : branch_name
@pr = open_pr(pull_from, @branch, @summary, @description)
# Check for CLA
@cla_url = "#{ENV.fetch("SITE_URL")}/cla.html"
@cla_url = "#{ENV.fetch("CLA_URL")}"
r = Faraday.get @cla_url
@has_cla = (r.status == 200)
end
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def show
# Get activity list
presenter = ProposalPresenter.new(@proposal)
@activity = presenter.activity_log
# TODO needs to check if the manifesto has a cla!
# @unsigned_cla = @is_author && !current_user.cla_accepted?
@unsigned_cla = true
@tbc = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
end

def webhook
Expand Down
13 changes: 13 additions & 0 deletions app/models/concerns/github_pull_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ def set_time_build_status
end
end

def set_cla_build_status
status = "groupthink/cla"
if cla_required?
if cla_accepted?
set_build_status(:success, I18n.t("build_status.cla.accepted"), status)
else
set_build_status(:pending, I18n.t("build_status.cla.pending"), status)
end
else
set_build_status(:success, I18n.t("build_status.cla.none"), status)
end
end

def merge_pr!
Octokit.merge_pull_request(ENV.fetch("GITHUB_REPO"), number)
true
Expand Down
1 change: 1 addition & 0 deletions app/models/concerns/user_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module UserAdmin
field :role
field :author
field :voter
field :cla_accepted
end
end
end
Expand Down
1 change: 1 addition & 0 deletions app/models/concerns/votable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def count_votes!
unless closed?
set_vote_build_status
set_time_build_status
set_cla_build_status
end
end

Expand Down
10 changes: 9 additions & 1 deletion app/models/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ def too_new?
age < Rules.min_age
end

def cla_required?
ENV['CLA_URL'].present?
end

def cla_accepted?
proposer.cla_accepted
end

def update_state!
state = pr_closed? ? closed_state : open_state
update!(state: state)
Expand Down Expand Up @@ -90,7 +98,7 @@ def closed_state
def open_state
return nil if pr_closed?
return "dead" if too_old?
return "blocked" if blocked?
return "blocked" if blocked? || (cla_required? && !cla_accepted?)
if passed?
return too_new? ? "agreed" : "passed"
end
Expand Down
16 changes: 16 additions & 0 deletions app/views/proposals/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@
</div>
</div>

<% if @unsigned_cla %>
<div class='row'>
<div class='col-md-9'>
<p>
This proposal is blocked because the manifesto has a contributor license agreement (CLA) which all contributors must sign.
Please <a href="<%= ENV.fetch("CLA_URL") %>" target="_blank" rel="noopener noreferrer">read the agreement</a> and sign it using the accept button below.
</p>
<div class="form-group">
<%= link_to "#{fa_icon('check')} #{t(:sign_cla)}".html_safe, @tbc, class: 'btn btn-primary'%>
</div>
</div>
</div>
<% end %>

<span style="clear: both">&nbsp;</span>

<hr/>

<div class='row'>
Expand Down
7 changes: 6 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ en:
signed_out_site_intro: To contribute you need to log in with a free GitHub account. GitHub is a popular code-sharing site which hosts the site content.
signed_in_site_intro: There is no way at the moment to explore github content here. Please go to the project you want to edit on GitHub and follow a link to the editor. Thanks!
cla: This project has a CLA (Contributor License Agreement). You may need to agree to it before your change can be accepted, if you haven't already.
sign_cla: Accept CLA
view_cla: View CLA
help:
edit: Make your changes in the editor below, then hit "Submit changes" at the bottom.
Expand Down Expand Up @@ -70,4 +71,8 @@ en:
time:
too_old: "The change has been open for more than %{max_age} days, and should be closed (age: %{age}d)."
too_new: "The change has not yet been open for %{min_age} days (age: %{age}d)."
success: "The change has been open long enough to be merged (age: %{age}d)."
success: "The change has been open long enough to be merged (age: %{age}d)."
cla:
none: No contributor license agreement required.
pending: The contributor license agreement has not been accepted.
accepted: The contributor license agreement has been accepted.

0 comments on commit 6585613

Please sign in to comment.