Skip to content

Commit

Permalink
Merge pull request #156 from Lixuhuilll/git-properties
Browse files Browse the repository at this point in the history
feat: 接口返回值返回编译时对应的 commit 的 abbreviatedId 以及 dateTime
  • Loading branch information
dragove authored Dec 25, 2023
2 parents 0981269 + 93b5529 commit 429d418
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 42 deletions.
21 changes: 4 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.apache.tools.ant.filters.ReplaceTokens

plugins {
id 'java'
id 'org.springframework.boot' version '3.1.5'
Expand All @@ -8,7 +6,7 @@ plugins {
id 'org.springdoc.openapi-gradle-plugin' version '1.8.0'
id 'org.hidetake.swagger.generator' version '2.19.2'
// id 'org.graalvm.buildtools.native' version '0.9.28'
id 'org.ajoberstar.grgit' version '5.2.1'
id 'com.gorylenko.gradle-git-properties' version '2.4.1'
}

group 'plus.maa'
Expand Down Expand Up @@ -131,18 +129,7 @@ rootProject.afterEvaluate(){
}
}

// 配置资源文件拷贝任务
processResources {
// 获取当前 commit
def commit = grgit?.head()
// 替换配置文件中的占位符
filesMatching(['**/*.properties', '**/*.yml', '**/*.yaml']) { file ->
{
file.filter(ReplaceTokens, tokens: [
// commit 不存在时,填充空字符串
'commitAbbreviatedId': commit?.abbreviatedId ?: '',
'commitDateTime' : commit?.dateTime?.toString() ?: ''
])
}
}
gitProperties {
failOnNoGitDirectory = false
keys = ["git.branch", "git.commit.id", "git.commit.id.abbrev", "git.commit.time"]
}
11 changes: 0 additions & 11 deletions src/main/java/plus/maa/backend/config/external/Commit.java

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/java/plus/maa/backend/config/external/Info.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package plus.maa.backend.config.external;

import org.springframework.boot.context.properties.NestedConfigurationProperty;

@lombok.Data
public class Info {
private String title;
private String description;
private String version;
private String domain;
private String frontendDomain;
@NestedConfigurationProperty
private Commit commit;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.info.GitProperties;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -20,7 +22,10 @@
@RestController
@RequiredArgsConstructor
public class SystemController {

private final MaaCopilotProperties properties;
@Nullable // 非必须字段,当 Git 仓库不存在时为 null
private final GitProperties gitProperties;

@GetMapping("/")
@Operation(summary = "Tests if the server is ready.")
Expand All @@ -38,7 +43,7 @@ public MaaResult<MaaSystemInfo> getSystemVersion() {
systemInfo.setTitle(info.getTitle());
systemInfo.setDescription(info.getDescription());
systemInfo.setVersion(info.getVersion());
systemInfo.setCommit(info.getCommit());
systemInfo.setGit(gitProperties);
return MaaResult.success(systemInfo);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package plus.maa.backend.controller.response;

import lombok.Data;
import plus.maa.backend.config.external.Commit;
import org.springframework.boot.info.GitProperties;

/**
* @author AnselYuki
Expand All @@ -11,5 +11,5 @@ public class MaaSystemInfo {
private String title;
private String description;
private String version;
private Commit commit;
private GitProperties git;
}
7 changes: 0 additions & 7 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,3 @@ logging:
rollingpolicy:
max-history: 14
clean-history-on-start: true

maa-copilot:
info:
# 这几个参数应在编译时生成,不宜修改
commit:
abbreviated-id: @commitAbbreviatedId@
date-time: @commitDateTime@

0 comments on commit 429d418

Please sign in to comment.