-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Report pending and completion status to the associated VSTS commit #91
Changes from all commits
0cc595f
1830479
2d96312
2cb5bd0
54169e0
338b139
11ccbf1
6452fa8
87e4e34
2c8c125
b3c7fdf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package hudson.plugins.tfs; | ||
|
||
import hudson.Extension; | ||
import hudson.FilePath; | ||
import hudson.Launcher; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.plugins.tfs.util.VstsStatus; | ||
import hudson.tasks.BuildStepDescriptor; | ||
import hudson.tasks.BuildStepMonitor; | ||
import hudson.tasks.Notifier; | ||
import hudson.tasks.Publisher; | ||
import jenkins.tasks.SimpleBuildStep; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.io.IOException; | ||
|
||
/** | ||
* A _Post-Build Action_ that reports the completion status of an associated build to VSTS. | ||
*/ | ||
public class VstsCompletedStatusPostBuildAction extends Notifier implements SimpleBuildStep { | ||
|
||
@DataBoundConstructor | ||
public VstsCompletedStatusPostBuildAction() { | ||
|
||
} | ||
|
||
@Override | ||
public void perform( | ||
@Nonnull final Run<?, ?> run, | ||
@Nonnull final FilePath workspace, | ||
@Nonnull final Launcher launcher, | ||
@Nonnull final TaskListener listener | ||
) throws InterruptedException, IOException { | ||
try { | ||
VstsStatus.createFromRun(run); | ||
} | ||
catch (final Exception e) { | ||
e.printStackTrace(listener.error("Error while trying to update completion status in VSTS")); | ||
} | ||
} | ||
|
||
@Override | ||
public BuildStepMonitor getRequiredMonitorService() { | ||
// we don't need the outcome of any previous builds for this step | ||
return BuildStepMonitor.NONE; | ||
} | ||
|
||
@Extension | ||
public static class DescriptorImpl extends BuildStepDescriptor<Publisher> { | ||
|
||
@Override | ||
public boolean isApplicable(final Class<? extends AbstractProject> jobType) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Set completion status for VSTS commit or pull request"; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package hudson.plugins.tfs; | ||
|
||
import hudson.Extension; | ||
import hudson.FilePath; | ||
import hudson.Launcher; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.plugins.tfs.util.VstsStatus; | ||
import hudson.tasks.BuildStepDescriptor; | ||
import hudson.tasks.Builder; | ||
import jenkins.tasks.SimpleBuildStep; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.io.IOException; | ||
|
||
/** | ||
* A _Build Step_ that reports the status of an associated build as "Pending" to VSTS. | ||
*/ | ||
public class VstsPendingStatusBuildStep extends Builder implements SimpleBuildStep { | ||
|
||
@DataBoundConstructor | ||
public VstsPendingStatusBuildStep() { | ||
|
||
} | ||
|
||
@Override | ||
public void perform( | ||
@Nonnull final Run<?, ?> run, | ||
@Nonnull final FilePath workspace, | ||
@Nonnull final Launcher launcher, | ||
@Nonnull final TaskListener listener | ||
) throws InterruptedException, IOException { | ||
try { | ||
VstsStatus.createFromRun(run); | ||
} | ||
catch (final Exception e) { | ||
e.printStackTrace(listener.error("Error while trying to update pending status in VSTS")); | ||
} | ||
} | ||
|
||
@Extension | ||
public static class DescriptorImpl extends BuildStepDescriptor<Builder> { | ||
|
||
@Override | ||
public boolean isApplicable(Class<? extends AbstractProject> jobType) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Set pending status for VSTS commit or pull request"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we change "VSTS" to "Team Services" here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If it's OK with you, I'll make a sweep after merging this and #92. |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package hudson.plugins.tfs.model; | ||
|
||
import net.sf.ezmorph.MorphException; | ||
import net.sf.ezmorph.ObjectMorpher; | ||
|
||
public class GitStatusStateMorpher implements ObjectMorpher { | ||
|
||
public static final GitStatusStateMorpher INSTANCE = new GitStatusStateMorpher(); | ||
|
||
private GitStatusStateMorpher() { | ||
|
||
} | ||
|
||
@Override | ||
public Object morph(final Object value) { | ||
if (value == null) { | ||
return null; | ||
} | ||
|
||
if (!supports(value.getClass())) { | ||
throw new MorphException(value.getClass() + " is not supported"); | ||
} | ||
|
||
final String s = value.toString(); | ||
return GitStatusState.caseInsensitiveValueOf(s); | ||
} | ||
|
||
@Override | ||
public Class morphsTo() { | ||
return GitStatusState.class; | ||
} | ||
|
||
@Override | ||
public boolean supports(Class clazz) { | ||
return String.class.isAssignableFrom(clazz); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change "VSTS" to "Team Services" here?