Skip to content

Commit bf14378

Browse files
authored
Merge pull request #19 from animuk/master
Added support for build ecosystem and scan enabled flag in Jenkins
2 parents bc1cc61 + dff1dae commit bf14378

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
- rename the pipeline step
3232
-->
3333
<artifactId>bayesian</artifactId>
34-
<version>0.3.0</version>
34+
<version>0.3.2</version>
3535
<packaging>hpi</packaging>
3636

3737
<properties>

src/main/java/com/redhat/jenkins/plugins/bayesian/Bayesian.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@
5555
private static final String DEFAULT_OSIO_USERS_FILTER = "username";
5656
private String url;
5757
private String gitUrl;
58+
private String ecosystem;
5859

5960
public Bayesian() throws URISyntaxException {
60-
this(DEFAULT_BAYESIAN_URL, "");
61+
this(DEFAULT_BAYESIAN_URL, "", "");
6162
}
6263

63-
public Bayesian(String url, String gitUrl) throws URISyntaxException {
64+
public Bayesian(String url, String gitUrl, String ecosystem) throws URISyntaxException {
6465
URI uri = new URI(url);
6566
String host = uri.getHost();
6667
if (host.indexOf('.') == -1) {
@@ -78,6 +79,7 @@ public Bayesian(String url, String gitUrl) throws URISyntaxException {
7879
}
7980
this.url = uri.toString();
8081
this.gitUrl = gitUrl;
82+
this.ecosystem = ecosystem;
8183
}
8284

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

122-
boolean scanEnabled = isScanEnabled();
123-
if(scanEnabled) {
124-
httpPost.setHeader("ScanRepoUrl", getGitUrl());
125-
}
126-
124+
httpPost.setHeader("ScanRepoUrl", getGitUrl());
125+
httpPost.setHeader("IsScanEnabled", isScanEnabled()? "true": "false");
126+
httpPost.setHeader("ecosystem", getEcosystem());
127+
127128
BayesianResponse responseObj = null;
128129
Gson gson;
129130
try (CloseableHttpClient client = HttpClients.createDefault();
@@ -338,4 +339,9 @@ private String getFilteringData() {
338339
String nameSpace = System.getenv("PROJECT_NAMESPACE");
339340
return (nameSpace != null) ? nameSpace : "Data-Not-Found";
340341
}
342+
343+
public String getEcosystem() {
344+
return ecosystem;
345+
}
346+
341347
}

src/main/java/com/redhat/jenkins/plugins/bayesian/BayesianAnalysisStep.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public final class BayesianAnalysisStep extends Step {
4242

4343
private String url;
4444
private String gitUrl;
45+
private String ecosystem;
4546

4647
@DataBoundConstructor
4748
public BayesianAnalysisStep() {
@@ -65,6 +66,15 @@ public String getGitUrl() {
6566
return gitUrl;
6667
}
6768

69+
@DataBoundSetter
70+
public void setEcosystem(String ecosystem) {
71+
this.ecosystem = ecosystem;
72+
}
73+
74+
public String getEcosystem() {
75+
return ecosystem;
76+
}
77+
6878
@Override
6979
public DescriptorImpl getDescriptor() {
7080
return (DescriptorImpl) super.getDescriptor();
@@ -109,12 +119,13 @@ protected BayesianStepResponse run() throws Exception {
109119
// TODO: refactor
110120
String url = (step.getUrl() != null) ? step.getUrl() : Bayesian.getDefaultUrl();
111121
String girUtl = (step.getGitUrl() != null) ? step.getGitUrl() : "";
112-
Bayesian bayesian = new Bayesian(url,girUtl);
122+
Bayesian bayesian = new Bayesian(url,girUtl,step.getEcosystem());
113123

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

0 commit comments

Comments
 (0)