Last active
November 2, 2016 14:38
-
-
Save fotiDim/638d2c638733c65f85ec7b90f1618eac to your computer and use it in GitHub Desktop.
A Ruby method to sanitize a changelog generated from commit messages
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
# | |
# Extracts ticket numbers (e.g. #ZLA-132) from a changelog generated from commit messages | |
# | |
def sanitize_changelog(changelog,hashtag,project_ID,delimiter) | |
# Convert text to an array | |
changelog_array = changelog.split(/\n+/) | |
# Clear rows that start with #ZLA-000 aka. version bumps | |
changelog_array.delete_if do |row| | |
row.start_with?('#ZLA-000') | |
end | |
# Only include rows that start with the desired pattern | |
search_pattern = hashtag + project_ID + delimiter | |
manipulated_rows = changelog_array.select { |row| row.start_with?(search_pattern) } | |
.uniq # Remove duplicates | |
.map { |row| row.sub(search_pattern, '') } # Remove the search_pattern | |
.sort_by(&:to_i) # Sort by ID | |
(["#{manipulated_rows.size} #{project_ID} issues:"] + manipulated_rows).join("\n") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment