Groovy web console

subscribe to the feed Subscribe
to this
site

Format commit message

Published 1 month ago by zacharyw
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def format(String message, String repo="default") {
    def prPattern = ~/^(.*)\(#(\d+)\)$/
    message = message.replaceFirst(prPattern) { _, other, pr ->
        "${other}(<https://github.com/org/${repo}/pull/${pr}|#${pr}>)"
    }

    def ticketPattern = ~/^([A-Z]+-\d+)(.*)$/
    message = message.replaceFirst(ticketPattern) { _, ticket, other ->
        "<https://jira.com/${ticket}|${ticket}>${other}"
    }
    return message
}

println format("JIRA-1234 fixed everything! (#100)")
println format("JIRA-NA to err is human (#143)")
println format("Nothing to look at (#143)")
println format("feature/jira 8943 wat? (#4)")
println format("JIRA-943 What did I forget?")