2424import static org .kohsuke .github .GHEvent .PUSH ;
2525
2626/**
27- * By default this plugin interested in push events only when job uses {@link GitHubPushTrigger}
27+ * By default this plugin interested in push events only when job uses
28+ * {@link GitHubPushTrigger}
2829 *
2930 * @author lanwen (Merkushev Kirill)
3031 * @since 1.12.0
@@ -57,7 +58,7 @@ protected Set<GHEvent> events() {
5758 /**
5859 * Calls {@link GitHubPushTrigger} in all projects to handle this hook
5960 *
60- * @param event only PUSH event
61+ * @param event only PUSH event
6162 * @param payload payload of gh-event. Never blank
6263 */
6364 @ Override
@@ -67,32 +68,21 @@ protected void onEvent(GHEvent event, String payload) {
6768 final String pusherName = json .getJSONObject ("pusher" ).getString ("name" );
6869
6970 LOGGER .info ("Received POST for: {}, pusher: {}" , repoUrl , pusherName );
70- final GitHubRepositoryName changedRepository = GitHubRepositoryName .create (repoUrl );
71+ final GitHubRepositoryName changedRepository = GitHubRepositoryName
72+ .create (repoUrl );
7173
7274 if (changedRepository != null ) {
7375 // run in high privilege to see all the projects anonymous users don't see.
74- // this is safe because when we actually schedule a build, it's a build that can
76+ // this is safe because when we actually schedule a build, it's a build that
77+ // can
7578 // happen at some random time anyway.
7679 ACL .impersonate (ACL .SYSTEM , new Runnable () {
7780 @ Override
7881 public void run () {
7982 for (Job <?, ?> job : Jenkins .getInstance ().getAllItems (Job .class )) {
80- GitHubTrigger trigger = triggerFrom (job , GitHubPushTrigger .class );
81- if (trigger != null ) {
82- LOGGER .debug ("Considering to poke {}" , job .getFullDisplayName ());
83- if (GitHubRepositoryNameContributor .parseAssociatedNames (job ).contains (changedRepository )) {
84- LOGGER .info ("Poked {}" , job .getFullDisplayName ());
85- if (pusherName .equalsIgnoreCase (GitHubPlugin .configuration ().getBannedCommitter ())) {
86- LOGGER .info ("Skipped {} because user is banned: {}." , job .getFullDisplayName ()
87- , pusherName );
88- } else {
89- trigger .onPost (pusherName );
90- }
91- } else {
92- LOGGER .debug ("Skipped {} because it doesn't have a matching repository." ,
93- job .getFullDisplayName ());
94- }
95- }
83+ final GitHubTrigger trigger = triggerFrom (job ,
84+ GitHubPushTrigger .class );
85+ triggerJob (job , trigger , pusherName , changedRepository );
9686 }
9787 }
9888 });
@@ -101,9 +91,30 @@ public void run() {
10191 .getExtensionList (GitHubWebHook .Listener .class )) {
10292 listener .onPushRepositoryChanged (pusherName , changedRepository );
10393 }
104-
10594 } else {
106- LOGGER .warn ("Malformed repo url {}" , repoUrl );
95+ LOGGER .warn ("Malformed repo url: {}" , repoUrl );
96+ }
97+ }
98+
99+ static void triggerJob (Job <?, ?> job , GitHubTrigger trigger , String pusherName ,
100+ GitHubRepositoryName changedRepository ) {
101+ if (trigger != null ) {
102+ LOGGER .debug ("Considering to poke: {}" , job .getFullDisplayName ());
103+ if (GitHubRepositoryNameContributor .parseAssociatedNames (job )
104+ .contains (changedRepository )) {
105+ LOGGER .info ("Poked: {}" , job .getFullDisplayName ());
106+ if (pusherName .equalsIgnoreCase (
107+ GitHubPlugin .configuration ().getBannedCommitter ())) {
108+ LOGGER .info ("Job: {} skipped because user: {} is banned." ,
109+ job .getFullDisplayName (), pusherName );
110+ } else {
111+ trigger .onPost (pusherName );
112+ }
113+ } else {
114+ LOGGER .debug (
115+ "Job: {} skipped because it doesn't have a matching repository." ,
116+ job .getFullDisplayName ());
117+ }
107118 }
108119 }
109120}
0 commit comments