jenkins-infra/plugin-modernizer-tool

Support for GitHub app authentication

Closed this issue ยท 6 comments

What feature do you want to see added?

If we want to run the CLI at scale (on GitHub actions or Jenkins infra) we will need to use a GitHub app token to be created and granted to open pull request on jenkinsci organisation

Until it's done we can use our own app, but we need to add support to authenticate with App JWT token

https://github-api.kohsuke.org/githubappappinsttokenauth.html
https://github-api.kohsuke.org/githubappjwtauth.html

Upstream changes

No response

Are you interested in contributing this feature?

Yes!

Is this error linked to this feature?

Failed to get primary email

Getting current user using token... 
(2fe74516) GitHub API request: GET https://api.github.com/user/emails 
io.jenkins.tools.pluginmodernizer.core.model.ModernizerException: Failed to get primary email
        at io.jenkins.tools.pluginmodernizer.core.github.GHService.getPrimaryEmail(GHService.java:626)
        at io.jenkins.tools.pluginmodernizer.core.github.GHService.connect(GHService.java:127)
        at io.jenkins.tools.pluginmodernizer.core.impl.PluginModernizer.start(PluginModernizer.java:48)
        at io.jenkins.tools.pluginmodernizer.cli.Main.run(Main.java:252)
        at picocli.CommandLine.executeUserObject(CommandLine.java:2030)
        at picocli.CommandLine.executeHelpRequest(CommandLine.java:2016)
        at picocli.CommandLine.executeHelpRequest(CommandLine.java:1987)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2272)
        at picocli.CommandLine$RunLast.execute(CommandLine.java:2421)
        at picocli.CommandLine.execute(CommandLine.java:2174)
        at io.jenkins.tools.pluginmodernizer.cli.Main.main(Main.java:47)
Caused by: org.kohsuke.github.GHFileNotFoundException: https://api.github.com/user/emails {"message":"Not Found","documentation_url":"https://docs.github.com/rest/users/emails#list-email-addresses-for-the-authenticated-user","status":"404"}
        at org.kohsuke.github.GitHubClient.interpretApiError(GitHubClient.java:737)
        at org.kohsuke.github.GitHubClient.sendRequest(GitHubClient.java:480)
        at org.kohsuke.github.GitHubPageIterator.fetch(GitHubPageIterator.java:146)
        at org.kohsuke.github.GitHubPageIterator.hasNext(GitHubPageIterator.java:93)
        at org.kohsuke.github.PagedIterator.fetch(PagedIterator.java:116)
        at org.kohsuke.github.PagedIterator.nextPageArray(PagedIterator.java:144)
        at org.kohsuke.github.PagedIterable.toArray(PagedIterable.java:85)
        at org.kohsuke.github.PagedIterable.toArray(PagedIterable.java:113)
        at org.kohsuke.github.PagedIterable.toList(PagedIterable.java:125)
        at io.jenkins.tools.pluginmodernizer.core.github.GHService.getPrimaryEmail(GHService.java:614)
        ... 10 more
Caused by: java.io.FileNotFoundException: https://api.github.com/user/emails
        at org.kohsuke.github.GitHubConnectorResponseErrorHandler$1.onError(GitHubConnectorResponseErrorHandler.java:79)
        at org.kohsuke.github.GitHubClient.detectKnownErrors(GitHubClient.java:504)
        at org.kohsuke.github.GitHubClient.sendRequest(GitHubClient.java:464)
        ... 18 more
Plugin Modernizer finished. 

404 on /emails ? This looks weird to me. Is it with your own GH_TOKEN ? Do you have permissions ot read email ? user:email permission

Let me change my token and see if it's working.
I've had this problem on GitPod and locally with different tokens, but both of them could be missing the right permission.
Do we refer to this permission in the README.md ?
Thanks. ๐Ÿ™

Okay, this was a typical chair-keyboard interface problem. ๐Ÿคฆ
I chose another token, and it now works. ๐Ÿคท

Stupid me. ๐Ÿ˜Š

Unless other permission are missing, it's documented here: https://github.com/jenkinsci/plugin-modernizer-tool?tab=readme-ov-file#setup

So double-stupid me, it's even in the documentation. ๐Ÿคฆ
Ashamed I should be. ๐Ÿ˜‰