-
Notifications
You must be signed in to change notification settings - Fork 75
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
Add dependency check results to Jenkins REST API #107
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -27,13 +27,20 @@ | |
import org.jenkinsci.plugins.DependencyCheck.model.Finding; | ||
import org.jenkinsci.plugins.DependencyCheck.model.SeverityDistribution; | ||
import org.jenkinsci.plugins.DependencyCheck.transformer.FindingsTransformer; | ||
import org.kohsuke.stapler.WebMethod; | ||
import org.kohsuke.stapler.bind.JavaScriptMethod; | ||
import org.kohsuke.stapler.export.Exported; | ||
import org.kohsuke.stapler.export.ExportedBean; | ||
import org.kohsuke.stapler.json.JsonHttpResponse; | ||
import org.kohsuke.stapler.verb.GET; | ||
|
||
import hudson.model.Action; | ||
import hudson.model.Api; | ||
import hudson.model.Run; | ||
import io.jenkins.plugins.util.AbstractXmlStream; | ||
import io.jenkins.plugins.util.BuildAction; | ||
import io.jenkins.plugins.util.JobAction; | ||
import net.sf.json.JSONArray; | ||
import net.sf.json.JSONObject; | ||
import net.sf.json.JsonConfig; | ||
|
||
|
@@ -43,6 +50,7 @@ | |
* @author Steve Springett ([email protected]) | ||
* @since 5.0.0 | ||
*/ | ||
@ExportedBean | ||
public class ResultAction extends BuildAction<DependencyCheckBuildResult> { | ||
|
||
private static final long serialVersionUID = -6533677178186658819L; | ||
|
@@ -135,4 +143,47 @@ | |
return JSONObject.fromObject(getSeverityDistribution(), jsonConfig); | ||
} | ||
|
||
public Api getApi() { | ||
return new Api(this); | ||
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. in this case we have to return only severity distribution so you can return |
||
} | ||
|
||
@Exported(visibility = 2) | ||
public int getCriticalCount() { | ||
return getSeverityDistribution().getCritical(); | ||
} | ||
|
||
@Exported(visibility = 2) | ||
public int getHighCount() { | ||
return getSeverityDistribution().getHigh(); | ||
} | ||
|
||
@Exported(visibility = 2) | ||
public int getMediumCount() { | ||
return getSeverityDistribution().getMedium(); | ||
} | ||
|
||
@Exported(visibility = 2) | ||
public int getLowCount() { | ||
return getSeverityDistribution().getLow(); | ||
} | ||
|
||
@Exported(visibility = 2) | ||
public int getInfoCount() { | ||
return getSeverityDistribution().getInfo(); | ||
} | ||
|
||
@Exported(visibility = 2) | ||
public int getUnassignedCount() { | ||
return getSeverityDistribution().getUnassigned(); | ||
} | ||
|
||
@GET | ||
@WebMethod(name = "findings") | ||
public JsonHttpResponse getFindingsExposedInRemoteApi() { | ||
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. I would not expose result unless a valid use case |
||
JSONObject tResult = new JSONObject(); | ||
JsonConfig jsonConfig = new JsonConfig(); | ||
jsonConfig.setExcludes(new String[] { "count", }); | ||
tResult.put("findings", JSONArray.fromObject(getFindings(), jsonConfig)); | ||
return new JsonHttpResponse(tResult, 200); | ||
} | ||
} |
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.
Miss API documentation (_api.jelly in the parent object folder)