add support for gitlab changed files.
fixes gh-341
This commit is contained in:
@@ -17,7 +17,9 @@
|
||||
package org.springframework.cloud.config.monitor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
@@ -36,12 +38,28 @@ public class GitlabPropertyPathNotificationExtractor
|
||||
Map<String, Object> request) {
|
||||
if ("Push Hook".equals(headers.getFirst("X-Gitlab-Event"))) {
|
||||
if (request.get("commits") instanceof Collection) {
|
||||
// Gitlab doesn't tell us the files that changed so this is a broadcast to
|
||||
// all apps
|
||||
return new PropertyPathNotification("application.yml");
|
||||
Set<String> paths = new HashSet<>();
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Map<String, Object>> commits = (Collection<Map<String, Object>>) request
|
||||
.get("commits");
|
||||
for (Map<String, Object> commit : commits) {
|
||||
addAllPaths(paths, commit, "added");
|
||||
addAllPaths(paths, commit, "removed");
|
||||
addAllPaths(paths, commit, "modified");
|
||||
}
|
||||
if (!paths.isEmpty()) {
|
||||
return new PropertyPathNotification(paths.toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void addAllPaths(Set<String> paths, Map<String, Object> commit, String name) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<String> files = (Collection<String>) commit.get(name);
|
||||
if (files != null) {
|
||||
paths.addAll(files);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.config.monitor;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
@@ -30,6 +27,11 @@ import org.springframework.http.HttpHeaders;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -64,7 +66,8 @@ public class CompositePropertyPathNotificationExtractorTests {
|
||||
this.headers.set("X-Gitlab-Event", "Push Hook");
|
||||
PropertyPathNotification extracted = this.extractor.extract(this.headers, value);
|
||||
assertNotNull(extracted);
|
||||
assertEquals("application.yml", extracted.getPaths()[0]);
|
||||
String[] paths = extracted.getPaths();
|
||||
assertThat("paths was wrong", paths, arrayContainingInAnyOrder("oldapp.yml", "newapp.properties", "application.yml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.config.monitor;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -29,6 +25,10 @@ import org.springframework.http.HttpHeaders;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -63,15 +63,4 @@ public class GithubPropertyPathNotificationExtractorTests {
|
||||
assertNull(extracted);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gitlabNotDetected() throws Exception {
|
||||
Map<String, Object> value = new ObjectMapper().readValue(
|
||||
new ClassPathResource("gitlab.json").getInputStream(),
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
this.headers.set("X-Github-Event", "push");
|
||||
PropertyPathNotification extracted = this.extractor.extract(this.headers, value);
|
||||
assertNull(extracted);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.config.monitor;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -29,6 +25,11 @@ import org.springframework.http.HttpHeaders;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -49,7 +50,8 @@ public class GitlabPropertyPathNotificationExtractorTests {
|
||||
this.headers.set("X-Gitlab-Event", "Push Hook");
|
||||
PropertyPathNotification extracted = this.extractor.extract(this.headers, value);
|
||||
assertNotNull(extracted);
|
||||
assertEquals("application.yml", extracted.getPaths()[0]);
|
||||
String[] paths = extracted.getPaths();
|
||||
assertThat("paths was wrong", paths, arrayContainingInAnyOrder("oldapp.yml", "newapp.properties", "application.yml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -6,12 +6,29 @@
|
||||
"user_id": 4,
|
||||
"user_name": "John Smith",
|
||||
"user_email": "john@example.com",
|
||||
"user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80",
|
||||
"project_id": 15,
|
||||
"repository": {
|
||||
"project":{
|
||||
"name":"Diaspora",
|
||||
"description":"",
|
||||
"web_url":"http://example.com/mike/diaspora",
|
||||
"avatar_url":null,
|
||||
"git_ssh_url":"git@example.com:mike/diaspora.git",
|
||||
"git_http_url":"http://example.com/mike/diaspora.git",
|
||||
"namespace":"Mike",
|
||||
"visibility_level":0,
|
||||
"path_with_namespace":"mike/diaspora",
|
||||
"default_branch":"master",
|
||||
"homepage":"http://example.com/mike/diaspora",
|
||||
"url":"git@example.com:mike/diasporadiaspora.git",
|
||||
"ssh_url":"git@example.com:mike/diaspora.git",
|
||||
"http_url":"http://example.com/mike/diaspora.git"
|
||||
},
|
||||
"repository":{
|
||||
"name": "Diaspora",
|
||||
"url": "git@example.com:mike/diasporadiaspora.git",
|
||||
"description": "",
|
||||
"homepage": "http://example.com/mike/diaspora",
|
||||
"homepage": "http://example.com/mike/diaspora",
|
||||
"git_http_url":"http://example.com/mike/diaspora.git",
|
||||
"git_ssh_url":"git@example.com:mike/diaspora.git",
|
||||
"visibility_level":0
|
||||
@@ -25,7 +42,10 @@
|
||||
"author": {
|
||||
"name": "Jordi Mallach",
|
||||
"email": "jordi@softcatala.org"
|
||||
}
|
||||
},
|
||||
"added": ["newapp.properties"],
|
||||
"modified": ["application.yml"],
|
||||
"removed": []
|
||||
},
|
||||
{
|
||||
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
|
||||
@@ -35,7 +55,10 @@
|
||||
"author": {
|
||||
"name": "GitLab dev user",
|
||||
"email": "gitlabdev@dv6700.(none)"
|
||||
}
|
||||
},
|
||||
"added": [],
|
||||
"modified": ["oldapp.yml"],
|
||||
"removed": []
|
||||
}
|
||||
],
|
||||
"total_commits_count": 4
|
||||
|
||||
Reference in New Issue
Block a user