Skip to content

Commit

Permalink
chore: revapi configuration and helper scripts to detect API breaking…
Browse files Browse the repository at this point in the history
… changes. (#1115)

They are run by Inria server spoon3r, triggered by a Github webhook.

Close #1156 #1023
  • Loading branch information
surli authored and monperrus committed Jan 31, 2017
1 parent 23ba99d commit 8195e3c
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -11,7 +11,7 @@ jdk:
install:
- # download deps with maven
- mvn dependency:resolve
- pip install --user CommonMark requests
- pip install --user CommonMark requests pygithub
- sudo apt-get install xmlstarlet

script: |
Expand Down
24 changes: 24 additions & 0 deletions chore/revapi_tpl.ftl
@@ -0,0 +1,24 @@
# Revapi Analysis results

Old API: **<#list analysis.oldApi.archives as archive>${archive.name}<#sep>, </#list>**

New API: **<#list analysis.newApi.archives as archive>${archive.name}<#sep>, </#list>**

Detected changes: ${reports?size}.

<#list reports as report>
<#list report.differences as diff>
## Change ${report?index+1}

| Name | Element |
| :---: | :---: |
| Old | ${report.oldElement!"none"} |
| New | ${report.newElement!"none"} |
| Code | ${diff.code} |
| Description | ${diff.description!"none"} |
| Breaking | <#list diff.classification?keys as compat>${compat?lower_case}: ${diff.classification?api.get(compat)?lower_case}<#sep>, </#list> |
</#list>
<#sep>

</#sep>
</#list>
69 changes: 69 additions & 0 deletions chore/revapy.py
@@ -0,0 +1,69 @@
#!/usr/bin/python
# Retrieve revapi report from target and publish it as PR comment
# This script intends to be launched by a webhooks and take as parameter the hook payload
# see: https://developer.github.com/v3/activity/events/types/#pullrequestevent

import os, sys, json
from github import *

revapi_file = "./target/revapi_report.md"

args = sys.argv

def usage():
print "Usage: "+str(args[0])+ " <github_login> <github_token> <PR_payload_path>"
exit(1)

if (args.__len__() < 4):
print "Error in the args number"
usage()

if (not(os.path.isfile(revapi_file))):
print "Revapi report file cannot be found at the following location: "+revapi_file
exit(1)

if (not(os.path.isfile(args[3]))):
print "JSON payload file cannot be found at the following location: "+args[3]
exit(1)

file_content = ""
with open(revapi_file) as f:
for line in f:
file_content += line

if (file_content == ""):
print "Revapi report is empty"
exit(1)

login = args[1]
token = args[2]

try:
gh = Github(login,token)
except GithubException as e:
print "Error while connecting to github, are you sure about your credentials?"
print e
exit(1)

payload_string = ""
with open(args[3]) as f:
for line in f:
payload_string += line

if (payload_string == ""):
print "Payload is empty"
exit(1)

payloadJSON = json.loads(payload_string)
repo_name = payloadJSON['repository']['full_name']
pr_id = payloadJSON['pull_request']['number']

try:
repo = gh.get_repo(repo_name,True)

pr = repo.get_pull(pr_id)
pr.create_issue_comment(file_content)
except GithubException as e:
print "Error while creating the PR comment."
print e
exit(1)
32 changes: 32 additions & 0 deletions pom.xml
Expand Up @@ -177,6 +177,11 @@
<name>Maven Repository for JDT Compiler release</name>
<url>http://spoon.gforge.inria.fr/repositories/releases</url>
</repository>
<repository>
<id>gforge.inria.fr-snapshot</id>
<name>Maven Repository for Spoon Snapshots</name>
<url>http://spoon.gforge.inria.fr/repositories/snapshots</url>
</repository>
</repositories>

<distributionManagement>
Expand Down Expand Up @@ -482,8 +487,35 @@
</executions>
</plugin>

<!-- Used for checking backward compatibility (binary and source) -->
<plugin>
<groupId>org.revapi</groupId>
<artifactId>revapi-maven-plugin</artifactId>
<!-- Lock down plugin version for build reproducibility -->
<version>0.8.1</version>
<dependencies>
<dependency>
<groupId>org.revapi</groupId>
<artifactId>revapi-java</artifactId>
<version>0.13.1</version>
</dependency>
<dependency>
<groupId>org.revapi</groupId>
<artifactId>revapi-reporter-text</artifactId>
<version>0.7.0</version>
</dependency>
</dependencies>
<configuration>
<alwaysCheckForReleaseVersion>false</alwaysCheckForReleaseVersion>
<oldVersion>LATEST</oldVersion>
<analysisConfigurationFiles>
<file>${project.basedir}/revapi.json</file>
</analysisConfigurationFiles>
</configuration>
</plugin>
</plugins>


<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
Expand Down
36 changes: 36 additions & 0 deletions revapi.json
@@ -0,0 +1,36 @@
{
"revapi": {
// use java module
// Doc there: http://revapi.org/modules/revapi-java/extensions/java.html
"java": {

// filter rules to compare API
"filter": {

// specify which package to filter
"packages": {
"regex": true,
"include": ["spoon\\..*"],
"exclude": ["spoon\\..*\\.test(\\..*)?"]
},

// Exclude all impl classes
"classes": {
"regex": true,
"exclude": [".*Impl.*"]
}

},
"reportUsesFor": ["java.missing.newClass", "java.missing.oldClass"]
},

"reporter" : {
"text" : {
"minSeverity": "BREAKING",
"output" : "target/revapi_report.md",
"template": "chore/revapi_tpl.ftl",
"append": false
}
}
}
}
Expand Up @@ -67,7 +67,7 @@
import static spoon.support.compiler.jdt.JDTTreeBuilderQuery.getModifiers;
import static spoon.support.compiler.jdt.JDTTreeBuilderQuery.isLhsAssignment;

class JDTTreeBuilderHelper {
public class JDTTreeBuilderHelper {
private final JDTTreeBuilder jdtTreeBuilder;

JDTTreeBuilderHelper(JDTTreeBuilder jdtTreeBuilder) {
Expand Down

0 comments on commit 8195e3c

Please sign in to comment.