Skip to content

Commit

Permalink
🌱 Patterns for Badge detection
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperancinha committed May 13, 2021
1 parent e8cf287 commit 4c934e2
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 20 deletions.
22 changes: 17 additions & 5 deletions markdowner-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,28 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand All @@ -81,11 +98,6 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.11.4</version>
</dependency>
</dependencies>
<profiles>
<profile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.jesperancinha.parser.markdowner.badges.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Value;

import java.util.regex.Pattern;

@Value
@Builder
@AllArgsConstructor(onConstructor_ = @JsonCreator)
public class BadgePattern {
String title;
Pattern pattern;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@Value
@AllArgsConstructor(onConstructor_ = @JsonCreator)
public class BadgeSetting {
String title;
String badge;
String codePrefix;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.jesperancinha.parser.markdowner.badges.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Value;

import java.util.List;
import java.util.regex.Pattern;

@Value
@Builder
@AllArgsConstructor(onConstructor_ = @JsonCreator)
public class BadgeSettingGroup {
BadgeType badgeType;
List<BadgePattern> badgeSettingList;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package org.jesperancinha.parser.markdowner.badges.model;

public enum BadgeType {
INFO("jeorg.badges.info.json"),
BUILD("jeorg.badges.build.json"),
QUALITY("jeorg.badges.quality.json"),
COVERAGE("jeorg.badges.coverage.json"),
CONTENT("jeorg.badges.content.json");
INFO("jeorg.badges.info.json","Info.md"),
BUILD("jeorg.badges.build.json","Build.md"),
QUALITY("jeorg.badges.quality.json","Quality.md"),
COVERAGE("jeorg.badges.coverage.json","Coverage.md"),
CONTENT("jeorg.badges.content.json","Content.md");

private String badgeFile;
private final String badgeFile;

BadgeType(String badgeFile) {
private final String destinationFile;

BadgeType(String badgeFile, String destinationFile) {
this.badgeFile = badgeFile;
this.destinationFile = destinationFile;
}

public String getBadgeFile() {
return badgeFile;
}

public String getDestinationFile() {
return destinationFile;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,74 @@
package org.jesperancinha.parser.markdowner.badges.parser;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.jesperancinha.parser.markdowner.badges.model.BadgeGroup;
import org.jesperancinha.parser.markdowner.badges.model.BadgePattern;
import org.jesperancinha.parser.markdowner.badges.model.BadgeSetting;
import org.jesperancinha.parser.markdowner.badges.model.BadgeSettingGroup;
import org.jesperancinha.parser.markdowner.badges.model.BadgeType;
import org.jesperancinha.parser.markdowner.helper.TemplateParserHelper;
import org.jesperancinha.parser.markdowner.model.Paragraphs;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@Slf4j
public class BadgeParser {

public static List<BadgeGroup> parse(final String readme) {
private static final ObjectMapper objectMapper = new ObjectMapper();

public static List<BadgeGroup> parse(final InputStream readmeInputStream) {
final var badgeSettingGroups = parseSettings();
badgeSettingGroups.stream().map(badgeSettingGroup ->
badgeSettingGroup.getBadgeSettingList()
.stream().map(badgeSetting -> {
return null;
})
);
try (BufferedReader br = new BufferedReader(new InputStreamReader(readmeInputStream))) {
String s;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}


static List<BadgeSettingGroup> parseSettings() {
return Arrays.stream(BadgeType.values())
.map(badgeType -> {
try {
final var badgeSettingList = Arrays.stream(objectMapper.readValue(
BadgeParser.class.getResourceAsStream("/".concat(badgeType.getBadgeFile())),
BadgeSetting[].class)).collect(Collectors.toList());
return BadgeSettingGroup
.builder()
.badgeType(badgeType)
.badgeSettingList(
badgeSettingList
.stream().map(badgeSetting ->
BadgePattern.builder()
.title(badgeSetting.getTitle())
.pattern(Pattern.compile(
String.format("\\(\\[!\\[%s]\\(http.*%s.*\\)",
badgeSetting.getBadge(),
badgeSetting.getCodePrefix().replace(".", "\\."))))
.build())
.collect(Collectors.toList())
)
.build();
} catch (IOException e) {
log.error("Error", e);
}
return null;
})
.collect(Collectors.toList());
}
}
7 changes: 5 additions & 2 deletions markdowner-core/src/main/resources/jeorg.badges.build.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
[
{
"title": "Travis",
"badge": "Build Status",
"codePrefix": "travis-ci.org"
"codePrefix": "travis-ci.com"
},
{
"badge": "Build Status",
"title": "App Surveyor",
"badge": "Build status",
"codePrefix": "ci.appveyor.com"
},
{
"title": "Circle CI",
"badge": "CircleCI",
"codePrefix": "circleci.com"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.jesperancinha.parser.markdowner.badges.parser;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class BadgeParserTest {

@Test
public void testBadgeParser() {
final var badgeGroups =
BadgeParser.parse(getClass().getResourceAsStream("/badges/Readme.md"));
}

@Test
public void testBadgeSettingsParserr() {
final var badgeSettingGroups =
BadgeParser.parseSettings();

assertThat(badgeSettingGroups).hasSize(5);
}
}
81 changes: 81 additions & 0 deletions markdowner-core/src/test/resources/badges/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# markdowner

[![Generic badge](https://img.shields.io/static/v1.svg?label=GitHub&message=Markdowner%20Core&color=informational)](https://github.com/jesperancinha/markdowner/tree/master/markdowner-core)
[![Maven Central](https://img.shields.io/maven-central/v/org.jesperancinha.parser/markdowner-core)](https://search.maven.org/search?q=parser.markdowner-core)

[![CircleCI](https://circleci.com/gh/jesperancinha/markdowner.svg?style=svg)](https://circleci.com/gh/jesperancinha/markdowner)
[![Build Status](https://travis-ci.org/jesperancinha/markdowner.svg?branch=master)](https://travis-ci.org/jesperancinha/markdowner)
[![Build status](https://ci.appveyor.com/api/projects/status/kuedmakr9bbne46q/branch/master?svg=true)](https://ci.appveyor.com/project/jesperancinha/markdowner/branch/master)

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/c423c85288eb45c883e2f721bb611a3f)](https://www.codacy.com/manual/jofisaes/markdowner?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=jesperancinha/markdowner&amp;utm_campaign=Badge_Grade)
[![codebeat badge](https://codebeat.co/badges/b6f714fa-6632-473e-9eb5-c481c776d415)](https://codebeat.co/projects/github-com-jesperancinha-markdowner-master)
[![BCH compliance](https://bettercodehub.com/edge/badge/jesperancinha/markdowner?branch=master)](https://bettercodehub.com/)

[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/c423c85288eb45c883e2f721bb611a3f)](https://www.codacy.com/gh/jesperancinha/markdowner/dashboard?utm_source=github.com&utm_medium=referral&utm_content=jesperancinha/markdowner&utm_campaign=Badge_Coverage)
[![codecov](https://codecov.io/gh/jesperancinha/markdowner/branch/master/graph/badge.svg?token=BREGsxyj5M)](https://codecov.io/gh/jesperancinha/markdowner)
[![Coverage Status](https://coveralls.io/repos/github/jesperancinha/markdowner/badge.svg?branch=master)](https://coveralls.io/github/jesperancinha/markdowner?branch=master)

[![GitHub language count](https://img.shields.io/github/languages/count/jesperancinha/markdowner.svg)]()
[![GitHub top language](https://img.shields.io/github/languages/top/jesperancinha/markdowner.svg)]()
[![GitHub top language](https://img.shields.io/github/languages/code-size/jesperancinha/markdowner.svg)]()

---

## Maven

```xml
<dependency>
<groupId>org.jesperancinha.parser</groupId>
<artifactId>markdowner-core</artifactId>
<version>2.0.2-SNAPSHOT</version>
</dependency>
```

## About me 👨🏽‍💻🚀🏳️‍🌈

[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/JEOrgLogo-20.png "João Esperancinha Homepage")](http://joaofilipesabinoesperancinha.nl)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/medium-20.png "Medium")](https://medium.com/@jofisaes)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/credly-20.png "Credly")](https://www.credly.com/users/joao-esperancinha)
[![Generic badge](https://img.shields.io/static/v1.svg?label=Homepage&message=joaofilipesabinoesperancinha.nl&color=6495ED "João Esperancinha Homepage")](https://joaofilipesabinoesperancinha.nl/)
[![GitHub followers](https://img.shields.io/github/followers/jesperancinha.svg?label=jesperancinha&style=social "GitHub")](https://github.com/jesperancinha)
[![Twitter Follow](https://img.shields.io/twitter/follow/joaofse?label=João%20Esperancinha&style=social "Twitter")](https://twitter.com/joaofse)
[![Generic badge](https://img.shields.io/static/v1.svg?label=GitHub&message=JEsperancinhaOrg&color=yellow "jesperancinha.org dependencies")](https://github.com/JEsperancinhaOrg)
[![Generic badge](https://img.shields.io/static/v1.svg?label=Articles&message=Across%20The%20Web&color=purple)](https://github.com/jesperancinha/project-signer/blob/master/project-signer-templates/Articles.md)
[![Generic badge](https://img.shields.io/static/v1.svg?label=Webapp&message=Image%20Train%20Filters&color=6495ED)](http://itf.joaofilipesabinoesperancinha.nl/)
[![Generic badge](https://img.shields.io/static/v1.svg?label=All%20Badges&message=Badges&color=red "All badges")](https://joaofilipesabinoesperancinha.nl/badges)
[![Generic badge](https://img.shields.io/static/v1.svg?label=Status&message=Project%20Status&color=red "Project statuses")](https://github.com/jesperancinha/project-signer/blob/master/project-signer-templates/Status.md)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/coursera-20.png "Coursera")](https://www.coursera.org/user/da3ff90299fa9297e283ee8e65364ffb)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/google-apps-20.png "Google Apps")](https://play.google.com/store/apps/developer?id=Joao+Filipe+Sabino+Esperancinha)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/sonatype-20.png "Sonatype Search Repos")](https://search.maven.org/search?q=org.jesperancinha)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/docker-20.png "Docker Images")](https://hub.docker.com/u/jesperancinha)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/stack-overflow-20.png)](https://stackoverflow.com/users/3702839/joao-esperancinha)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/reddit-20.png "Reddit")](https://www.reddit.com/user/jesperancinha/)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/devto-20.png "Dev To")](https://dev.to/jofisaes)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/hackernoon-20.jpeg "Hackernoon")](https://hackernoon.com/@jesperancinha)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/codeproject-20.png "Code Project")](https://www.codeproject.com/Members/jesperancinha)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/github-20.png "GitHub")](https://github.com/jesperancinha)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/bitbucket-20.png "BitBucket")](https://bitbucket.org/jesperancinha)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/gitlab-20.png "GitLab")](https://gitlab.com/jesperancinha)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/bintray-20.png "BinTray")](https://bintray.com/jesperancinha)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/free-code-camp-20.jpg "FreeCodeCamp")](https://www.freecodecamp.org/jofisaes)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/hackerrank-20.png "HackerRank")](https://www.hackerrank.com/jofisaes)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/codeforces-20.png "Code Forces")](https://codeforces.com/profile/jesperancinha)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/codebyte-20.png "Codebyte")](https://coderbyte.com/profile/jesperancinha)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/codewars-20.png "CodeWars")](https://www.codewars.com/users/jesperancinha)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/codepen-20.png "Code Pen")](https://codepen.io/jesperancinha)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/hacker-news-20.png "Hacker News")](https://news.ycombinator.com/user?id=jesperancinha)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/infoq-20.png "InfoQ")](https://www.infoq.com/profile/Joao-Esperancinha.2/)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/linkedin-20.png "LinkedIn")](https://www.linkedin.com/in/joaoesperancinha/)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/xing-20.png "Xing")](https://www.xing.com/profile/Joao_Esperancinha/cv)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/tumblr-20.png "Tumblr")](https://jofisaes.tumblr.com/)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/pinterest-20.png "Pinterest")](https://nl.pinterest.com/jesperancinha/)
[![alt text](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/icons-20/quora-20.png "Quora")](https://nl.quora.com/profile/Jo%C3%A3o-Esperancinha)

## Achievements

[![Oracle Certified Professional, JEE 7 Developer](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/badges/oracle-certified-professional-java-ee-7-application-developer-100.png "Oracle Certified Professional, JEE7 Developer")](https://www.credly.com/badges/27a14e06-f591-4105-91ca-8c3215ef39a2)
[![Oracle Certified Professional, Java SE 11 Programmer](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/badges/oracle-certified-professional-java-se-11-developer-100.png "Oracle Certified Professional, Java SE 11 Programmer")](https://www.credly.com/badges/87609d8e-27c5-45c9-9e42-60a5e9283280)
[![Oracle Certified Professional, Java SE 8 Programmer](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/badges/oracle-certified-professional-java-se-8-programmer-100.png "Oracle Certified Professional, Java SE 8 Programmer")](https://www.credly.com/badges/92e036f5-4e11-4cff-9935-3e62266d2074)
[![Oracle Certified Associate, Java SE 8 Programmer](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/badges/oracle-certified-associate-java-se-8-programmer-100.png "Oracle Certified Associate, Java SE 8 Programmer")](https://www.credly.com/badges/a206436d-6fd8-4ca1-8feb-38a838446ee7)
[![Oracle Certified Associate, Java SE 7 Programmer](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/badges/oracle-certified-associate-java-se-7-programmer-100.png "Oracle Certified Associate, Java SE 7 Programmer")](https://www.credly.com/badges/f4c6cc1e-cb52-432b-904d-36d266112225)
[![Oracle Certified Junior Associate](https://raw.githubusercontent.com/jesperancinha/project-signer/master/project-signer-templates/badges/oracle-certified-foundations-associate-java-100.png "Oracle Certified Foundations Associate")](https://www.credly.com/badges/6db92c1e-7bca-4856-9543-0d5ed0182794)
Loading

0 comments on commit 4c934e2

Please sign in to comment.