Skip to content

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

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
36 changes: 34 additions & 2 deletions app/controllers/github_commits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,47 @@ 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)
#if issue id exists in redmine & status is in progress (2)
if issue.present? && issue.status_id == 2
#we are using status id 14 for "jenkins validation" which we created.
#you can easily adapt this plugin to your need by changing
#the "from" status id in the previous if conditional statement and
#the "to" status id in next line update statement
issue.update(status_id: 14) #jenkins validation
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'