This is an automated email from the ASF dual-hosted git repository.
dklco pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-committer-cli.git
The following commit(s) were added to refs/heads/master by this push:
new cb4348f SLING-12148 - Fixing CI Validation Failure (#26)
cb4348f is described below
commit cb4348f76e89e4d53db0b8d0ed597e77b22efa63
Author: Dan Klco <[email protected]>
AuthorDate: Mon Nov 13 11:05:13 2023 -0500
SLING-12148 - Fixing CI Validation Failure (#26)
* Adding more logging to failure to get CI status
* Catching all exceptions rather than just the expected ones
* Fixing extra .git suffix
* Tweaking log message
* Adding test to verify
---
.../sling/cli/impl/ci/CIStatusValidator.java | 12 ++++++--
.../sling/cli/impl/ci/CIStatusValidatorTest.java | 6 ++++
src/test/resources/ci/gh-repo-1.0.pom | 32 ++++++++++++++++++++++
3 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/sling/cli/impl/ci/CIStatusValidator.java
b/src/main/java/org/apache/sling/cli/impl/ci/CIStatusValidator.java
index 25ca1c0..c4190c8 100644
--- a/src/main/java/org/apache/sling/cli/impl/ci/CIStatusValidator.java
+++ b/src/main/java/org/apache/sling/cli/impl/ci/CIStatusValidator.java
@@ -120,6 +120,10 @@ public class CIStatusValidator {
repositoryName = repositoryName.substring(0,
repositoryName.indexOf('/'));
}
}
+ // strip off the .git suffix from the repo name if it exists
+ if(repositoryName.endsWith(".git")) {
+ repositoryName = repositoryName.substring(0,
repositoryName.length() - 4);
+ }
log.debug("Extracted REPO: {}", repositoryName);
}
if (repositoryName != null && !repositoryName.isEmpty() &&
!tagName.isEmpty() && !tagName.equalsIgnoreCase("HEAD")) {
@@ -139,8 +143,9 @@ public class CIStatusValidator {
if (ciEndpoint == null) {
return new ValidationResult(false, "Cannot extract a CI endpoint
from " + artifactFilePath.getFileName());
}
+ JsonObject status = null;
try {
- JsonObject status = fetchJson(ciEndpoint);
+ status = fetchJson(ciEndpoint);
if ("pending".equals(status.get(PN_STATE).getAsString())
&& status.get("statuses").getAsJsonArray().size() == 0) {
@@ -172,8 +177,9 @@ public class CIStatusValidator {
} else {
return new ValidationResult(false, message);
}
- } catch (UnsupportedOperationException | IOException e) {
- return new ValidationResult(false, "Failed to get CI Status: " +
e.toString());
+ } catch (Exception e) {
+ return new ValidationResult(false,
+ "Failed to get CI Status: " + e.toString() + "\nCI Status
Url: " + ciEndpoint + "\nCI Status Body: " + status);
}
}
diff --git
a/src/test/java/org/apache/sling/cli/impl/ci/CIStatusValidatorTest.java
b/src/test/java/org/apache/sling/cli/impl/ci/CIStatusValidatorTest.java
index 9aa127f..6c5e4d5 100644
--- a/src/test/java/org/apache/sling/cli/impl/ci/CIStatusValidatorTest.java
+++ b/src/test/java/org/apache/sling/cli/impl/ci/CIStatusValidatorTest.java
@@ -146,4 +146,10 @@ public class CIStatusValidatorTest {
assertNotNull(valid.getMessage());
}
+ @Test
+ public void supportsGitHubUrls() throws URISyntaxException {
+ ValidationResult valid =
validator.isValid(getResourcePath("/ci/gh-repo-1.0.pom"));
+ assertTrue(valid.isValid());
+ assertNotNull(valid.getMessage());
+ }
}
diff --git a/src/test/resources/ci/gh-repo-1.0.pom
b/src/test/resources/ci/gh-repo-1.0.pom
new file mode 100644
index 0000000..d15caae
--- /dev/null
+++ b/src/test/resources/ci/gh-repo-1.0.pom
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with this work
for additional
+ information regarding copyright ownership. The ASF licenses this file to
you under the Apache License, Version 2.0 (the "License"); you may not use this
file except
+ in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or
agreed to
+ in writing, software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See
+ the License for the specific language governing permissions and
limitations under the License. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"
+>
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling-bundle-parent</artifactId>
+ <version>35</version>
+ <relativePath />
+ </parent>
+
+ <artifactId>repo-pom</artifactId>
+ <version>1.1</version>
+
+ <name>Repo POM</name>
+ <description>A Sample POM File with a repo</description>
+
+ <scm>
+
<connection>scm:git:https://gitbox.apache.org/repos/asf/sling-repo-pom.git</connection>
+
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-repo-pom.git</developerConnection>
+ <url>https://github.com/apache/sling-repo-pom.git</url>
+ <tag>repo-pom-1.1</tag>
+ </scm>
+
+</project>