Skip to content
Permalink
Browse files

Merge pull request #67 from jenkins-infra/develop

[WEBSITE-640, WEBSITE-650] - Promote Plugin Site API 1.7.0 to production
  • Loading branch information...
oleg-nenashev committed Sep 5, 2019
2 parents 9194b92 + 6934a42 commit a1e744236541e2a84832bf7fee9b40068f83c2fe
@@ -0,0 +1,6 @@
# See https://github.com/jenkinsci/.github/blob/master/.github/release-drafter.adoc
_extends: jenkinsci/.github
# Semantic versioning: https://semver.org/
version-template: $MAJOR.$MINOR.$PATCH
tag-template: v$NEXT_MINOR_VERSION
name-template: v$NEXT_MINOR_VERSION
@@ -3,3 +3,6 @@ target/
*.iml
*.sw*
plugins.json.gzip
.classpath
.project
.settings
@@ -1,5 +1,11 @@
= Plugin Site API

image:https://img.shields.io/github/release/jenkins-infra/plugin-site-api.svg?label=release[link="https://github.com/jenkins-infra/plugin-site-api/releases/latest"]

:toc:
:toc-placement: preamble
:toclevels: 3

This is the backend API for Jenkins Plugin Site frontend. It provides a REST API
to allow searching for plugins and retrieving specific plugin information.

@@ -13,8 +13,14 @@
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class GithubExtractor implements WikiExtractor {
/**
* Bootstrap class setting !important padding. Scrapped by extractor
* to avoid !important override.
*/
public static final String BOOTSTRAP_PADDING_5 = "p-5";

private static final String README_ENDPOINT = "https://api.github.com/repos/jenkinsci/%s/readme?client_id=%s&client_secret=%s";
private static final Pattern REPO_PATTERN = Pattern
@@ -61,7 +67,11 @@ public String extractHtml(String apiContent, String url, HttpClientWikiService s
private void convertLinksToAbsolute(HttpClientWikiService service, Element wikiContent, String orgName, String repoName, String branch) {
String documentationHost = String.format("https://github.com/%s/%s/blob/%s", orgName, repoName, branch);
String imageHost = String.format("https://cdn.jsdelivr.net/gh/%s/%s@%s", orgName, repoName, branch);

Elements headings = wikiContent.getElementsByTag("H1");
if (headings.size() == 1) {
headings.get(0).remove();
}
wikiContent.getElementsByClass(BOOTSTRAP_PADDING_5).forEach(element -> element.removeClass(BOOTSTRAP_PADDING_5));
// Relative hyperlinks, we resolve "/docs/rest-api.adoc" as https://github.com/jenkinsci/folder-auth-plugin/blob/master/docs/rest-api.adoc
wikiContent.getElementsByAttribute("href").forEach(element -> service.replaceAttribute(element, "href", documentationHost, "/"));

@@ -24,6 +24,7 @@

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@@ -108,7 +109,7 @@ private String getHttpContent(String url, List<Header> headers) {
final CloseableHttpResponse response = httpClient.execute(get)) {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
final HttpEntity entity = response.getEntity();
final String html = EntityUtils.toString(entity);
final String html = EntityUtils.toString(entity, StandardCharsets.UTF_8);
EntityUtils.consume(entity);
return html;
} else {
@@ -8,6 +8,7 @@

import org.apache.commons.io.FileUtils;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Matcher;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
@@ -18,6 +19,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Locale;

public class WikiServiceTest {

@@ -42,6 +44,12 @@ public void testGetWikiContentGit() {
final String url = "https://github.com/jenkinsci/labelled-steps-plugin";
final String content = wikiService.getWikiContent(url);
assertValidContent(content);
// heading inserted by plugin site, should be removed here
Assert.assertThat(content.toLowerCase(Locale.US),
CoreMatchers.not(CoreMatchers.containsString("<h1")));
// check removal of padding class that makes embedding hard
Assert.assertThat(content,
CoreMatchers.not(CoreMatchers.containsString(GithubExtractor.BOOTSTRAP_PADDING_5)));
}

@Test
@@ -183,9 +191,15 @@ private void assertValid(WikiExtractor extractor, String string) {

private void assertValidContent(String content) {
Assert.assertNotNull("Wiki content is null", content);
Assert.assertThat(content, isValidUnicode());
Assert.assertThat(content, CoreMatchers.not(CoreMatchers.containsString(
HttpClientWikiService.EXTERNAL_DOCUMENTATION_PREFIX)));
Assert.assertFalse("Wiki content is empty", content.isEmpty());
}

private Matcher<String> isValidUnicode() {
return CoreMatchers.not(CoreMatchers.containsString(
"\u00c2"));
}

}

0 comments on commit a1e7442

Please sign in to comment.
You can’t perform that action at this time.