Repository navigation
Expand file tree
/
Copy pathcommon.ts
More file actions
79 lines (65 loc) · 2.22 KB
/
Copy pathcommon.ts
File metadata and controls
79 lines (65 loc) · 2.22 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { extname } from "https://deno.land/std@0.208.0/path/mod.ts";
import { minOf } from "https://deno.land/std@0.208.0/collections/min_of.ts";
export const semverRegExp = /v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/;
export const CommitType = [
"build",
"ci",
"docs",
] as const;
export type CommitType = typeof CommitType[number];
export type UpdateSpec = {
name: string;
initial?: string;
target: string;
};
export abstract class Update {
path: string;
spec: UpdateSpec;
type: CommitType;
constructor(path: string, spec: UpdateSpec) {
this.path = path;
this.spec = spec;
this.type = this.isDocument() ? "docs" : this.isWorkflow() ? "ci" : "build";
}
isDocument = () => extname(this.path).match(/\.md|\.txt/) !== null;
isWorkflow = () => this.path.startsWith(".github/workflows/");
message = () => {
const { name, initial, target } = this.spec;
const str = initial ? ` from ${initial} ` : " ";
return `${this.type}(deps): bump ${name}` + str + `to ${target}`;
};
abstract content: (input: string) => string;
}
export const pullRequestType = (types: CommitType[]): CommitType =>
CommitType[
minOf(
types,
(type) => CommitType.findIndex((it) => it === type),
)!
];
export function removeIgnore(input: string) {
const fns = [
// ignore sections in typescript code (denopendabot-ignore-start/end)
(input: string) => {
const start = "// @denopendabot ignore\\-start";
const end = "// @denopendabot ignore\\-end";
const regexp = RegExp("^\\s*" + start + ".*" + end + "\\s*$", "gms");
return input.replaceAll(regexp, "");
},
// ignore sections in markdown (denopendabot-ignore-start/end)
(input: string) => {
const start = "<!\\-\\- @denopendabot ignore\\-start \\-\\->";
const end = "<!\\-\\- @denopendabot ignore\\-end \\-\\->";
const regexp = RegExp("^\\s*" + start + ".*" + end + "\\s*$", "gms");
return input.replaceAll(regexp, "");
},
// ignore a single line (@denopendabot ignore)
(input: string) => {
const regexp = /^.*@denopendabot ignore.*$/gm;
return input.replaceAll(regexp, "");
},
];
let output = input;
fns.forEach((fn) => output = fn(output));
return output;
}