Class: PlanMyStuff::LabelsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/plan_my_stuff/labels_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /issues/:issue_id/labels



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/plan_my_stuff/labels_controller.rb', line 6

def create
  labels = parse_labels(params[:label_name])
  if labels.blank?
    flash[:error] = 'Label name is required.'
    redirect_to(plan_my_stuff.issue_path(params[:issue_id]))
    return
  end

  issue = PlanMyStuff::Issue.find(params[:issue_id])

  missing = labels.reject { |label| PlanMyStuff::Label.exists?(repo: issue.repo, name: label) }
  if missing.any?
    flash[:error] = "Label#{'s' if missing.size > 1} not found in repo: #{missing.join(', ')}"
    redirect_to(plan_my_stuff.issue_path(issue))
    return
  end

  PlanMyStuff::Label.add!(issue: issue, labels: labels)

  yield(issue) if block_given?
  return if performed?

  flash[:success] = 'Label was successfully added.'
  redirect_to(plan_my_stuff.issue_path(issue))
rescue PlanMyStuff::Error, Octokit::Error => e
  pms_handle_rescue(e)
  flash[:error] = e.message
  redirect_to(plan_my_stuff.issue_path(params[:issue_id]))
end

#destroyObject

DELETE /issues/:issue_id/labels/:id



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/plan_my_stuff/labels_controller.rb', line 37

def destroy
  issue = PlanMyStuff::Issue.find(params[:issue_id])
  PlanMyStuff::Label.remove!(issue: issue, labels: [params[:id]])

  yield(issue) if block_given?
  return if performed?

  flash[:success] = 'Label was successfully removed.'
  redirect_to(plan_my_stuff.issue_path(issue))
rescue PlanMyStuff::Error, Octokit::Error => e
  pms_handle_rescue(e)
  flash[:error] = e.message
  redirect_to(plan_my_stuff.issue_path(params[:issue_id]))
end