Created
August 30, 2019 02:13
-
-
Save gaussbeam/3a454d5c9f038363704ebb3d93f3293c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Fastlane | |
module Actions | |
class IsMergeCommitLatestAction < Action | |
def self.run(params) | |
last_commit_hash = Action.sh("git log -1 --pretty=format:\"%H\"") | |
last_merge_commit_hash = Action.sh("git log -1 --merges --pretty=format:\"%H\"") | |
UI.message "Determine if the latest commit is merge commit." | |
return false if last_commit_hash != last_merge_commit_hash | |
branch_regex = params[:head_branch_name_regex] | |
if branch_regex.nil? then | |
return true | |
else | |
UI.message "Determine if the latest merge commit from expected head branch." | |
UI.message "Regular expression of expected head branch: /#{branch_regex}/" | |
last_commit_msg = Actions.last_git_commit_message() | |
return /^Merge.*#{branch_regex}/ === last_commit_msg | |
end | |
end | |
##################################################### | |
# @!group Documentation | |
##################################################### | |
def self.description | |
"Returns a boolean value indicating whether the latest commit is merge commit" | |
end | |
def self.details | |
"If option 'head_branch_name_regex' is defined, returns true only when tha latest commit is merge commit from branch matches pattern defined in `head_branch_name_regex`" | |
end | |
def self.available_options | |
[ | |
FastlaneCore::ConfigItem.new(key: :head_branch_name_regex, | |
description: "Regular expression of head branch name. **IMPORTANT** Don't use '^' or '$'", | |
optional: true) | |
] | |
end | |
def self.return_value | |
"A boolean value indicating whether latest commit is merge commit" | |
end | |
def self.is_supported?(platform) | |
true # All platform | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment