@@ -65,49 +65,50 @@ protected Set<GHEvent> events() {
65
65
*/
66
66
@ Override
67
67
protected void onEvent (GHEvent event , String payload ) {
68
+ GHEventPayload .Push push ;
68
69
try {
69
- GHEventPayload .Push push =
70
- GitHub .offline ().parseEventPayload (new StringReader (payload ), GHEventPayload .Push .class );
71
- URL repoUrl = push .getRepository ().getUrl ();
72
- final String pusherName = push .getPusher ().getName ();
73
- LOGGER .info ("Received PushEvent for {}" , repoUrl );
74
- final GitHubRepositoryName changedRepository = GitHubRepositoryName .create (repoUrl .toExternalForm ());
70
+ push = GitHub .offline ().parseEventPayload (new StringReader (payload ), GHEventPayload .Push .class );
71
+ } catch (IOException e ) {
72
+ LOGGER .warn ("Received malformed PushEvent: " + payload , e );
73
+ return ;
74
+ }
75
+ URL repoUrl = push .getRepository ().getUrl ();
76
+ final String pusherName = push .getPusher ().getName ();
77
+ LOGGER .info ("Received PushEvent for {}" , repoUrl );
78
+ final GitHubRepositoryName changedRepository = GitHubRepositoryName .create (repoUrl .toExternalForm ());
75
79
76
- if (changedRepository != null ) {
77
- // run in high privilege to see all the projects anonymous users don't see.
78
- // this is safe because when we actually schedule a build, it's a build that can
79
- // happen at some random time anyway.
80
- ACL .impersonate (ACL .SYSTEM , new Runnable () {
81
- @ Override
82
- public void run () {
83
- for (Item job : Jenkins .getInstance ().getAllItems (Item .class )) {
84
- GitHubTrigger trigger = triggerFrom (job , GitHubPushTrigger .class );
85
- if (trigger != null ) {
86
- String fullDisplayName = job .getFullDisplayName ();
87
- LOGGER .debug ("Considering to poke {}" , fullDisplayName );
88
- if (GitHubRepositoryNameContributor .parseAssociatedNames (job )
89
- .contains (changedRepository )) {
90
- LOGGER .info ("Poked {}" , fullDisplayName );
91
- trigger .onPost (pusherName );
92
- } else {
93
- LOGGER .debug ("Skipped {} because it doesn't have a matching repository." ,
94
- fullDisplayName );
95
- }
80
+ if (changedRepository != null ) {
81
+ // run in high privilege to see all the projects anonymous users don't see.
82
+ // this is safe because when we actually schedule a build, it's a build that can
83
+ // happen at some random time anyway.
84
+ ACL .impersonate (ACL .SYSTEM , new Runnable () {
85
+ @ Override
86
+ public void run () {
87
+ for (Item job : Jenkins .getInstance ().getAllItems (Item .class )) {
88
+ GitHubTrigger trigger = triggerFrom (job , GitHubPushTrigger .class );
89
+ if (trigger != null ) {
90
+ String fullDisplayName = job .getFullDisplayName ();
91
+ LOGGER .debug ("Considering to poke {}" , fullDisplayName );
92
+ if (GitHubRepositoryNameContributor .parseAssociatedNames (job )
93
+ .contains (changedRepository )) {
94
+ LOGGER .info ("Poked {}" , fullDisplayName );
95
+ trigger .onPost (pusherName );
96
+ } else {
97
+ LOGGER .debug ("Skipped {} because it doesn't have a matching repository." ,
98
+ fullDisplayName );
96
99
}
97
100
}
98
101
}
99
- });
100
-
101
- for (GitHubWebHook .Listener listener : Jenkins .getInstance ()
102
- .getExtensionList (GitHubWebHook .Listener .class )) {
103
- listener .onPushRepositoryChanged (pusherName , changedRepository );
104
102
}
103
+ });
105
104
106
- } else {
107
- LOGGER .warn ("Malformed repo url {}" , repoUrl );
105
+ for (GitHubWebHook .Listener listener : Jenkins .getInstance ()
106
+ .getExtensionList (GitHubWebHook .Listener .class )) {
107
+ listener .onPushRepositoryChanged (pusherName , changedRepository );
108
108
}
109
- } catch (IOException e ) {
110
- LOGGER .warn ("Received malformed PushEvent: " + payload , e );
109
+
110
+ } else {
111
+ LOGGER .warn ("Malformed repo url {}" , repoUrl );
111
112
}
112
113
}
113
114
}
0 commit comments