mirror of
https://gitee.com/log4j/pig.git
synced 2024-12-23 05:00:23 +08:00
✨ Introducing new features. 基于git-commit-id-maven-plugin暴露git仓库状态端点
This commit is contained in:
parent
85b41b87c7
commit
0a3bf68b9d
@ -0,0 +1,74 @@
|
|||||||
|
package com.pig4cloud.pig.common.core.git;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* git仓库状态
|
||||||
|
*
|
||||||
|
* @author lishangbu
|
||||||
|
* @date 2021/10/10
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class GitRepositoryState implements Serializable {
|
||||||
|
private String tags;
|
||||||
|
private String branch;
|
||||||
|
private String dirty;
|
||||||
|
private String remoteOriginUrl;
|
||||||
|
|
||||||
|
private String commitId;
|
||||||
|
private String commitIdAbbrev;
|
||||||
|
private String describe;
|
||||||
|
private String describeShort;
|
||||||
|
private String commitUserName;
|
||||||
|
private String commitUserEmail;
|
||||||
|
private String commitMessageFull;
|
||||||
|
private String commitMessageShort;
|
||||||
|
private String commitTime;
|
||||||
|
private String closestTagName;
|
||||||
|
private String closestTagCommitCount;
|
||||||
|
|
||||||
|
private String buildUserName;
|
||||||
|
private String buildUserEmail;
|
||||||
|
private String buildTime;
|
||||||
|
private String buildHost;
|
||||||
|
private String buildVersion;
|
||||||
|
private String buildNumber;
|
||||||
|
private String buildNumberUnique;
|
||||||
|
|
||||||
|
private String totalCommitCount;
|
||||||
|
|
||||||
|
public GitRepositoryState() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public GitRepositoryState(Properties properties) {
|
||||||
|
this.tags = properties.getProperty("git.tags", "");
|
||||||
|
this.branch = properties.getProperty("git.branch", "");
|
||||||
|
this.dirty = properties.getProperty("git.dirty", "");
|
||||||
|
this.remoteOriginUrl = properties.getProperty("git.remote.origin.url", "");
|
||||||
|
this.commitId = properties.getProperty("git.commit.id.full", "");
|
||||||
|
this.commitIdAbbrev = properties.getProperty("git.commit.id.abbrev", "");
|
||||||
|
this.describe = properties.getProperty("git.commit.id.describe", "");
|
||||||
|
this.describeShort = properties.getProperty("git.commit.id.describe-short", "");
|
||||||
|
this.commitUserName = properties.getProperty("git.commit.user.name", "");
|
||||||
|
this.commitUserEmail = properties.getProperty("git.commit.user.email", "");
|
||||||
|
this.commitMessageFull = properties.getProperty("git.commit.message.full", "");
|
||||||
|
this.commitMessageShort = properties.getProperty("git.commit.message.short", "");
|
||||||
|
this.commitTime = properties.getProperty("git.commit.time", "");
|
||||||
|
this.closestTagName = properties.getProperty("git.closest.tag.name", "");
|
||||||
|
this.closestTagCommitCount = properties.getProperty("git.closest.tag.commit.count", "");
|
||||||
|
|
||||||
|
this.buildUserName = properties.getProperty("git.build.user.name", "");
|
||||||
|
this.buildUserEmail = properties.getProperty("git.build.user.email", "");
|
||||||
|
this.buildTime = properties.getProperty("git.build.time", "");
|
||||||
|
this.buildHost = properties.getProperty("git.build.host", "");
|
||||||
|
this.buildVersion = properties.getProperty("git.build.version", "");
|
||||||
|
this.buildNumber = properties.getProperty("git.build.number", "");
|
||||||
|
this.buildNumberUnique = properties.getProperty("git.build.number.unique", "");
|
||||||
|
|
||||||
|
this.totalCommitCount = properties.getProperty("git.total.commit.count", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.pig4cloud.pig.common.core.git;
|
||||||
|
|
||||||
|
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||||
|
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 版本号端点
|
||||||
|
*
|
||||||
|
* @author lishangbu
|
||||||
|
* @date 2021/10/10
|
||||||
|
*/
|
||||||
|
@Endpoint(id = "gitrepositorystate")
|
||||||
|
public class GitRepositoryStateEndpoint {
|
||||||
|
|
||||||
|
private GitRepositoryState gitRepositoryState;
|
||||||
|
|
||||||
|
@ReadOperation
|
||||||
|
public GitRepositoryState getGitRepositoryState() throws IOException {
|
||||||
|
if (gitRepositoryState == null) {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.load(getClass().getClassLoader().getResourceAsStream("git.properties"));
|
||||||
|
gitRepositoryState = new GitRepositoryState(properties);
|
||||||
|
}
|
||||||
|
return gitRepositoryState;
|
||||||
|
}
|
||||||
|
}
|
@ -2,5 +2,6 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
|||||||
com.pig4cloud.pig.common.core.config.JacksonConfiguration,\
|
com.pig4cloud.pig.common.core.config.JacksonConfiguration,\
|
||||||
com.pig4cloud.pig.common.core.config.RedisTemplateConfiguration,\
|
com.pig4cloud.pig.common.core.config.RedisTemplateConfiguration,\
|
||||||
com.pig4cloud.pig.common.core.config.RestTemplateConfiguration,\
|
com.pig4cloud.pig.common.core.config.RestTemplateConfiguration,\
|
||||||
|
com.pig4cloud.pig.common.core.git.GitRepositoryStateEndpoint,\
|
||||||
com.pig4cloud.pig.common.core.util.SpringContextHolder,\
|
com.pig4cloud.pig.common.core.util.SpringContextHolder,\
|
||||||
com.pig4cloud.pig.common.core.config.WebMvcConfiguration
|
com.pig4cloud.pig.common.core.config.WebMvcConfiguration
|
||||||
|
5
pom.xml
5
pom.xml
@ -218,6 +218,11 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<failOnNoGitDirectory>false</failOnNoGitDirectory>
|
<failOnNoGitDirectory>false</failOnNoGitDirectory>
|
||||||
<generateGitPropertiesFile>true</generateGitPropertiesFile>
|
<generateGitPropertiesFile>true</generateGitPropertiesFile>
|
||||||
|
<dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat>
|
||||||
|
<includeOnlyProperties>
|
||||||
|
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
|
||||||
|
<includeOnlyProperty>^git.commit.(id|message|time).*$</includeOnlyProperty>
|
||||||
|
</includeOnlyProperties>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!--代码格式插件,默认使用spring 规则-->
|
<!--代码格式插件,默认使用spring 规则-->
|
||||||
|
Loading…
Reference in New Issue
Block a user