mirror of https://github.com/actions/toolkit
lint
parent
deda97d5e6
commit
24da3e2d1c
|
@ -35,7 +35,7 @@ describe('artifact-http-client', () => {
|
||||||
msg.statusCode = 200
|
msg.statusCode = 200
|
||||||
return {
|
return {
|
||||||
message: msg,
|
message: msg,
|
||||||
readBody: () => {
|
readBody: async () => {
|
||||||
return Promise.resolve(
|
return Promise.resolve(
|
||||||
`{"ok": true, "signedUploadUrl": "http://localhost:8080/upload"}`
|
`{"ok": true, "signedUploadUrl": "http://localhost:8080/upload"}`
|
||||||
)
|
)
|
||||||
|
@ -72,7 +72,7 @@ describe('artifact-http-client', () => {
|
||||||
msgSucceeded.statusCode = 200
|
msgSucceeded.statusCode = 200
|
||||||
return {
|
return {
|
||||||
message: msgSucceeded,
|
message: msgSucceeded,
|
||||||
readBody: () => {
|
readBody: async () => {
|
||||||
return Promise.resolve(
|
return Promise.resolve(
|
||||||
`{"ok": true, "signedUploadUrl": "http://localhost:8080/upload"}`
|
`{"ok": true, "signedUploadUrl": "http://localhost:8080/upload"}`
|
||||||
)
|
)
|
||||||
|
@ -85,7 +85,7 @@ describe('artifact-http-client', () => {
|
||||||
msgFailed.statusMessage = 'Internal Server Error'
|
msgFailed.statusMessage = 'Internal Server Error'
|
||||||
return {
|
return {
|
||||||
message: msgFailed,
|
message: msgFailed,
|
||||||
readBody: () => {
|
readBody: async () => {
|
||||||
return Promise.resolve(`{"ok": false}`)
|
return Promise.resolve(`{"ok": false}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ describe('artifact-http-client', () => {
|
||||||
msgFailed.statusMessage = 'Internal Server Error'
|
msgFailed.statusMessage = 'Internal Server Error'
|
||||||
return {
|
return {
|
||||||
message: msgFailed,
|
message: msgFailed,
|
||||||
readBody: () => {
|
readBody: async () => {
|
||||||
return Promise.resolve(`{"ok": false}`)
|
return Promise.resolve(`{"ok": false}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ describe('artifact-http-client', () => {
|
||||||
msgFailed.statusMessage = 'Unauthorized'
|
msgFailed.statusMessage = 'Unauthorized'
|
||||||
return {
|
return {
|
||||||
message: msgFailed,
|
message: msgFailed,
|
||||||
readBody: () => {
|
readBody: async () => {
|
||||||
return Promise.resolve(`{"ok": false}`)
|
return Promise.resolve(`{"ok": false}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,9 @@ interface Rpc {
|
||||||
class ArtifactHttpClient implements Rpc {
|
class ArtifactHttpClient implements Rpc {
|
||||||
private httpClient: HttpClient
|
private httpClient: HttpClient
|
||||||
private baseUrl: string
|
private baseUrl: string
|
||||||
private maxAttempts: number = 5
|
private maxAttempts = 5
|
||||||
private baseRetryIntervalMilliseconds: number = 3000
|
private baseRetryIntervalMilliseconds = 3000
|
||||||
private retryMultiplier: number = 1.5
|
private retryMultiplier = 1.5
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
userAgent: string,
|
userAgent: string,
|
||||||
|
@ -52,14 +52,14 @@ class ArtifactHttpClient implements Rpc {
|
||||||
contentType: 'application/json' | 'application/protobuf',
|
contentType: 'application/json' | 'application/protobuf',
|
||||||
data: object | Uint8Array
|
data: object | Uint8Array
|
||||||
): Promise<object | Uint8Array> {
|
): Promise<object | Uint8Array> {
|
||||||
let url = `${this.baseUrl}/twirp/${service}/${method}`
|
const url = `${this.baseUrl}/twirp/${service}/${method}`
|
||||||
let headers = {
|
const headers = {
|
||||||
'Content-Type': contentType
|
'Content-Type': contentType
|
||||||
}
|
}
|
||||||
info(`Making request to ${url} with data: ${JSON.stringify(data)}`)
|
info(`Making request to ${url} with data: ${JSON.stringify(data)}`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await this.retryableRequest(() =>
|
const response = await this.retryableRequest(async () =>
|
||||||
this.httpClient.post(url, JSON.stringify(data), headers)
|
this.httpClient.post(url, JSON.stringify(data), headers)
|
||||||
)
|
)
|
||||||
const body = await response.readBody()
|
const body = await response.readBody()
|
||||||
|
|
Loading…
Reference in New Issue