mirror of
https://github.com/dorny/test-reporter.git
synced 2026-02-04 04:05:22 -08:00
Merge pull request #438 from JojOatXGME/fix-artifact-download-alternative
Fix problematic retransmission of authentication token (alternative solution) #438
This commit is contained in:
23
dist/index.js
generated
vendored
23
dist/index.js
generated
vendored
@@ -2153,26 +2153,11 @@ function downloadArtifact(octokit, artifactId, fileName, token) {
|
|||||||
const headers = {
|
const headers = {
|
||||||
Authorization: `Bearer ${token}`
|
Authorization: `Bearer ${token}`
|
||||||
};
|
};
|
||||||
const resp = yield (0, got_1.default)(req.url, {
|
const downloadStream = got_1.default.stream(req.url, { headers });
|
||||||
headers,
|
|
||||||
followRedirect: false
|
|
||||||
});
|
|
||||||
core.info(`Fetch artifact URL: ${resp.statusCode} ${resp.statusMessage}`);
|
|
||||||
if (resp.statusCode !== 302) {
|
|
||||||
throw new Error('Fetch artifact URL failed: received unexpected status code');
|
|
||||||
}
|
|
||||||
const url = resp.headers.location;
|
|
||||||
if (url === undefined) {
|
|
||||||
const receivedHeaders = Object.keys(resp.headers);
|
|
||||||
core.info(`Received headers: ${receivedHeaders.join(', ')}`);
|
|
||||||
throw new Error('Location header was not found in API response');
|
|
||||||
}
|
|
||||||
if (typeof url !== 'string') {
|
|
||||||
throw new Error(`Location header has unexpected value: ${url}`);
|
|
||||||
}
|
|
||||||
const downloadStream = got_1.default.stream(url, { headers });
|
|
||||||
const fileWriterStream = (0, fs_1.createWriteStream)(fileName);
|
const fileWriterStream = (0, fs_1.createWriteStream)(fileName);
|
||||||
core.info(`Downloading ${url}`);
|
downloadStream.on('redirect', response => {
|
||||||
|
core.info(`Downloading ${response.headers.location}`);
|
||||||
|
});
|
||||||
downloadStream.on('downloadProgress', ({ transferred }) => {
|
downloadStream.on('downloadProgress', ({ transferred }) => {
|
||||||
core.info(`Progress: ${transferred} B`);
|
core.info(`Progress: ${transferred} B`);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -50,33 +50,17 @@ export async function downloadArtifact(
|
|||||||
const headers = {
|
const headers = {
|
||||||
Authorization: `Bearer ${token}`
|
Authorization: `Bearer ${token}`
|
||||||
}
|
}
|
||||||
const resp = await got(req.url, {
|
|
||||||
headers,
|
|
||||||
followRedirect: false
|
|
||||||
})
|
|
||||||
|
|
||||||
core.info(`Fetch artifact URL: ${resp.statusCode} ${resp.statusMessage}`)
|
const downloadStream = got.stream(req.url, {headers})
|
||||||
if (resp.statusCode !== 302) {
|
|
||||||
throw new Error('Fetch artifact URL failed: received unexpected status code')
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = resp.headers.location
|
|
||||||
if (url === undefined) {
|
|
||||||
const receivedHeaders = Object.keys(resp.headers)
|
|
||||||
core.info(`Received headers: ${receivedHeaders.join(', ')}`)
|
|
||||||
throw new Error('Location header was not found in API response')
|
|
||||||
}
|
|
||||||
if (typeof url !== 'string') {
|
|
||||||
throw new Error(`Location header has unexpected value: ${url}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const downloadStream = got.stream(url, {headers})
|
|
||||||
const fileWriterStream = createWriteStream(fileName)
|
const fileWriterStream = createWriteStream(fileName)
|
||||||
|
|
||||||
core.info(`Downloading ${url}`)
|
downloadStream.on('redirect', response => {
|
||||||
|
core.info(`Downloading ${response.headers.location}`)
|
||||||
|
})
|
||||||
downloadStream.on('downloadProgress', ({transferred}) => {
|
downloadStream.on('downloadProgress', ({transferred}) => {
|
||||||
core.info(`Progress: ${transferred} B`)
|
core.info(`Progress: ${transferred} B`)
|
||||||
})
|
})
|
||||||
|
|
||||||
await asyncStream(downloadStream, fileWriterStream)
|
await asyncStream(downloadStream, fileWriterStream)
|
||||||
} finally {
|
} finally {
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
|
|||||||
Reference in New Issue
Block a user