retry request on failure to save attestation

Signed-off-by: Brian DeHamer <bdehamer@github.com>
This commit is contained in:
Brian DeHamer
2024-04-24 11:31:11 -07:00
parent 29885a805e
commit 0e8fe8af62
5 changed files with 282 additions and 56 deletions

View File

@@ -1,7 +1,12 @@
import * as github from '@actions/github'
import {retry} from '@octokit/plugin-retry'
const CREATE_ATTESTATION_REQUEST = 'POST /repos/{owner}/{repo}/attestations'
const DEFAULT_RETRY_COUNT = 5
export type WriteOptions = {
retry?: number
}
/**
* Writes an attestation to the repository's attestations endpoint.
* @param attestation - The attestation to write.
@@ -11,9 +16,11 @@ const CREATE_ATTESTATION_REQUEST = 'POST /repos/{owner}/{repo}/attestations'
*/
export const writeAttestation = async (
attestation: unknown,
token: string
token: string,
options: WriteOptions = {}
): Promise<string> => {
const octokit = github.getOctokit(token)
const retries = options.retry ?? DEFAULT_RETRY_COUNT
const octokit = github.getOctokit(token, {retry: {retries}}, retry)
try {
const response = await octokit.request(CREATE_ATTESTATION_REQUEST, {