-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocs:use-codecov-as-test-link.js
61 lines (51 loc) · 1.54 KB
/
docs:use-codecov-as-test-link.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
53
54
55
56
57
58
59
60
61
import find from '../lib/code/find.js';
import replace from '../lib/code/replace.js';
export const description = 'Use codecov as test link.';
export const commit = {
type: 'docs',
subject: description,
};
const newValue = (oldValue) => {
const [owner, repo] = oldValue.split('/').slice(-2);
if (owner === undefined || repo === undefined) return oldValue;
return `https://app.codecov.io/gh/${owner}/${repo}`;
};
const paths = ['doc/scripts/header.js'];
const filter = (node, {is, n}) => {
if (!is(node, n.AssignmentExpression)) return false;
const {operator, left, right} = node;
if (!is(left, n.MemberExpression)) return false;
if (!is(right, n.Literal)) return false;
const {object, property} = left;
if (!is(object, n.Identifier)) return false;
if (!is(property, n.Identifier)) return false;
return (
object.name === 'testlink' &&
property.name === 'href' &&
operator === '=' &&
right.value !== newValue(right.value)
);
};
const map = ({operator, left, right}, {b}) => {
return b.assignmentExpression(
operator,
left,
b.literal(newValue(right.value)),
);
};
export async function postcondition({read, assert}) {
const found = await find([{filter}], paths, {read});
assert(!found);
}
export async function precondition({read, assert}) {
const found = await find([{filter}], paths, {read});
assert(found);
}
export async function apply({read, write, fixSources}) {
await replace([{filter, map}], paths, {read, write});
await fixSources();
}
export const dependencies = [
'sources:lint-setup',
'github:workflow-configure-ci:test',
];