Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature in same plugin we did code in house and want to share #5

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
41 changes: 39 additions & 2 deletions app/controllers/github_commits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,52 @@ class GithubCommitsController < ApplicationController

unloadable

skip_before_filter :check_if_login_required
skip_before_filter :verify_authenticity_token
skip_before_action :check_if_login_required
skip_before_action :verify_authenticity_token

before_action :verify_signature?

GITHUB_URL = "https://github.com/"
REDMINE_JOURNALIZED_TYPE = "Issue"
REDMINE_ISSUE_NUMBER_PREFIX = "#rm"

#added JPBD Jan2022
def github_change_notification
resp_json = nil
# if payload contains pr and action is opened (new pr)
if params[:pull_request].present? && params[:pull_request][:state] == "open"
#get issue ID
pr_title = params[:pull_request][:title]
issue_id = pr_title.partition(REDMINE_ISSUE_NUMBER_PREFIX).last.split(" ").first.to_i
issue = Issue.find_by(id: issue_id)
#use env var if defined, else use default
currentstate = ENV["CURRENT_REDMINE_STATE"]
if currentstate.nil?
currentstate = 2 #default for in progress
end
nextstate = ENV["NEXT_REDMINE_STATE"]
if nextstate.nil?
nextstate = 3 #default for in review
end
#if issue id exists in redmine & status is in progress (2)
if issue.present? && issue.status_id == currentstate.to_i
issue.update(status_id: nextstate.to_i)
resp_json = {success: true}
else
resp_json = {success: false, error: t('lables.no_pr_found') }
end

resp_json = {success: true}
else # if not a pr payload
resp_json = {success: false, error: t('lables.no_update') }
end

respond_to do |format|
format.json { render json: resp_json, status: :ok }
end

end

def create_comment
resp_json = nil
if params[:commits].present?
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ en:
lables:
no_commit_data_found: "Request does not have commit data."
no_issue_found: "Issue not found."
no_pr_found: "Request does not have PR data."
no_update: "status was not updated for missing requirements."
commit:
message: ! "__Github Commit__ - __%{author}__ has commited on __%{branch}__ branch with message: __%{message}__ , [%{commit_id}](%{commit_url})"
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Plugin's routes
# See: http://guides.rubyonrails.org/routing.html
post 'github_commits/create_comment.json', to: 'github_commits#create_comment'
post 'github_commits/github_change_notification.json', to: 'github_commits#github_change_notification'