From 00fa0b28be3d9d332498cc2c4b91fcd9b9046bd5 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 22 Apr 2024 19:03:18 +0200 Subject: [PATCH 1/3] ci(action): update actions/checkout digest to 1d96c77 (#380) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/codeql.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/test.yml | 4 ++-- .github/workflows/update-prettier.yml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 3e669cb..c515fbc 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -18,7 +18,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4 with: # We must fetch at least the immediate parents so that if this is # a pull request then we can checkout the head. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 510b902..353a7d0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,7 +15,7 @@ jobs: name: release runs-on: ubuntu-latest steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4 - uses: actions/setup-node@v4 with: node-version: lts/* diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9f4ae55..5ba25d0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: - 18 - 20 steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4 - name: Use Node.js ${{ matrix.node_version }} uses: actions/setup-node@v4 with: @@ -33,7 +33,7 @@ jobs: steps: - run: exit 1 if: ${{ needs.test_matrix.result != 'success' }} - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4 - uses: actions/setup-node@v4 with: node-version: "lts/*" diff --git a/.github/workflows/update-prettier.yml b/.github/workflows/update-prettier.yml index d03357f..a1fbd11 100644 --- a/.github/workflows/update-prettier.yml +++ b/.github/workflows/update-prettier.yml @@ -7,7 +7,7 @@ jobs: update_prettier: runs-on: ubuntu-latest steps: - - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4 - uses: actions/setup-node@v4 with: cache: npm From 25434e22ea81a04f886dbd080258cf5ea033f49f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:54:56 -0700 Subject: [PATCH 2/3] ci(action): update actions/checkout digest to 0ad4b8f (#381) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/codeql.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/test.yml | 4 ++-- .github/workflows/update-prettier.yml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index c515fbc..10478a8 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -18,7 +18,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4 + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4 with: # We must fetch at least the immediate parents so that if this is # a pull request then we can checkout the head. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 353a7d0..12aa933 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,7 +15,7 @@ jobs: name: release runs-on: ubuntu-latest steps: - - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4 + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4 - uses: actions/setup-node@v4 with: node-version: lts/* diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5ba25d0..46ccd51 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: - 18 - 20 steps: - - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4 + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4 - name: Use Node.js ${{ matrix.node_version }} uses: actions/setup-node@v4 with: @@ -33,7 +33,7 @@ jobs: steps: - run: exit 1 if: ${{ needs.test_matrix.result != 'success' }} - - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4 + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4 - uses: actions/setup-node@v4 with: node-version: "lts/*" diff --git a/.github/workflows/update-prettier.yml b/.github/workflows/update-prettier.yml index a1fbd11..5f0ea48 100644 --- a/.github/workflows/update-prettier.yml +++ b/.github/workflows/update-prettier.yml @@ -7,7 +7,7 @@ jobs: update_prettier: runs-on: ubuntu-latest steps: - - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4 + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4 - uses: actions/setup-node@v4 with: cache: npm From 2431de57cae12cb98dcc528f8c44bb572001260b Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Thu, 2 May 2024 17:53:51 +0200 Subject: [PATCH 3/3] feat: add x-github-request-id into logging message (#382) --- src/index.ts | 9 ++++-- test/request-log.test.ts | 69 +++++++++++++++++++++++++++++++++------- 2 files changed, 64 insertions(+), 14 deletions(-) diff --git a/src/index.ts b/src/index.ts index 8ede717..29d949f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,8 +15,9 @@ export function requestLog(octokit: Octokit) { return (request as typeof octokit.request)(options) .then((response) => { + const requestId = response.headers["x-github-request-id"]; octokit.log.info( - `${requestOptions.method} ${path} - ${response.status} in ${ + `${requestOptions.method} ${path} - ${response.status} with id ${requestId} in ${ Date.now() - start }ms`, ); @@ -24,8 +25,10 @@ export function requestLog(octokit: Octokit) { }) .catch((error) => { - octokit.log.info( - `${requestOptions.method} ${path} - ${error.status} in ${ + const requestId = + error.response.headers["x-github-request-id"] || "UNKNOWN"; + octokit.log.error( + `${requestOptions.method} ${path} - ${error.status} with id ${requestId} in ${ Date.now() - start }ms`, ); diff --git a/test/request-log.test.ts b/test/request-log.test.ts index 8cdc958..581a853 100644 --- a/test/request-log.test.ts +++ b/test/request-log.test.ts @@ -5,10 +5,16 @@ import { jest } from "@jest/globals"; import { requestLog } from "../src/index.js"; describe("logging", () => { - it("logs sucessful 'GET /'", async () => { - const mock = fetchMock - .sandbox() - .getOnce("https://api.github.com/", { ok: true }); + it("logs successful 'GET /'", async () => { + const mock = fetchMock.sandbox().getOnce("https://api.github.com/", { + status: 200, + body: { + ok: true, + }, + headers: { + "x-github-request-id": "1234", + }, + }); const mockLogInfo = jest.fn(); const mockDebugInfo = jest.fn(); @@ -31,15 +37,22 @@ describe("logging", () => { method: "GET", url: "/", }); - expect(mockLogInfo.mock.calls[0][0]).toMatch(/GET \/ - 200 in \d+ms/); + expect(mockLogInfo.mock.calls[0][0]).toMatch( + /GET \/ - 200 with id 1234 in \d+ms/, + ); }); it("logs 404 for 'GET /unknown'", async () => { - const mock = fetchMock - .sandbox() - .getOnce("https://api.github.com/unknown", 404); + const mock = fetchMock.sandbox().getOnce("https://api.github.com/unknown", { + status: 404, + body: { message: "Not Found" }, + headers: { + "x-github-request-id": "1234", + }, + }); const mockLogInfo = jest.fn(); + const mockErrorInfo = jest.fn(); const mockDebugInfo = jest.fn(); const MyOctokit = Octokit.plugin(requestLog); const octokit = new MyOctokit({ @@ -50,15 +63,49 @@ describe("logging", () => { debug: mockDebugInfo, info: mockLogInfo, warn() {}, - error() {}, + error: mockErrorInfo, + }, + }); + + try { + await octokit.request("GET /unknown"); + } catch (error) { + expect(mockErrorInfo.mock.calls[0][0]).toMatch( + /GET \/unknown - 404 with id 1234 in \d+ms/, + ); + return; + } + + throw new Error('"GET /unknown" should not resolve'); + }); + + it("logs malformed error response for 'GET /unknown'", async () => { + const mock = fetchMock.sandbox().getOnce("https://api.github.com/unknown", { + status: 500, + body: "Internal Server Error", + }); + + const mockLogInfo = jest.fn(); + const mockErrorInfo = jest.fn(); + const mockDebugInfo = jest.fn(); + const MyOctokit = Octokit.plugin(requestLog); + const octokit = new MyOctokit({ + request: { + fetch: mock, + }, + log: { + debug: mockDebugInfo, + info: mockLogInfo, + warn() {}, + error: mockErrorInfo, }, }); try { await octokit.request("GET /unknown"); } catch (error) { - expect(mockLogInfo.mock.calls[0][0]).toMatch( - /GET \/unknown - 404 in \d+ms/, + expect(mockErrorInfo.mock.calls[0][0]).toMatch( + /GET \/unknown - 500 with id UNKNOWN in \d+ms/, ); return; }