-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdiffCheck.ts
More file actions
101 lines (90 loc) · 2.46 KB
/
diffCheck.ts
File metadata and controls
101 lines (90 loc) · 2.46 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { Stainless } from "@stainless-api/sdk";
import { logger } from "./logger";
import type { Outcomes } from "./outcomes";
export async function isOnlyStatsChanged({
stainless,
outcomes,
baseOutcomes,
headBuildId,
}: {
stainless: Stainless;
outcomes: Outcomes;
baseOutcomes: Outcomes;
headBuildId: string;
}): Promise<boolean> {
for (const lang of Object.keys(baseOutcomes)) {
if (!(lang in outcomes)) {
return false;
}
}
for (const [lang, head] of Object.entries(outcomes)) {
if (!(lang in baseOutcomes)) {
return false;
}
const base = baseOutcomes[lang]!;
const headConclusion = head.commit?.conclusion;
if (headConclusion === "noop") {
continue;
}
if (!base.commit?.completed?.commit || !head.commit?.completed?.commit) {
return false;
}
const baseSha = base.commit.completed.commit.sha;
const headSha = head.commit.completed.commit.sha;
const { owner, name } = head.commit.completed.commit.repo;
let token: string;
try {
const output = await stainless.builds.targetOutputs.retrieve({
build_id: headBuildId,
target: lang as Stainless.Target,
type: "source",
output: "git",
});
if (output.output !== "git") {
logger.debug(
`targetOutputs for ${lang} returned non-git output, skipping stats check`,
);
return false;
}
token = output.token;
} catch (e) {
logger.debug(
`Could not get git access for ${lang}, skipping stats check`,
e,
);
return false;
}
try {
const response = await fetch(
`https://api.github.com/repos/${owner}/${name}/compare/${baseSha}...${headSha}`,
{
headers: {
Authorization: `token ${token}`,
Accept: "application/vnd.github.v3+json",
},
},
);
if (!response.ok) {
logger.debug(
`GitHub compare API returned ${response.status} for ${lang}, skipping stats check`,
);
return false;
}
const data = (await response.json()) as {
status: string;
files?: Array<{ filename: string }>;
};
const files = data.files ?? [];
if (!files.every((f) => f.filename === ".stats.yml")) {
return false;
}
} catch (e) {
logger.debug(
`Error comparing commits for ${lang}, skipping stats check`,
e,
);
return false;
}
}
return true;
}