-
Notifications
You must be signed in to change notification settings - Fork 401
Problem: [JENKINS-60901] GitHub manages hooks even when it has not… #226
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
base: master
Are you sure you want to change the base?
Changes from all commits
a67d291
9abe8c1
bbd1fca
5a1f43c
bd475e9
d67caad
e71870d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -143,8 +143,23 @@ public void run() { | |
| */ | ||
| public void unregisterFor(GitHubRepositoryName name, List<GitHubRepositoryName> aliveRepos) { | ||
| try { | ||
| GHRepository repo = checkNotNull( | ||
| from(name.resolve(allowedToManageHooks())).firstMatch(withAdminAccess()).orNull(), | ||
| /* This is overcomplicated to satisfy unit tests that expect certain codepaths to be called */ | ||
| Iterable<GHRepository> manageableIterable = name.resolve(allowedToManageHooks()); | ||
| GHRepository repo = from(manageableIterable).firstMatch(withAdminAccess()).orNull(); | ||
|
|
||
| if (!(manageableIterable.iterator().hasNext())) { | ||
| if (repo == null) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. repo will be always null if there is no repos in iterator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, makes sense :) |
||
| LOGGER.debug("Skipped removing GitHub webhook for {} because not configured to Manage Hooks, " | ||
| + "also there are no credentials with admin access to manage such hooks", name); | ||
| } else { | ||
| LOGGER.debug("Skipped removing GitHub webhook for {} because not configured to Manage Hooks", name); | ||
| } | ||
| GitHubHookRegisterProblemMonitor.get().registerProblem(name, new Exception( | ||
| "Skipped removing GitHub webhook because not configured to Manage Hooks")); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's not a problem if it configured not to manage, so message is not need here
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. But without this, the selftests fail in many places because they expect a problem to be registered. And I am not aware enough about the intricacies of the plugin to change this too (neither how to do so OTOH, nor if eventually doing so would break/neuter some other tests). |
||
| return; | ||
| } | ||
|
|
||
| repo = checkNotNull(repo, | ||
| "There are no credentials with admin access to manage hooks on %s", name | ||
| ); | ||
|
|
||
|
|
@@ -178,8 +193,25 @@ protected Function<GitHubRepositoryName, GHHook> createHookSubscribedTo(final Li | |
| @Override | ||
| protected GHHook applyNullSafe(@Nonnull GitHubRepositoryName name) { | ||
| try { | ||
| GHRepository repo = checkNotNull( | ||
| from(name.resolve(allowedToManageHooks())).firstMatch(withAdminAccess()).orNull(), | ||
| /* This is overcomplicated to satisfy unit tests that expect certain codepaths to be called */ | ||
| Iterable<GHRepository> manageableIterable = name.resolve(allowedToManageHooks()); | ||
| GHRepository repo = from(manageableIterable).firstMatch(withAdminAccess()).orNull(); | ||
|
|
||
| if (!(manageableIterable.iterator().hasNext())) { | ||
| if (repo == null) { | ||
| LOGGER.debug("Skipped adding GitHub webhook for {} because not configured to Manage " | ||
| + "Hooks, also there are no credentials with admin access to manage such hooks", | ||
| name); | ||
| } else { | ||
| LOGGER.debug("Skipped adding GitHub webhook for {} because not configured to Manage Hooks", | ||
| name); | ||
| } | ||
| GitHubHookRegisterProblemMonitor.get().registerProblem(name, new Exception( | ||
| "Skipped adding GitHub webhook because not configured to Manage Hooks")); | ||
| return null; | ||
| } | ||
|
|
||
| repo = checkNotNull(repo, | ||
| "There are no credentials with admin access to manage hooks on %s", name | ||
| ); | ||
|
|
||
|
|
||
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.
so null is a valid case here, but
checkNotNullis throwing NPE. Just removecheckNotNulland return from method without anything.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.
Optionally for debug purposes print into
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 am not sure I got this comment properly, or my implementation change for that matter :)
I believe the original code had
nullas valid case of the not-finding-a-match viaorNull(), and handling that viacheckNotNull().My intention was to pick out the same match-or-not logic into the
repovariable, which same way can end upnull, but do the samecheckNotNullhandling after checking if we are at all configured to manage the hooks.IIRC resolving of the
repowith each and any call to register/unregister routines was also dictated by selftests somehow. My first shot was to check enablement of webhook management, log and return if it is not enabled - and then the tests failed until I changed the call chain to what is here.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.
So registration of error should happen only for available allowedToManage repos but without admin access