Class: PlanMyStuff::LabelsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- PlanMyStuff::LabelsController
- Defined in:
- app/controllers/plan_my_stuff/labels_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /issues/:issue_id/labels.
-
#destroy ⇒ Object
DELETE /issues/:issue_id/labels/:id.
Instance Method Details
#create ⇒ Object
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 |
# 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], repo: params[:repo])) return end issue = PlanMyStuff::Issue.find(params[:issue_id].to_i, repo: params[:repo]) 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.number, repo: issue.repo.full_name)) return end PlanMyStuff::Label.add!(issue: issue, labels: labels) flash[:success] = 'Label was successfully added.' redirect_to(plan_my_stuff.issue_path(issue.number, repo: issue.repo.full_name)) rescue PlanMyStuff::Error, Octokit::Error => e pms_handle_rescue(e) flash[:error] = e. redirect_to(plan_my_stuff.issue_path(params[:issue_id], repo: params[:repo])) end |
#destroy ⇒ Object
DELETE /issues/:issue_id/labels/:id
34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/plan_my_stuff/labels_controller.rb', line 34 def destroy issue = PlanMyStuff::Issue.find(params[:issue_id].to_i, repo: params[:repo]) PlanMyStuff::Label.remove!(issue: issue, labels: [params[:id]]) flash[:success] = 'Label was successfully removed.' redirect_to(plan_my_stuff.issue_path(issue.number, repo: issue.repo.full_name)) rescue PlanMyStuff::Error, Octokit::Error => e pms_handle_rescue(e) flash[:error] = e. redirect_to(plan_my_stuff.issue_path(params[:issue_id], repo: params[:repo])) end |