src/main/kotlin/de/uapcore/lightpit/types/CommitRef.kt

Sat, 22 Jul 2023 13:04:12 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 22 Jul 2023 13:04:12 +0200
changeset 282
c112fad21bf6
parent 280
src/main/kotlin/de/uapcore/lightpit/vcs/CommitRef.kt@12b898531d1a
child 288
10324c383126
permissions
-rw-r--r--

remove vcs connectors in favor of externally fed logs

relates to #276

universe@282 1 /*
universe@282 2 * Copyright 2023 Mike Becker. All rights reserved.
universe@282 3 *
universe@282 4 * Redistribution and use in source and binary forms, with or without
universe@282 5 * modification, are permitted provided that the following conditions are met:
universe@282 6 *
universe@282 7 * 1. Redistributions of source code must retain the above copyright
universe@282 8 * notice, this list of conditions and the following disclaimer.
universe@282 9 *
universe@282 10 * 2. Redistributions in binary form must reproduce the above copyright
universe@282 11 * notice, this list of conditions and the following disclaimer in the
universe@282 12 * documentation and/or other materials provided with the distribution.
universe@282 13 *
universe@282 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
universe@282 15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
universe@282 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
universe@282 17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
universe@282 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
universe@282 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
universe@282 20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
universe@282 21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
universe@282 22 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
universe@282 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
universe@282 24 *
universe@282 25 */
universe@282 26
universe@282 27 package de.uapcore.lightpit.types
universe@280 28
universe@280 29 data class CommitRef(val hash: String, val issueId: Int, val message: String)
universe@282 30
universe@282 31 /**
universe@282 32 * Takes a [commitLog] in format `::lpitref::{node}:{desc}` and parses commit references.
universe@282 33 * Supported references are (in this example, 47 is the issue ID):
universe@282 34 * - fixes #47
universe@282 35 * - fix #47
universe@282 36 * - closes #47
universe@282 37 * - close #47
universe@282 38 * - relates to #47
universe@282 39 */
universe@282 40 fun parseCommitRefs(commitLog: String): List<CommitRef> = buildList {
universe@282 41 val marker = "::lpitref:"
universe@282 42 var currentHash = ""
universe@282 43 var currentDesc = ""
universe@282 44 for (line in commitLog.split("\n")) {
universe@282 45 // see if current line contains a new log entry
universe@282 46 if (line.startsWith(marker)) {
universe@282 47 val head = line.substring(marker.length).split(':', limit = 2)
universe@282 48 currentHash = head[0]
universe@282 49 currentDesc = head[1]
universe@282 50 }
universe@282 51
universe@282 52 // skip possible preamble output
universe@282 53 if (currentHash.isEmpty()) continue
universe@282 54
universe@282 55 // scan the lines for commit references
universe@282 56 Regex("""(?:relates to|fix(?:es)?|close(?:es)?) #(\d+)""")
universe@282 57 .findAll(line)
universe@282 58 .map { it.groupValues[1] }
universe@282 59 .map { it.toIntOrNull() }
universe@282 60 .filterNotNull()
universe@282 61 .forEach { commitId -> add(CommitRef(currentHash, commitId, currentDesc)) }
universe@282 62 }
universe@282 63 }
universe@282 64

mercurial