Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

authStrategy does not inherit logger from Octokit #218

Closed
gr2m opened this issue Oct 15, 2020 · 5 comments · Fixed by #226
Closed

authStrategy does not inherit logger from Octokit #218

gr2m opened this issue Oct 15, 2020 · 5 comments · Fixed by #226
Labels
Type: Bug Something isn't working as documented

Comments

@gr2m
Copy link
Contributor

gr2m commented Oct 15, 2020

What happened?

@octokit/auth-app introduced a new log option, similar to Octokit's logging via octokit/auth-app.js#190. But when I pass a custom logger as options.log to Octokit, it is not passed down to the configured authentication strategy.

Example:

const { Octokit } = require("@octokit/core")
const { createAppAuth } = require("@octokit/auth-app");

const octokit = new Octokit({
  log: myCustomLogger
  authStrategy: createAppAuth,
  auth: {
    id: 1,
    privateKey: PRIVATE_KEY,
    installationId: 2
  }
})

octokit.request('GET /repos/octokit/core.js')

If GitHub responds with a 401 (usually due to a replication lag), @octokit/auth-app is logging a warning:

[@octokit/auth-app] Retrying after 401 response to account for token replication delay (retry: 1, wait: 1s)

But it logs using the default console.warn.

Test case that reproduces the problem:
https://runkit.com/gr2m/octokit-core-authstrategy-custom-logger/1.0.0

What did you expect to happen?

I expected that myCustomLogger from the Octokit constructor options is passed down to createAppAuth({ log }), so that myCustomLogger.log.warn is used to log the warning instead of console.warn.

What the problem might be

We do pass the internal request method as options.request to createAppAuth(options) by default, see

core.js/src/index.ts

Lines 141 to 148 in 4582982

const auth = options.authStrategy(
Object.assign(
{
request: this.request,
},
options.auth
)
);

We have to do the same with the internal log object

How to contribute

Comment below if you would like to work on this issue. Then follow the instructions in our contributing guidelines

@gr2m gr2m added the Type: Bug Something isn't working as documented label Oct 15, 2020
@ewanharris
Copy link
Contributor

ewanharris commented Oct 23, 2020

@gr2m can I claim this issue? Where would be the right place to add a test for this, log.test.ts or auth.test.ts?

@gr2m
Copy link
Contributor Author

gr2m commented Oct 23, 2020

you can add the test to https://github.com/octokit/core.js/blob/master/test/issues.test.ts, that's exactly what we created this file for :)

@ewanharris
Copy link
Contributor

Ah I just made the PR before I saw your comment. I'll move the test there and push a new commit

@gr2m
Copy link
Contributor Author

gr2m commented Oct 23, 2020

no need, it's good as is 👍🏼

@gr2m gr2m closed this as completed in #226 Oct 23, 2020
@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 3.1.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants