Ensure full commit id is always available

Update `GitProperties` so that the `commit.id` entry is also copied to
`commit.id.full`.

Prior to this commit, when returning full details, the value of
`commit.id` would be replaced with a `Map` containing only `abbriv` as
a key. By  copying the value to a sub-key we ensure that it remains
available both in the FULL and SIMPLE modes.

Fixes gh-11892
pull/11886/head
Phillip Webb 7 years ago
parent 16b7dbf487
commit b5c4ce230d

@ -22,6 +22,7 @@ import java.util.Properties;
import org.junit.Test;
import org.springframework.boot.actuate.info.InfoPropertiesInfoContributor.Mode;
import org.springframework.boot.info.GitProperties;
import static org.assertj.core.api.Assertions.assertThat;
@ -63,4 +64,22 @@ public class GitInfoContributorTests {
assertThat(commit.get("id")).isEqualTo("8e29a0b");
}
@Test
@SuppressWarnings("unchecked")
public void withGitIdAndAbbrev() {
// gh-11892
Properties properties = new Properties();
properties.put("branch", "master");
properties.put("commit.id", "1b3cec34f7ca0a021244452f2cae07a80497a7c7");
properties.put("commit.id.abbrev", "1b3cec3");
GitInfoContributor contributor = new GitInfoContributor(
new GitProperties(properties), Mode.FULL);
Map<String, Object> content = contributor.generateContent();
Map<String, Object> commit = (Map<String, Object>) content.get("commit");
assertThat(commit.get("id")).isInstanceOf(Map.class);
Map<String, Object> id = (Map<String, Object>) commit.get("id");
assertThat(id.get("full")).isEqualTo("1b3cec34f7ca0a021244452f2cae07a80497a7c7");
assertThat(id.get("abbrev")).isEqualTo("1b3cec3");
}
}

@ -80,6 +80,11 @@ public class GitProperties extends InfoProperties {
private static Properties processEntries(Properties properties) {
coercePropertyToEpoch(properties, "commit.time");
coercePropertyToEpoch(properties, "build.time");
Object commitId = properties.get("commit.id");
if (commitId != null) {
// Can get converted into a map, so we copy the entry as a nested key
properties.put("commit.id.full", commitId);
}
return properties;
}

Loading…
Cancel
Save