• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

AgileVentures / WebsiteOne / #233

pending completion
#233

push

semaphore

web-flow
add last_github_update to project list (#3838)

* add last_github_update to project list

* add test for display of last_github_update

* test for display of last_github_update

4929 of 5374 relevant lines covered (91.72%)

14.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.07
/app/controllers/projects_controller.rb
1
# frozen_string_literal: true
2

3
class ProjectsController < ApplicationController
1✔
4
  layout 'with_sidebar'
1✔
5
  before_action :authenticate_user!, except: %i(index show)
1✔
6
  before_action :set_project, only: %i(show edit update access_to_edit)
1✔
7
  before_action -> { query_projects('title ASC') }, only: %i(show edit update new)
22✔
8
  before_action :get_current_stories, only: %i(show)
1✔
9
  before_action :valid_admin, only: %i(index), if: -> { params[:status] == 'pending' }
4✔
10
  before_action :access_to_edit, only: %i(edit)
1✔
11
  include DocumentsHelper
1✔
12

13
  def index
1✔
14
    @language = params[:language]
2✔
15
    query_projects('last_github_update DESC NULLS LAST')
2✔
16
    if params[:status] == 'pending'
2✔
17
      render :pending_projects, layout: 'with_sidebar_sponsor_right'
2✔
18
    else
19
      render layout: 'with_sidebar_sponsor_right'
×
20
    end
21
  end
22

23
  def show
1✔
24
    documents
13✔
25
    @members = @project.members
13✔
26
    relation = EventInstance.where(project_id: @project.id)
13✔
27
    @event_instances_count = relation.count
13✔
28
    @event_instances = relation.order(created_at: :desc).limit(25)
13✔
29
  end
30

31
  def new
1✔
32
    @project = Project.new
1✔
33
    @project.source_repositories.build
1✔
34
    @project.issue_trackers.build
1✔
35
    @project.languages.build
1✔
36
  end
37

38
  def create
1✔
39
    status = current_user.admin? ? project_params[:status].downcase : 'pending'
1✔
40
    @project = Project.create(project_params.merge(user: current_user, status: status))
1✔
41
    if @project.persisted?
1✔
42
      add_to_feed(:create)
1✔
43
      current_user.follow(@project)
1✔
44
      redirect_to project_path(@project), notice: 'Project was successfully created.'
1✔
45
    else
46
      query_projects('title ASC')
×
47
      flash.now[:alert] = 'Project was not saved. Please check the input.'
×
48
      render action: 'new'
×
49
    end
50
  end
51

52
  def edit; end
1✔
53

54
  def update
1✔
55
    params[:command].present? && update_project_status(params[:command]) and return
4✔
56
    if @project.update(project_params)
×
57
      add_to_feed(:update)
×
58
      redirect_to project_path(@project), notice: 'Project was successfully updated.'
×
59
    else
60
      # TODO: change this to notify for invalid params
61
      flash.now[:alert] = 'Project was not updated.'
×
62
      render 'edit'
×
63
    end
64
  end
65

66
  def follow
1✔
67
    set_project
×
68
    if current_user
×
69
      current_user.follow(@project)
×
70
      send_email_notifications
×
71
      redirect_to project_path(@project)
×
72
      flash[:notice] = "You just joined #{@project.title}."
×
73
    else
74
      flash[:error] = "You must <a href='/users/sign_in'>login</a> to follow #{@project.title}.".html_safe
×
75
    end
76
  end
77

78
  def unfollow
1✔
79
    set_project
×
80
    current_user.stop_following(@project)
×
81
    redirect_to project_path(@project)
×
82
    flash[:notice] = "You are no longer a member of #{@project.title}."
×
83
  end
84

85
  private
1✔
86

87
  def send_email_notifications
1✔
88
    if @project.user.receive_mailings
×
89
      ProjectMailer.with(project: @project, user: current_user, project_creator: @project.user)
×
90
                   .alert_project_creator_about_new_member.deliver_now
91
    end
92

93
    if current_user.receive_mailings
×
94
      ProjectMailer.with(project: @project, user: current_user, project_creator: @project.user)
×
95
                   .welcome_project_joinee.deliver_now
96
    end
97
  end
98

99
  def set_project
1✔
100
    @project = Project.friendly.find(params[:id])
20✔
101
  end
102

103
  def query_projects(order)
1✔
104
    status = params[:status]
23✔
105
    @projects = if status == 'pending'
23✔
106
                  Project.where(status: status)
2✔
107
                         .order(order)
108
                         .includes(:user)
109
                else
110
                  Project.order(order)
21✔
111
                         .includes(:user)
112
                end
113
    @projects_languages_array = Language.pluck(:name)
23✔
114
    @projects = @projects.search_by_language(@language) if @language.presence
23✔
115
  end
116

117
  def add_to_feed(action)
1✔
118
    @project.create_activity action, owner: current_user
1✔
119
  end
120

121
  def get_current_stories
1✔
122
    PivotalAPI::Service.set_token('1e90ef53f12fc327d3b5d8ee007cce39')
13✔
123
    @is_non_pt_issue_tracker = false
13✔
124
    if @project.pivotaltracker_url.present?
13✔
125
      pivotaltracker_id = @project.pivotaltracker_url.split('/')[-1]
×
126
      begin
127
        project = PivotalAPI::Project.retrieve(pivotaltracker_id)
×
128
        iteration = project.current_iteration
×
129
        @stories = iteration.stories
×
130
      rescue Exception => e
131
        # TODO: deal with simple not found errors, should not send for all exceptions
132
        ExceptionNotifier.notify_exception(e, env: request.env,
×
133
                                              data: { message: 'an error occurred in Pivotal Tracker' })
134
        @is_non_pt_issue_tracker = true
×
135
      end
136
    end
137
    @stories ||= []
13✔
138
  end
139

140
  def project_params
1✔
141
    params.require(:project).permit(:title, :description, :pitch, :created, :status,
1✔
142
                                    :user_id, :github_url, :pivotaltracker_url, :slack_channel_name,
143
                                    :pivotaltracker_id, :image_url, languages_attributes: [:name],
144
                                                                    name_ids: [], source_repositories_attributes: %i(id url _destroy),
145
                                                                    issue_trackers_attributes: %i(id url _destroy))
146
  end
147

148
  def valid_admin
1✔
149
    redirect_to root_path, notice: 'You do not have permission to perform that operation' unless user_signed_in? && current_user.admin?
3✔
150
  end
151

152
  def access_to_edit
1✔
153
    unless current_user.admin? || (current_user == @project.user)
3✔
154
      redirect_to root_path, notice: 'You do not have permission to perform that operation'
1✔
155
    end
156
  end
157

158
  def update_project_status(command)
1✔
159
    status = command == 'activate' ? 'active' : 'pending'
4✔
160
    @project = Project.friendly.find(params[:id])
4✔
161
    @project.update(status: status)
4✔
162
    redirect_to project_path, notice: "Project was #{command}d"
4✔
163
  end
164
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc