String getCIStatusEndpoint()

in src/main/java/org/apache/sling/cli/impl/ci/CIStatusValidator.java [98:133]


    String getCIStatusEndpoint(Path artifactFilePath) {
        log.trace("getCIStatusEndpoint");
        String ciEndpoint = null;
        try {
            builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
            DocumentBuilder builder = builderFactory.newDocumentBuilder();

            Document xmlDocument = builder.parse(artifactFilePath.toFile());
            XPath xPath = xPathFactory.newXPath();
            String repositoryName = (String) xPath.compile("/project/scm/url/text()").evaluate(xmlDocument, XPathConstants.STRING);
            String tagName = (String) xPath.compile("/project/scm/tag/text()").evaluate(xmlDocument, XPathConstants.STRING);
            if (!tagName.isEmpty()) {
                tagName = tagName.trim();
                log.debug("Extracted TAG: {}", tagName);
            }
            if (repositoryName != null && repositoryName.trim().length() > 0) {
                if (repositoryName.startsWith("https://gitbox.apache.org/repos/asf?p=")) {
                    repositoryName = repositoryName.substring(repositoryName.indexOf("?p=") + 3);
                    repositoryName = repositoryName.substring(0, repositoryName.indexOf(".git"));
                } else if (repositoryName.startsWith("https://github.com/apache/sling-")) {
                    repositoryName = repositoryName.substring(26);
                    if (repositoryName.contains("/")) {
                        repositoryName = repositoryName.substring(0, repositoryName.indexOf('/'));
                    }
                }
                log.debug("Extracted REPO: {}", repositoryName);
            }
            if (repositoryName != null && !repositoryName.isEmpty() && !tagName.isEmpty() && !tagName.equalsIgnoreCase("HEAD")) {
                ciEndpoint = String.format("https://api.github.com/repos/apache/%s/commits/%s/status", repositoryName, tagName);
                log.debug("Loaded CI Endpoint: {}", ciEndpoint);
            }
        } catch (XPathExpressionException | SAXException | IOException | ParserConfigurationException e) {
            log.debug("Failed to extract SCM URL", e);
        }
        return ciEndpoint;
    }