Skip to content

Commit

Permalink
Merge pull request #19 from animuk/master
Browse files Browse the repository at this point in the history
Added support for build ecosystem and scan enabled flag in Jenkins
  • Loading branch information
animuk authored Nov 21, 2018
2 parents bc1cc61 + dff1dae commit bf14378
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
- rename the pipeline step
-->
<artifactId>bayesian</artifactId>
<version>0.3.0</version>
<version>0.3.2</version>
<packaging>hpi</packaging>

<properties>
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/com/redhat/jenkins/plugins/bayesian/Bayesian.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@
private static final String DEFAULT_OSIO_USERS_FILTER = "username";
private String url;
private String gitUrl;
private String ecosystem;

public Bayesian() throws URISyntaxException {
this(DEFAULT_BAYESIAN_URL, "");
this(DEFAULT_BAYESIAN_URL, "", "");
}

public Bayesian(String url, String gitUrl) throws URISyntaxException {
public Bayesian(String url, String gitUrl, String ecosystem) throws URISyntaxException {
URI uri = new URI(url);
String host = uri.getHost();
if (host.indexOf('.') == -1) {
Expand All @@ -78,6 +79,7 @@ public Bayesian(String url, String gitUrl) throws URISyntaxException {
}
this.url = uri.toString();
this.gitUrl = gitUrl;
this.ecosystem = ecosystem;
}

public BayesianStepResponse submitStackForAnalysis(Collection<FilePath> manifests, Collection<FilePath> deps) throws BayesianException {
Expand Down Expand Up @@ -119,11 +121,10 @@ public BayesianStepResponse submitStackForAnalysis(Collection<FilePath> manifest
httpPost.setHeader("Authorization", "Bearer " + getAuthToken());
httpPost.setHeader("UserEmail", getEmail());

boolean scanEnabled = isScanEnabled();
if(scanEnabled) {
httpPost.setHeader("ScanRepoUrl", getGitUrl());
}

httpPost.setHeader("ScanRepoUrl", getGitUrl());
httpPost.setHeader("IsScanEnabled", isScanEnabled()? "true": "false");
httpPost.setHeader("ecosystem", getEcosystem());

BayesianResponse responseObj = null;
Gson gson;
try (CloseableHttpClient client = HttpClients.createDefault();
Expand Down Expand Up @@ -338,4 +339,9 @@ private String getFilteringData() {
String nameSpace = System.getenv("PROJECT_NAMESPACE");
return (nameSpace != null) ? nameSpace : "Data-Not-Found";
}

public String getEcosystem() {
return ecosystem;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public final class BayesianAnalysisStep extends Step {

private String url;
private String gitUrl;
private String ecosystem;

@DataBoundConstructor
public BayesianAnalysisStep() {
Expand All @@ -65,6 +66,15 @@ public String getGitUrl() {
return gitUrl;
}

@DataBoundSetter
public void setEcosystem(String ecosystem) {
this.ecosystem = ecosystem;
}

public String getEcosystem() {
return ecosystem;
}

@Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl) super.getDescriptor();
Expand Down Expand Up @@ -109,12 +119,13 @@ protected BayesianStepResponse run() throws Exception {
// TODO: refactor
String url = (step.getUrl() != null) ? step.getUrl() : Bayesian.getDefaultUrl();
String girUtl = (step.getGitUrl() != null) ? step.getGitUrl() : "";
Bayesian bayesian = new Bayesian(url,girUtl);
Bayesian bayesian = new Bayesian(url,girUtl,step.getEcosystem());

BayesianStepResponse response = null;
try {
logger.println("Running Bayesian stack analysis...");
logger.println("Bayesian API URL is " + bayesian.getApiUrl());
logger.println("Bayesian Ecosystem is " + bayesian.getEcosystem());
response = bayesian.submitStackForAnalysis(manifests,deps);
} catch (Throwable e) {
// intentionally not failing the build here
Expand Down

0 comments on commit bf14378

Please sign in to comment.