22
22
import org .slf4j .Logger ;
23
23
import org .slf4j .LoggerFactory ;
24
24
25
+ import java .util .Collection ;
25
26
import java .util .Set ;
26
27
27
28
import static com .google .common .collect .Sets .immutableEnumSet ;
@@ -66,6 +67,9 @@ protected Set<GHEvent> events() {
66
67
* @param event only PUSH event
67
68
*/
68
69
@ Override
70
+ @ edu .umd .cs .findbugs .annotations .SuppressFBWarnings (
71
+ value = "SIC_INNER_SHOULD_BE_STATIC_ANON" , justification = "anonymous inner class is acceptable"
72
+ )
69
73
protected void onEvent (final GHSubscriberEvent event ) {
70
74
GHEventPayload .Push push ;
71
75
try {
@@ -77,7 +81,7 @@ protected void onEvent(final GHSubscriberEvent event) {
77
81
URL repoUrl = push .getRepository ().getUrl ();
78
82
final String pusherName = push .getPusher ().getName ();
79
83
final String ref = push .getRef ();
80
- LOGGER .info ("Received PushEvent for {} from {}" , repoUrl , event .getOrigin ());
84
+ LOGGER .info ("Received PushEvent for {} {} from {}" , repoUrl , ref , event .getOrigin ());
81
85
GitHubRepositoryName fromEventRepository = GitHubRepositoryName .create (repoUrl .toExternalForm ());
82
86
83
87
if (fromEventRepository == null ) {
@@ -94,12 +98,8 @@ protected void onEvent(final GHSubscriberEvent event) {
94
98
}
95
99
96
100
final GitHubRepositoryName changedRepository = fromEventRepository ;
97
-
98
101
if (changedRepository != null ) {
99
- // run in high privilege to see all the projects anonymous users don't see.
100
- // this is safe because when we actually schedule a build, it's a build that can
101
- // happen at some random time anyway.
102
- Runnable body = new Runnable () {
102
+ final Runnable body = new Runnable () {
103
103
@ Override
104
104
public void run () {
105
105
for (Item job : Jenkins .get ().getAllItems (Item .class )) {
@@ -109,32 +109,48 @@ public void run() {
109
109
}
110
110
String fullDisplayName = job .getFullDisplayName ();
111
111
LOGGER .debug ("Considering to poke {}" , fullDisplayName );
112
- if (!GitHubRepositoryNameContributor .parseAssociatedNames (job ).contains (changedRepository )) {
113
- LOGGER .debug ("Skipped {} because it doesn't have a matching repository." , fullDisplayName );
112
+ final Collection <GitHubRepositoryName > names =
113
+ GitHubRepositoryNameContributor .parseAssociatedNames (job );
114
+ if (!names .contains (changedRepository )) {
115
+ LOGGER .debug (
116
+ "Skipped {} because {} doesn't have a matching repository for {}." ,
117
+ fullDisplayName , names , changedRepository );
114
118
continue ;
115
119
}
116
- boolean foundBranch = false ;
117
- for (GitHubBranch branch : GitHubRepositoryNameContributor .parseAssociatedBranches (job )) {
118
- if (branch .matches (changedRepository , ref )) {
119
- foundBranch = true ;
120
- break ;
120
+ try {
121
+ final Collection <GitHubBranch > branchSpecs =
122
+ GitHubRepositoryNameContributor .parseAssociatedBranches (job );
123
+ if (!branchSpecs .isEmpty ()) {
124
+ boolean foundBranch = false ;
125
+ for (GitHubBranch branch : branchSpecs ) {
126
+ if (branch .matches (changedRepository , ref )) {
127
+ foundBranch = true ;
128
+ break ;
129
+ }
130
+ }
131
+ if (!foundBranch ) {
132
+ LOGGER .debug ("Skipped {} because it doesn't have a matching branch specifier." ,
133
+ job .getFullDisplayName ());
134
+ continue ;
135
+ }
121
136
}
122
- }
123
- if (!foundBranch ) {
124
- LOGGER .debug ("Skipped {} because it doesn't have a matching branch specifier." ,
125
- job .getFullDisplayName ());
126
- continue ;
137
+ } catch (Exception e ) {
138
+ LOGGER .error ("parseAssociatedBranches threw exception" , e );
127
139
}
128
140
LOGGER .info ("Poked {}" , fullDisplayName );
129
141
trigger .onPost (GitHubTriggerEvent .create ()
130
142
.withTimestamp (event .getTimestamp ())
131
143
.withOrigin (event .getOrigin ())
132
144
.withTriggeredByUser (pusherName )
145
+ .withTriggeredByRef (ref )
133
146
.build ()
134
147
);
135
148
}
136
149
}
137
150
};
151
+ // run in high privilege to see all the projects anonymous users don't see.
152
+ // this is safe because when we actually schedule a build, it's a build that can
153
+ // happen at some random time anyway.
138
154
ACL .impersonate (ACL .SYSTEM , body );
139
155
140
156
for (GitHubWebHook .Listener listener : ExtensionList .lookup (GitHubWebHook .Listener .class )) {
0 commit comments