File tree Expand file tree Collapse file tree
main/java/com/baeldung/git
test/java/com/baeldung/git Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ [submodule "testgitrepo "]
2+ path = testgitrepo
3+ url = /home/prd/Development/projects/idea/tutorials/spring-boot/src/main/resources/testgitrepo/
Original file line number Diff line number Diff line change 112112 <artifactId >maven-war-plugin</artifactId >
113113 </plugin >
114114
115- </plugins >
115+ <plugin >
116+ <groupId >pl.project13.maven</groupId >
117+ <artifactId >git-commit-id-plugin</artifactId >
118+ <version >2.2.1</version >
119+ <executions >
120+ <execution >
121+ <id >get-the-git-infos</id >
122+ <goals >
123+ <goal >revision</goal >
124+ </goals >
125+ </execution >
126+ </executions >
127+ <configuration >
128+ <verbose >true</verbose >
129+ </configuration >
130+ </plugin >
131+
132+ </plugins >
116133
117134 </build >
118135
Original file line number Diff line number Diff line change 1+ package com .baeldung .git ;
2+
3+ import org .springframework .boot .SpringApplication ;
4+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5+ import org .springframework .context .annotation .PropertySource ;
6+
7+ @ PropertySource ("classpath:/git.properties" )
8+ @ SpringBootApplication (scanBasePackages = { "com.baeldung.git" })
9+ public class CommitIdApplication {
10+ public static void main (String [] args ) {
11+ SpringApplication .run (CommitIdApplication .class , args );
12+ }
13+ }
14+
Original file line number Diff line number Diff line change 1+ package com .baeldung .git ;
2+
3+ import org .springframework .beans .factory .annotation .Value ;
4+ import org .springframework .web .bind .annotation .RequestMapping ;
5+ import org .springframework .web .bind .annotation .RestController ;
6+
7+ @ RestController
8+ public class CommitInfoController {
9+ @ Value ("${git.commit.message.short}" )
10+ private String commitMessage ;
11+
12+ @ Value ("${git.branch}" )
13+ private String branch ;
14+
15+ @ Value ("${git.commit.id}" )
16+ private String commitId ;
17+
18+ @ RequestMapping ("/commitId" )
19+ public GitInfoDto getCommitId () {
20+ return new GitInfoDto (commitMessage , branch , commitId );
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .git ;
2+
3+ public class GitInfoDto {
4+ private String commitMessage ;
5+ private String branch ;
6+ private String commitId ;
7+
8+ public GitInfoDto (String commitMessage , String branch , String commitId ) {
9+ this .commitMessage = commitMessage ;
10+ this .branch = branch ;
11+ this .commitId = commitId ;
12+ }
13+
14+ public String getCommitMessage () {
15+ return commitMessage ;
16+ }
17+
18+ public String getBranch () {
19+ return branch ;
20+ }
21+
22+ public String getCommitId () {
23+ return commitId ;
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .git ;
2+
3+ import org .junit .Test ;
4+ import org .junit .runner .RunWith ;
5+ import org .springframework .beans .factory .annotation .Value ;
6+ import org .springframework .test .context .ContextConfiguration ;
7+ import org .springframework .test .context .junit4 .SpringRunner ;
8+
9+ import static org .assertj .core .api .Assertions .assertThat ;
10+ @ RunWith (SpringRunner .class )
11+ @ ContextConfiguration (classes = CommitIdApplication .class )
12+ public class CommitIdTest {
13+
14+ @ Value ("${git.commit.message.short}" )
15+ private String commitMessage ;
16+
17+ @ Value ("${git.branch}" )
18+ private String branch ;
19+
20+ @ Value ("${git.commit.id}" )
21+ private String commitId ;
22+
23+ @ Test
24+ public void shouldInjectGitInfoProperties () throws Exception {
25+ assertThat (commitMessage ).isNotNull ();
26+ assertThat (commitMessage ).isNotEqualTo ("${git.commit.message.short}" );
27+ assertThat (branch ).isNotNull ();
28+ assertThat (branch ).isNotEqualTo ("${git.branch}" );
29+ assertThat (commitId ).isNotNull ();
30+ assertThat (commitId ).isNotEqualTo ("${git.commit.id}" );
31+ }
32+ }
Submodule testgitrepo added at b3e635b
You can’t perform that action at this time.
0 commit comments