universe@282: /* universe@282: * Copyright 2023 Mike Becker. All rights reserved. universe@282: * universe@282: * Redistribution and use in source and binary forms, with or without universe@282: * modification, are permitted provided that the following conditions are met: universe@282: * universe@282: * 1. Redistributions of source code must retain the above copyright universe@282: * notice, this list of conditions and the following disclaimer. universe@282: * universe@282: * 2. Redistributions in binary form must reproduce the above copyright universe@282: * notice, this list of conditions and the following disclaimer in the universe@282: * documentation and/or other materials provided with the distribution. universe@282: * universe@282: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" universe@282: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE universe@282: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE universe@282: * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE universe@282: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL universe@282: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR universe@282: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER universe@282: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, universe@282: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE universe@282: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. universe@282: * universe@282: */ universe@282: universe@282: package de.uapcore.lightpit.types universe@280: universe@280: data class CommitRef(val hash: String, val issueId: Int, val message: String) universe@282: universe@282: /** universe@282: * Takes a [commitLog] in format `::lpitref::{node}:{desc}` and parses commit references. universe@282: * Supported references are (in this example, 47 is the issue ID): universe@282: * - fixes #47 universe@282: * - fix #47 universe@282: * - closes #47 universe@282: * - close #47 universe@282: * - relates to #47 universe@282: */ universe@282: fun parseCommitRefs(commitLog: String): List = buildList { universe@282: val marker = "::lpitref:" universe@282: var currentHash = "" universe@282: var currentDesc = "" universe@282: for (line in commitLog.split("\n")) { universe@282: // see if current line contains a new log entry universe@282: if (line.startsWith(marker)) { universe@282: val head = line.substring(marker.length).split(':', limit = 2) universe@282: currentHash = head[0] universe@282: currentDesc = head[1] universe@282: } universe@282: universe@282: // skip possible preamble output universe@282: if (currentHash.isEmpty()) continue universe@282: universe@282: // scan the lines for commit references universe@282: Regex("""(?:relates to|fix(?:es)?|close(?:es)?) #(\d+)""") universe@282: .findAll(line) universe@282: .map { it.groupValues[1] } universe@282: .map { it.toIntOrNull() } universe@282: .filterNotNull() universe@282: .forEach { commitId -> add(CommitRef(currentHash, commitId, currentDesc)) } universe@282: } universe@282: } universe@282: