Skip to content

Commit 75e26be

Browse files
committed
fixup! fix: support list detail of failed GitHub CI
1 parent 5cfc18b commit 75e26be

File tree

1 file changed

+291
-0
lines changed

1 file changed

+291
-0
lines changed

test/unit/pr_checker.test.js

Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,297 @@ describe('PRChecker', () => {
19411941
assert(status);
19421942
cli.assertCalledWith(expectedLogs);
19431943
});
1944+
1945+
it('should error if Check suite cancelled', async() => {
1946+
const cli = new TestCLI();
1947+
1948+
const expectedLogs = {
1949+
error: [
1950+
['1 GitHub CI job(s) cancelled:'],
1951+
[' - test-linux: CANCELLED (https://github.com/nodejs/node/runs/12345)']
1952+
]
1953+
};
1954+
1955+
const commits = githubCI['check-suite-cancelled'];
1956+
const data = Object.assign({}, baseData, { commits });
1957+
1958+
const checker = new PRChecker(cli, data, {}, testArgv);
1959+
1960+
const status = await checker.checkCI();
1961+
assert(!status);
1962+
cli.assertCalledWith(expectedLogs);
1963+
});
1964+
1965+
it('should handle multiple failed jobs with detailed output', async() => {
1966+
const cli = new TestCLI();
1967+
1968+
const multipleFailures = [{
1969+
commit: {
1970+
committedDate: '2017-10-26T12:10:20Z',
1971+
oid: '9d098ssiskj8dhd39js0sjd0cn2ng4is9n40sj12d',
1972+
messageHeadline: 'doc: add api description README',
1973+
author: { login: 'foo' },
1974+
checkSuites: {
1975+
nodes: [{
1976+
app: { slug: 'github-actions' },
1977+
status: 'COMPLETED',
1978+
conclusion: 'FAILURE',
1979+
checkRuns: {
1980+
nodes: [
1981+
{
1982+
name: 'test-linux',
1983+
status: 'COMPLETED',
1984+
conclusion: 'FAILURE',
1985+
detailsUrl: 'https://github.com/nodejs/node/runs/1'
1986+
},
1987+
{
1988+
name: 'test-windows',
1989+
status: 'COMPLETED',
1990+
conclusion: 'FAILURE',
1991+
detailsUrl: 'https://github.com/nodejs/node/runs/2'
1992+
},
1993+
{
1994+
name: 'lint',
1995+
status: 'COMPLETED',
1996+
conclusion: 'SUCCESS',
1997+
detailsUrl: 'https://github.com/nodejs/node/runs/3'
1998+
}
1999+
]
2000+
}
2001+
}]
2002+
}
2003+
}
2004+
}];
2005+
2006+
const expectedLogs = {
2007+
error: [
2008+
['2 GitHub CI job(s) failed:'],
2009+
[' - test-linux: FAILURE (https://github.com/nodejs/node/runs/1)'],
2010+
[' - test-windows: FAILURE (https://github.com/nodejs/node/runs/2)']
2011+
]
2012+
};
2013+
2014+
const data = Object.assign({}, baseData, { commits: multipleFailures });
2015+
const checker = new PRChecker(cli, data, {}, testArgv);
2016+
2017+
const status = await checker.checkCI();
2018+
assert(!status);
2019+
cli.assertCalledWith(expectedLogs);
2020+
});
2021+
2022+
it('should handle mixed failed and cancelled jobs', async() => {
2023+
const cli = new TestCLI();
2024+
2025+
const mixedResults = [{
2026+
commit: {
2027+
committedDate: '2017-10-26T12:10:20Z',
2028+
oid: '9d098ssiskj8dhd39js0sjd0cn2ng4is9n40sj12d',
2029+
messageHeadline: 'doc: add api description README',
2030+
author: { login: 'foo' },
2031+
checkSuites: {
2032+
nodes: [{
2033+
app: { slug: 'github-actions' },
2034+
status: 'COMPLETED',
2035+
conclusion: 'FAILURE',
2036+
checkRuns: {
2037+
nodes: [
2038+
{
2039+
name: 'test-linux',
2040+
status: 'COMPLETED',
2041+
conclusion: 'FAILURE',
2042+
detailsUrl: 'https://github.com/nodejs/node/runs/1'
2043+
},
2044+
{
2045+
name: 'test-macos',
2046+
status: 'COMPLETED',
2047+
conclusion: 'CANCELLED',
2048+
detailsUrl: 'https://github.com/nodejs/node/runs/2'
2049+
}
2050+
]
2051+
}
2052+
}]
2053+
}
2054+
}
2055+
}];
2056+
2057+
const expectedLogs = {
2058+
error: [
2059+
['1 GitHub CI job(s) failed:'],
2060+
[' - test-linux: FAILURE (https://github.com/nodejs/node/runs/1)'],
2061+
['1 GitHub CI job(s) cancelled:'],
2062+
[' - test-macos: CANCELLED (https://github.com/nodejs/node/runs/2)']
2063+
]
2064+
};
2065+
2066+
const data = Object.assign({}, baseData, { commits: mixedResults });
2067+
const checker = new PRChecker(cli, data, {}, testArgv);
2068+
2069+
const status = await checker.checkCI();
2070+
assert(!status);
2071+
cli.assertCalledWith(expectedLogs);
2072+
});
2073+
2074+
it('should fallback to checkSuite level when no checkRuns available', async() => {
2075+
const cli = new TestCLI();
2076+
2077+
const noCheckRuns = [{
2078+
commit: {
2079+
committedDate: '2017-10-26T12:10:20Z',
2080+
oid: '9d098ssiskj8dhd39js0sjd0cn2ng4is9n40sj12d',
2081+
messageHeadline: 'doc: add api description README',
2082+
author: { login: 'foo' },
2083+
checkSuites: {
2084+
nodes: [{
2085+
app: { slug: 'github-actions' },
2086+
status: 'COMPLETED',
2087+
conclusion: 'CANCELLED'
2088+
// No checkRuns field
2089+
}]
2090+
}
2091+
}
2092+
}];
2093+
2094+
const expectedLogs = {
2095+
error: [
2096+
['1 GitHub CI job(s) cancelled:'],
2097+
[' - github-actions: CANCELLED']
2098+
]
2099+
};
2100+
2101+
const data = Object.assign({}, baseData, { commits: noCheckRuns });
2102+
const checker = new PRChecker(cli, data, {}, testArgv);
2103+
2104+
const status = await checker.checkCI();
2105+
assert(!status);
2106+
cli.assertCalledWith(expectedLogs);
2107+
});
2108+
2109+
it('should handle empty checkRuns array', async() => {
2110+
const cli = new TestCLI();
2111+
2112+
const emptyCheckRuns = [{
2113+
commit: {
2114+
committedDate: '2017-10-26T12:10:20Z',
2115+
oid: '9d098ssiskj8dhd39js0sjd0cn2ng4is9n40sj12d',
2116+
messageHeadline: 'doc: add api description README',
2117+
author: { login: 'foo' },
2118+
checkSuites: {
2119+
nodes: [{
2120+
app: { slug: 'github-actions' },
2121+
status: 'COMPLETED',
2122+
conclusion: 'FAILURE',
2123+
checkRuns: { nodes: [] }
2124+
}]
2125+
}
2126+
}
2127+
}];
2128+
2129+
const expectedLogs = {
2130+
error: [
2131+
['1 GitHub CI job(s) failed:'],
2132+
[' - github-actions: FAILURE']
2133+
]
2134+
};
2135+
2136+
const data = Object.assign({}, baseData, { commits: emptyCheckRuns });
2137+
const checker = new PRChecker(cli, data, {}, testArgv);
2138+
2139+
const status = await checker.checkCI();
2140+
assert(!status);
2141+
cli.assertCalledWith(expectedLogs);
2142+
});
2143+
2144+
it('should handle jobs without URLs', async() => {
2145+
const cli = new TestCLI();
2146+
2147+
const noUrlJobs = [{
2148+
commit: {
2149+
committedDate: '2017-10-26T12:10:20Z',
2150+
oid: '9d098ssiskj8dhd39js0sjd0cn2ng4is9n40sj12d',
2151+
messageHeadline: 'doc: add api description README',
2152+
author: { login: 'foo' },
2153+
checkSuites: {
2154+
nodes: [{
2155+
app: { slug: 'github-actions' },
2156+
status: 'COMPLETED',
2157+
conclusion: 'FAILURE',
2158+
checkRuns: {
2159+
nodes: [{
2160+
name: 'test-linux',
2161+
status: 'COMPLETED',
2162+
conclusion: 'FAILURE'
2163+
// No detailsUrl field
2164+
}]
2165+
}
2166+
}]
2167+
}
2168+
}
2169+
}];
2170+
2171+
const expectedLogs = {
2172+
error: [
2173+
['1 GitHub CI job(s) failed:'],
2174+
[' - test-linux: FAILURE']
2175+
]
2176+
};
2177+
2178+
const data = Object.assign({}, baseData, { commits: noUrlJobs });
2179+
const checker = new PRChecker(cli, data, {}, testArgv);
2180+
2181+
const status = await checker.checkCI();
2182+
assert(!status);
2183+
cli.assertCalledWith(expectedLogs);
2184+
});
2185+
2186+
it('should ignore non-completed checkRuns when processing failures', async() => {
2187+
const cli = new TestCLI();
2188+
2189+
const mixedStatusJobs = [{
2190+
commit: {
2191+
committedDate: '2017-10-26T12:10:20Z',
2192+
oid: '9d098ssiskj8dhd39js0sjd0cn2ng4is9n40sj12d',
2193+
messageHeadline: 'doc: add api description README',
2194+
author: { login: 'foo' },
2195+
checkSuites: {
2196+
nodes: [{
2197+
app: { slug: 'github-actions' },
2198+
status: 'COMPLETED',
2199+
conclusion: 'FAILURE',
2200+
checkRuns: {
2201+
nodes: [
2202+
{
2203+
name: 'test-linux',
2204+
status: 'COMPLETED',
2205+
conclusion: 'FAILURE',
2206+
detailsUrl: 'https://github.com/nodejs/node/runs/1'
2207+
},
2208+
{
2209+
name: 'test-pending',
2210+
status: 'IN_PROGRESS',
2211+
conclusion: null,
2212+
detailsUrl: 'https://github.com/nodejs/node/runs/2'
2213+
}
2214+
]
2215+
}
2216+
}]
2217+
}
2218+
}
2219+
}];
2220+
2221+
const expectedLogs = {
2222+
error: [
2223+
['1 GitHub CI job(s) failed:'],
2224+
[' - test-linux: FAILURE (https://github.com/nodejs/node/runs/1)']
2225+
]
2226+
};
2227+
2228+
const data = Object.assign({}, baseData, { commits: mixedStatusJobs });
2229+
const checker = new PRChecker(cli, data, {}, testArgv);
2230+
2231+
const status = await checker.checkCI();
2232+
assert(!status);
2233+
cli.assertCalledWith(expectedLogs);
2234+
});
19442235
});
19452236

19462237
describe('checkAuthor', () => {

0 commit comments

Comments
 (0)