-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.utils.js
52 lines (45 loc) · 1.23 KB
/
index.utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const core = require("@actions/core");
function formatLineNumbers(numbers) {
if (!numbers || numbers.length === 0) return "";
let formatted = [];
let start = numbers[0];
let end = start;
for (let i = 1; i < numbers.length; i++) {
// Check if the current number is consecutive to the previous
if (numbers[i] === end + 1) {
end = numbers[i];
} else {
if (end - start >= 2) {
// Check if there's more than one number in between
formatted.push(`${start}...${end}`);
} else {
formatted.push(start.toString());
if (end !== start) {
formatted.push(end.toString());
}
}
start = end = numbers[i];
}
}
// Add the last number or range to the formatted array
if (end - start >= 2) {
formatted.push(`${start}...${end}`);
} else {
formatted.push(start.toString());
if (end !== start) {
formatted.push(end.toString());
}
}
return formatted.join(", ");
}
function debug(...args) {
const debug = core.getInput("debug", { required: false });
const enableLogging = ["true", "yes", "on"].includes(debug.toLowerCase());
if (enableLogging) {
console.log(...args);
}
}
module.exports = {
debug,
formatLineNumbers,
};