1
1
package com .cloudbees .jenkins ;
2
2
3
3
import hudson .Extension ;
4
+ import hudson .FilePath ;
4
5
import hudson .Launcher ;
5
6
import hudson .Util ;
6
- import hudson .model .AbstractBuild ;
7
7
import hudson .model .AbstractProject ;
8
- import hudson .model .BuildListener ;
9
8
import hudson .model .Result ;
9
+ import hudson .model .Run ;
10
+ import hudson .model .TaskListener ;
10
11
import hudson .tasks .BuildStepDescriptor ;
11
12
import hudson .tasks .BuildStepMonitor ;
12
13
import hudson .tasks .Notifier ;
13
14
import hudson .tasks .Publisher ;
14
15
import hudson .util .ListBoxModel ;
16
+ import jenkins .tasks .SimpleBuildStep ;
17
+
15
18
import org .eclipse .jgit .lib .ObjectId ;
16
19
import org .jenkinsci .plugins .github .common .ExpandableMessage ;
17
20
import org .jenkinsci .plugins .github .util .BuildDataHelper ;
41
44
*
42
45
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
43
46
*/
44
- public class GitHubCommitNotifier extends Notifier {
47
+ public class GitHubCommitNotifier extends Notifier implements SimpleBuildStep {
45
48
private static final ExpandableMessage DEFAULT_MESSAGE = new ExpandableMessage ("" );
46
49
47
50
private ExpandableMessage statusMessage = DEFAULT_MESSAGE ;
@@ -100,12 +103,12 @@ public BuildStepMonitor getRequiredMonitorService() {
100
103
}
101
104
102
105
@ Override
103
- public boolean perform (AbstractBuild <?, ?> build ,
106
+ public void perform (Run <?, ?> build ,
107
+ FilePath ws ,
104
108
Launcher launcher ,
105
- BuildListener listener ) throws InterruptedException , IOException {
109
+ TaskListener listener ) throws InterruptedException , IOException {
106
110
try {
107
111
updateCommitStatus (build , listener );
108
- return true ;
109
112
} catch (IOException error ) {
110
113
final Result buildResult = getEffectiveResultOnFailure ();
111
114
if (buildResult .equals (FAILURE )) {
@@ -118,19 +121,18 @@ public boolean perform(AbstractBuild<?, ?> build,
118
121
build .setResult (buildResult );
119
122
}
120
123
}
121
- return true ;
122
124
}
123
125
124
- private void updateCommitStatus (@ Nonnull AbstractBuild <?, ?> build ,
125
- @ Nonnull BuildListener listener ) throws InterruptedException , IOException {
126
+ private void updateCommitStatus (@ Nonnull Run <?, ?> build ,
127
+ @ Nonnull TaskListener listener ) throws InterruptedException , IOException {
126
128
final String sha1 = ObjectId .toString (BuildDataHelper .getCommitSHA1 (build ));
127
129
128
130
StatusResult status = statusFrom (build );
129
131
String message = defaultIfEmpty (firstNonNull (statusMessage , DEFAULT_MESSAGE )
130
132
.expandAll (build , listener ), status .getMsg ());
131
- String contextName = displayNameFor (build .getProject ());
133
+ String contextName = displayNameFor (build .getParent ());
132
134
133
- for (GitHubRepositoryName name : GitHubRepositoryNameContributor .parseAssociatedNames (build .getProject ())) {
135
+ for (GitHubRepositoryName name : GitHubRepositoryNameContributor .parseAssociatedNames (build .getParent ())) {
134
136
for (GHRepository repository : name .resolve ()) {
135
137
136
138
listener .getLogger ().println (
@@ -146,7 +148,7 @@ private void updateCommitStatus(@Nonnull AbstractBuild<?, ?> build,
146
148
}
147
149
}
148
150
149
- private static StatusResult statusFrom (@ Nonnull AbstractBuild <?, ?> build ) {
151
+ private static StatusResult statusFrom (@ Nonnull Run <?, ?> build ) {
150
152
Result result = build .getResult ();
151
153
152
154
// We do not use `build.getDurationString()` because it appends 'and counting' (build is still running)
0 commit comments