Skip to content

Commit

Permalink
[FIXED JENKINS-60825] Based on issue comment add NPE safety
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenc committed Jun 4, 2020
1 parent d94b490 commit 7ff03b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Propertly fetch tags ([JENKINS-61258](https://issues.jenkins-ci.org/browse/JENKINS-61258))
* Handle unknown pull request event payload actions ([JENKINS-61753](https://issues.jenkins-ci.org/browse/JENKINS-61753))
* Reluctantly adding `@Symbol` to the branch discovery traits ([JENKINS-60885](https://issues.jenkins-ci.org/browse/JENKINS-60885)). For anyone wondering why reluctantly... the idea behind `@Symbol` is that it is supposed to use type information to determine the set of possible candidates for a specific injection point. The current implementation of `@Symbol` support, however, decides to ignore type information from generics - even though that information is used elseweher in Jenkins and thus for the `@Symbol` case it gets confused and thinks that e.g. GitHub's `BranchDiscoveryTrait` is a viable candidate for injection into the Gitea SCM classes. As a result we cannot use default naming and thus have to add an explicit name. Even worse each SCM plugin has to prefix with their own names leading to an excess of `gitea` in configuration snippets. The final insult to injury is the naming conventions that have been followed. It pains me no end to have to add this workaround just because the symbol api maintainers refuse to add the type info filtering.
* Hopefully workaround NPE in branch discovery where there is a PR from a head that has already been deleted ([JENKINS-60825](https://issues.jenkins-ci.org/browse/JENKINS-60825))

## Version 1.2.0 (2020-02-17)

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/jenkinsci/plugin/gitea/BranchDiscoveryTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ public static class ExcludeOriginPRBranchesSCMHeadFilter extends SCMHeadFilter {
public boolean isExcluded(@NonNull SCMSourceRequest request, @NonNull SCMHead head) {
if (head instanceof BranchSCMHead && request instanceof GiteaSCMSourceRequest) {
for (GiteaPullRequest p : ((GiteaSCMSourceRequest) request).getPullRequests()) {
if (p.getHead() == null || p.getHead().getRepo() == null
|| p.getHead().getRepo().getOwner() == null
|| p.getHead().getRepo().getName() == null
|| p.getHead().getRef() == null
) {
// the head has already been deleted, so ignore as we cannot build yet JENKINS-60825
// TODO figure out if we can build a PR who's head has been deleted as it should be possible
return true;
}
// only match if the pull request is an origin pull request
if (StringUtils.equalsIgnoreCase(
p.getBase().getRepo().getOwner().getUsername(),
Expand Down Expand Up @@ -262,6 +271,15 @@ public static class OnlyOriginPRBranchesSCMHeadFilter extends SCMHeadFilter {
public boolean isExcluded(@NonNull SCMSourceRequest request, @NonNull SCMHead head) {
if (head instanceof BranchSCMHead && request instanceof GiteaSCMSourceRequest) {
for (GiteaPullRequest p : ((GiteaSCMSourceRequest) request).getPullRequests()) {
if (p.getHead() == null || p.getHead().getRepo() == null
|| p.getHead().getRepo().getOwner() == null
|| p.getHead().getRepo().getName() == null
|| p.getHead().getRef() == null
) {
// the head has already been deleted, so ignore as we cannot build yet JENKINS-60825
// TODO figure out if we can build a PR who's head has been deleted as it should be possible
return true;
}
if (StringUtils.equalsIgnoreCase(
p.getBase().getRepo().getOwner().getUsername(),
p.getHead().getRepo().getOwner().getUsername())
Expand Down

0 comments on commit 7ff03b7

Please sign in to comment.