-
Notifications
You must be signed in to change notification settings - Fork 38
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
Support GitHubAppCredentials owner inference when specified on a pipeline using GitHub SCM #396
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #396 +/- ##
============================================
- Coverage 71.80% 71.77% -0.04%
- Complexity 162 165 +3
============================================
Files 16 16
Lines 532 542 +10
Branches 51 52 +1
============================================
+ Hits 382 389 +7
- Misses 124 125 +1
- Partials 26 28 +2 ☔ View full report in Codecov by Sentry. |
apiUri = gitHubAppCredentials.getApiUri(); | ||
if (context instanceof GitHubSCMSourceChecksContext) { | ||
final var gitHubSCMSourceChecksContext = (GitHubSCMSourceChecksContext) context; | ||
credentials = gitHubAppCredentials.withOwner(gitHubSCMSourceChecksContext.getOwner()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could add a test to
github-checks-plugin/src/test/java/io/jenkins/plugins/checks/github/GitHubChecksPublisherITest.java
Line 77 in c8db062
public class GitHubChecksPublisherITest { |
In the existing test the owner is set on the SCM context but not on the credentials
@@ -35,6 +36,9 @@ public class GitHubChecksPublisher extends ChecksPublisher { | |||
private final PluginLogger buildLogger; | |||
private final String gitHubUrl; | |||
|
|||
@Nullable | |||
private StandardUsernameCredentials credentials; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
credentials
where moved from method variable to class field. This helps GitHubChecksPublisherITest
to check that owner is propagated from context to credentials.
final var gitHubAppCredentials = (GitHubAppCredentials) credentials; | ||
if (context instanceof GitHubSCMSourceChecksContext) { | ||
final var gitHubSCMSourceChecksContext = (GitHubSCMSourceChecksContext) context; | ||
credentials = gitHubAppCredentials.withOwner(gitHubSCMSourceChecksContext.getOwner()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I think it is undesirable to have the withOwner
method be considered a public API of the plugin. Is there a reason we cannot use Connector.lookupScanCredentials
from github-branch-source
instead to handle contextualization automatically? It looks like it would require some API changes to SCMFacade
methods to have them accept an owner
parameter, but would that be ok, or is there some fundamental problem with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds fine if someone wants to work on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll create a follow-up PR ASAP.
GitHub App installed in multiple organizations get:
Steps to reproduce:
This fixes the issue by explicitly setting
owner
on contextualized credentials. This also needs jenkinsci/github-branch-source-plugin#803 to make it work. I manually tested this PR withgithub-branch-source-plugin
snapshot. The owner is inferred as expected and the build runs without any exception.