@simbo/github-actions-octokit 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # @simbo/github-actions-octokit
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 3222348: Add `@simbo/github-actions-octokit` to create an Octokit client for
8
+ GitHub Actions that waits and retries on rate limits.
9
+
10
+ - `createOctokit()` authenticates with a token through `getOctokit` from
11
+ `@actions/github` and passes further options on.
12
+ - Requests that hit the primary or secondary rate limit are retried up to
13
+ `RATE_LIMIT_MAX_RETRIES` (4) times with `@octokit/plugin-throttling`, and
14
+ `shouldRetryOnRateLimit()` logs each decision as a warning.
15
+ - `hasStatus()` checks whether an error has a given HTTP status.
package/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2026 Simon Lepel <simbo@simbo.de> (https://simbo.de)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,91 @@
1
- # Temporary Holding Version
1
+ # GitHub Actions Octokit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 📦
4
+ [**`@simbo/github-actions-octokit`**](https://npmjs.com/package/@simbo/github-actions-octokit)
5
+
6
+ Create an authenticated Octokit client for GitHub Actions that waits and retries
7
+ on rate limits.
8
+
9
+ Built on `getOctokit` from `@actions/github` and the official plugin
10
+ `@octokit/plugin-throttling`.
11
+
12
+ ## Features
13
+
14
+ - `createOctokit()` returns the client of `getOctokit`, with the REST endpoint
15
+ methods, pagination, and GraphQL
16
+
17
+ - Requests that hit the primary or secondary rate limit wait as long as GitHub
18
+ asks and are retried up to `RATE_LIMIT_MAX_RETRIES` (4) times
19
+
20
+ - Every retry and the final failure are logged as warnings in the workflow run
21
+
22
+ - `hasStatus()` checks whether a failed request has a given HTTP status, such as
23
+ 404 or 422
24
+
25
+ ## Requirements
26
+
27
+ Requires Node.js `^24.15.0 || >=26.0.0`. Meant for JavaScript actions, since it
28
+ logs with `@actions/core`.
29
+
30
+ ## Installation
31
+
32
+ Install `@simbo/github-actions-octokit` from the npm registry:
33
+
34
+ ```bash
35
+ npm i @simbo/github-actions-octokit
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ For a complete API reference, see the
41
+ [documentation](https://simbo.de/packages/modules/_simbo_github-actions-octokit/).
42
+
43
+ ```ts
44
+ import { getInput } from '@actions/core';
45
+ import { createOctokit, hasStatus } from '@simbo/github-actions-octokit';
46
+
47
+ const octokit = createOctokit(getInput('token', { required: true }));
48
+
49
+ try {
50
+ await octokit.rest.git.getRef({
51
+ owner: 'simbo',
52
+ repo: 'packages',
53
+ ref: 'tags/v1.0.0',
54
+ });
55
+ } catch (error) {
56
+ if (!hasStatus(error, 404)) {
57
+ throw error;
58
+ }
59
+ // the tag does not exist
60
+ }
61
+ ```
62
+
63
+ ### Rate Limits
64
+
65
+ When GitHub reports a rate limit, the client waits for the time that GitHub
66
+ names and retries the request. After `RATE_LIMIT_MAX_RETRIES` retries, it gives
67
+ up and the request rejects with the error of GitHub. Each decision is logged
68
+ with `warning` from `@actions/core`:
69
+
70
+ ```text
71
+ The secondary rate limit was reached for POST /repos/{owner}/{repo}/git/refs; retrying in 60 seconds (retry 1 of 4).
72
+ The primary rate limit persists for GET /repos/{owner}/{repo}; giving up after 4 retries.
73
+ ```
74
+
75
+ `shouldRetryOnRateLimit()` makes this decision and can serve as a handler for
76
+ your own Octokit client with `@octokit/plugin-throttling`.
77
+
78
+ ### Options
79
+
80
+ The second argument of `createOctokit()` takes the options of `getOctokit` from
81
+ `@actions/github`, such as `baseUrl`, `userAgent`, `previews`, or `log`.
82
+
83
+ | Option | Description | Default |
84
+ | ---------- | ------------------------------------------------------------------------------------------------------------- | -------------------------- |
85
+ | `baseUrl` | The URL of the GitHub API. | `GITHUB_API_URL` or GitHub |
86
+ | `request` | Request options; replaces the defaults of `@actions/github` as a whole, including its proxy support. | proxy-aware `fetch` |
87
+ | `throttle` | Settings of `@octokit/plugin-throttling`; the handlers `onRateLimit` and `onSecondaryRateLimit` are replaced. | the defaults of the plugin |
88
+
89
+ ## License
90
+
91
+ [MIT © Simon Lepel](https://simbo.mit-license.org/2026/)
@@ -0,0 +1,56 @@
1
+ import { getOctokit } from '@actions/github';
2
+ /**
3
+ * An authenticated Octokit client with rate limit handling.
4
+ */
5
+ export type Octokit = ReturnType<typeof getOctokit>;
6
+ /**
7
+ * The options of `getOctokit` from `@actions/github`, such as `baseUrl`,
8
+ * `userAgent`, or `request`.
9
+ */
10
+ export type CreateOctokitOptions = NonNullable<Parameters<typeof getOctokit>[1]>;
11
+ /**
12
+ * The kind of rate limit that GitHub reports.
13
+ */
14
+ export type RateLimitKind = 'primary' | 'secondary';
15
+ /**
16
+ * The parts of a request description used in log messages.
17
+ */
18
+ export interface RateLimitedRequest {
19
+ /**
20
+ * The HTTP method, such as `GET`.
21
+ */
22
+ method: string;
23
+ /**
24
+ * The URL template of the request, such as `/repos/{owner}/{repo}`.
25
+ */
26
+ url: string;
27
+ }
28
+ /**
29
+ * Maximum number of retries of a request that hits a rate limit.
30
+ */
31
+ export declare const RATE_LIMIT_MAX_RETRIES = 4;
32
+ /**
33
+ * Decides whether to retry a request that hit a rate limit, and logs a warning
34
+ * with `warning` from `@actions/core`.
35
+ *
36
+ * @param kind - The kind of rate limit, for the log message.
37
+ * @param retryAfter - The seconds GitHub asks to wait.
38
+ * @param request - The request that hit the rate limit.
39
+ * @param retryCount - The number of retries so far.
40
+ * @returns `true` to retry after the wait time, `false` after
41
+ * {@link RATE_LIMIT_MAX_RETRIES} retries.
42
+ */
43
+ export declare function shouldRetryOnRateLimit(kind: RateLimitKind, retryAfter: number, request: RateLimitedRequest, retryCount: number): boolean;
44
+ /**
45
+ * Creates an authenticated Octokit client with `getOctokit` from
46
+ * `@actions/github` that waits and retries when GitHub reports a rate limit,
47
+ * using the official plugin `@octokit/plugin-throttling`.
48
+ *
49
+ * Both rate limit handlers call {@link shouldRetryOnRateLimit} and replace any
50
+ * handlers in `options.throttle`; its other settings are kept.
51
+ *
52
+ * @param token - The token to authenticate with, such as `GITHUB_TOKEN`.
53
+ * @param options - Further options for `getOctokit`.
54
+ * @returns The Octokit client.
55
+ */
56
+ export declare function createOctokit(token: string, options?: CreateOctokitOptions): Octokit;
@@ -0,0 +1,51 @@
1
+ import { warning } from '@actions/core';
2
+ import { getOctokit } from '@actions/github';
3
+ import { throttling } from '@octokit/plugin-throttling';
4
+ /**
5
+ * Maximum number of retries of a request that hits a rate limit.
6
+ */
7
+ export const RATE_LIMIT_MAX_RETRIES = 4;
8
+ /**
9
+ * Decides whether to retry a request that hit a rate limit, and logs a warning
10
+ * with `warning` from `@actions/core`.
11
+ *
12
+ * @param kind - The kind of rate limit, for the log message.
13
+ * @param retryAfter - The seconds GitHub asks to wait.
14
+ * @param request - The request that hit the rate limit.
15
+ * @param retryCount - The number of retries so far.
16
+ * @returns `true` to retry after the wait time, `false` after
17
+ * {@link RATE_LIMIT_MAX_RETRIES} retries.
18
+ */
19
+ export function shouldRetryOnRateLimit(kind, retryAfter, request, retryCount) {
20
+ const description = `${request.method} ${request.url}`;
21
+ if (retryCount >= RATE_LIMIT_MAX_RETRIES) {
22
+ warning(`The ${kind} rate limit persists for ${description}; giving up after ${retryCount} retries.`);
23
+ return false;
24
+ }
25
+ warning(`The ${kind} rate limit was reached for ${description}; retrying in ${retryAfter} seconds ` +
26
+ `(retry ${retryCount + 1} of ${RATE_LIMIT_MAX_RETRIES}).`);
27
+ return true;
28
+ }
29
+ /**
30
+ * Creates an authenticated Octokit client with `getOctokit` from
31
+ * `@actions/github` that waits and retries when GitHub reports a rate limit,
32
+ * using the official plugin `@octokit/plugin-throttling`.
33
+ *
34
+ * Both rate limit handlers call {@link shouldRetryOnRateLimit} and replace any
35
+ * handlers in `options.throttle`; its other settings are kept.
36
+ *
37
+ * @param token - The token to authenticate with, such as `GITHUB_TOKEN`.
38
+ * @param options - Further options for `getOctokit`.
39
+ * @returns The Octokit client.
40
+ */
41
+ export function createOctokit(token, options = {}) {
42
+ return getOctokit(token, {
43
+ ...options,
44
+ throttle: {
45
+ ...options.throttle,
46
+ onRateLimit: (retryAfter, request, _octokit, retryCount) => shouldRetryOnRateLimit('primary', retryAfter, request, retryCount),
47
+ onSecondaryRateLimit: (retryAfter, request, _octokit, retryCount) => shouldRetryOnRateLimit('secondary', retryAfter, request, retryCount),
48
+ },
49
+ }, throttling);
50
+ }
51
+ //# sourceMappingURL=create-octokit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-octokit.js","sourceRoot":"","sources":["../src/create-octokit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAiCxD;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAExC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,sBAAsB,CACpC,IAAmB,EACnB,UAAkB,EAClB,OAA2B,EAC3B,UAAkB;IAElB,MAAM,WAAW,GAAG,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACvD,IAAI,UAAU,IAAI,sBAAsB,EAAE,CAAC;QACzC,OAAO,CAAC,OAAO,IAAI,4BAA4B,WAAW,qBAAqB,UAAU,WAAW,CAAC,CAAC;QACtG,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,CACL,OAAO,IAAI,+BAA+B,WAAW,iBAAiB,UAAU,WAAW;QACzF,UAAU,UAAU,GAAG,CAAC,OAAO,sBAAsB,IAAI,CAC5D,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa,EAAE,UAAgC,EAAE;IAC7E,OAAO,UAAU,CACf,KAAK,EACL;QACE,GAAG,OAAO;QACV,QAAQ,EAAE;YACR,GAAG,OAAO,CAAC,QAAQ;YACnB,WAAW,EAAE,CAAC,UAAkB,EAAE,OAA2B,EAAE,QAAiB,EAAE,UAAkB,EAAE,EAAE,CACtG,sBAAsB,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC;YACpE,oBAAoB,EAAE,CACpB,UAAkB,EAClB,OAA2B,EAC3B,QAAiB,EACjB,UAAkB,EAClB,EAAE,CAAC,sBAAsB,CAAC,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC;SAC1E;KACF,EACD,UAAU,CACX,CAAC;AACJ,CAAC","sourcesContent":["import { warning } from '@actions/core';\nimport { getOctokit } from '@actions/github';\nimport { throttling } from '@octokit/plugin-throttling';\n\n/**\n * An authenticated Octokit client with rate limit handling.\n */\nexport type Octokit = ReturnType<typeof getOctokit>;\n\n/**\n * The options of `getOctokit` from `@actions/github`, such as `baseUrl`,\n * `userAgent`, or `request`.\n */\nexport type CreateOctokitOptions = NonNullable<Parameters<typeof getOctokit>[1]>;\n\n/**\n * The kind of rate limit that GitHub reports.\n */\nexport type RateLimitKind = 'primary' | 'secondary';\n\n/**\n * The parts of a request description used in log messages.\n */\nexport interface RateLimitedRequest {\n /**\n * The HTTP method, such as `GET`.\n */\n method: string;\n\n /**\n * The URL template of the request, such as `/repos/{owner}/{repo}`.\n */\n url: string;\n}\n\n/**\n * Maximum number of retries of a request that hits a rate limit.\n */\nexport const RATE_LIMIT_MAX_RETRIES = 4;\n\n/**\n * Decides whether to retry a request that hit a rate limit, and logs a warning\n * with `warning` from `@actions/core`.\n *\n * @param kind - The kind of rate limit, for the log message.\n * @param retryAfter - The seconds GitHub asks to wait.\n * @param request - The request that hit the rate limit.\n * @param retryCount - The number of retries so far.\n * @returns `true` to retry after the wait time, `false` after\n * {@link RATE_LIMIT_MAX_RETRIES} retries.\n */\nexport function shouldRetryOnRateLimit(\n kind: RateLimitKind,\n retryAfter: number,\n request: RateLimitedRequest,\n retryCount: number,\n): boolean {\n const description = `${request.method} ${request.url}`;\n if (retryCount >= RATE_LIMIT_MAX_RETRIES) {\n warning(`The ${kind} rate limit persists for ${description}; giving up after ${retryCount} retries.`);\n return false;\n }\n warning(\n `The ${kind} rate limit was reached for ${description}; retrying in ${retryAfter} seconds ` +\n `(retry ${retryCount + 1} of ${RATE_LIMIT_MAX_RETRIES}).`,\n );\n return true;\n}\n\n/**\n * Creates an authenticated Octokit client with `getOctokit` from\n * `@actions/github` that waits and retries when GitHub reports a rate limit,\n * using the official plugin `@octokit/plugin-throttling`.\n *\n * Both rate limit handlers call {@link shouldRetryOnRateLimit} and replace any\n * handlers in `options.throttle`; its other settings are kept.\n *\n * @param token - The token to authenticate with, such as `GITHUB_TOKEN`.\n * @param options - Further options for `getOctokit`.\n * @returns The Octokit client.\n */\nexport function createOctokit(token: string, options: CreateOctokitOptions = {}): Octokit {\n return getOctokit(\n token,\n {\n ...options,\n throttle: {\n ...options.throttle,\n onRateLimit: (retryAfter: number, request: RateLimitedRequest, _octokit: unknown, retryCount: number) =>\n shouldRetryOnRateLimit('primary', retryAfter, request, retryCount),\n onSecondaryRateLimit: (\n retryAfter: number,\n request: RateLimitedRequest,\n _octokit: unknown,\n retryCount: number,\n ) => shouldRetryOnRateLimit('secondary', retryAfter, request, retryCount),\n },\n },\n throttling,\n );\n}\n"]}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Checks whether an error is an HTTP error with the given status, such as a
3
+ * `RequestError` that Octokit throws for a failed request.
4
+ *
5
+ * @param error - The error to check.
6
+ * @param status - The expected HTTP status.
7
+ * @returns `true` if the error has a `status` property with the given value.
8
+ */
9
+ export declare function hasStatus(error: unknown, status: number): error is {
10
+ status: number;
11
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Checks whether an error is an HTTP error with the given status, such as a
3
+ * `RequestError` that Octokit throws for a failed request.
4
+ *
5
+ * @param error - The error to check.
6
+ * @param status - The expected HTTP status.
7
+ * @returns `true` if the error has a `status` property with the given value.
8
+ */
9
+ export function hasStatus(error, status) {
10
+ return typeof error === 'object' && error !== null && 'status' in error && error.status === status;
11
+ }
12
+ //# sourceMappingURL=has-status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-status.js","sourceRoot":"","sources":["../src/has-status.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc,EAAE,MAAc;IACtD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,QAAQ,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC;AACrG,CAAC","sourcesContent":["/**\n * Checks whether an error is an HTTP error with the given status, such as a\n * `RequestError` that Octokit throws for a failed request.\n *\n * @param error - The error to check.\n * @param status - The expected HTTP status.\n * @returns `true` if the error has a `status` property with the given value.\n */\nexport function hasStatus(error: unknown, status: number): error is { status: number } {\n return typeof error === 'object' && error !== null && 'status' in error && error.status === status;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './create-octokit.js';
2
+ export * from './has-status.js';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './create-octokit.js';
2
+ export * from './has-status.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './create-octokit.js';\nexport * from './has-status.js';\n"]}
package/package.json CHANGED
@@ -1,6 +1,68 @@
1
1
  {
2
2
  "name": "@simbo/github-actions-octokit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "description": "Create an authenticated Octokit client for GitHub Actions that waits and retries on rate limits.",
4
+ "version": "1.0.0",
5
+ "keywords": [
6
+ "github-actions",
7
+ "octokit",
8
+ "github",
9
+ "github-api",
10
+ "rate-limit",
11
+ "throttling",
12
+ "retry",
13
+ "typescript"
14
+ ],
15
+ "author": "Simon Lepel <simbo@simbo.de> (https://simbo.de/)",
16
+ "license": "MIT",
17
+ "homepage": "https://github.com/simbo/packages/tree/main/packages/github-actions-octokit",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/simbo/packages.git",
21
+ "directory": "packages/github-actions-octokit"
22
+ },
23
+ "bugs": "https://github.com/simbo/packages/issues",
24
+ "engines": {
25
+ "node": "^24.15.0 || >=26.0.0"
26
+ },
27
+ "type": "module",
28
+ "exports": {
29
+ ".": "./dist/index.js"
30
+ },
31
+ "files": [
32
+ "CHANGELOG.md",
33
+ "dist",
34
+ "LICENSE.md",
35
+ "README.md"
36
+ ],
37
+ "dependencies": {
38
+ "@actions/core": "^3.0.1",
39
+ "@actions/github": "^9.1.1",
40
+ "@octokit/plugin-throttling": "^11.0.5"
41
+ },
42
+ "devDependencies": {
43
+ "@simbo/eslint-config": "5.0.0",
44
+ "@simbo/tsconfig": "3.0.1",
45
+ "@types/node": "^24.19.2",
46
+ "@vitest/coverage-v8": "^5.1.1",
47
+ "@vitest/ui": "^5.1.1",
48
+ "eslint": "^10.15.0",
49
+ "jiti": "^2.7.0",
50
+ "typescript": "^6.0.3",
51
+ "vitest": "^5.1.1"
52
+ },
53
+ "scripts": {
54
+ "build": "tsc --project tsconfig.build.json",
55
+ "check": "pnpm run check:eslint && pnpm run check:types",
56
+ "check:eslint": "eslint --config ./eslint.config.ts --max-warnings 0",
57
+ "check:types": "tsc --noEmit",
58
+ "clean": "pnpm run clean:dist && pnpm run clean:coverage && pnpm run clean:turbo && pnpm run clean:node_modules",
59
+ "clean:dist": "rm -rf dist",
60
+ "clean:node_modules": "rm -rf node_modules",
61
+ "clean:turbo": "rm -rf .turbo",
62
+ "clean:coverage": "rm -rf coverage",
63
+ "fix:eslint": "pnpm run check:eslint --fix",
64
+ "test": "vitest run --coverage",
65
+ "test:ui": "pnpm run test:watch --ui",
66
+ "test:watch": "vitest dev --coverage"
67
+ }
6
68
  }