Skip to content

Commit

Permalink
Fix/build info (#579)
Browse files Browse the repository at this point in the history
* fix build info when git in commit

* fix build info

* change version to 2.0.7-SNAPSHOT

Co-authored-by: yuanyuan <[email protected]>
Co-authored-by: leo james <[email protected]>
  • Loading branch information
3 people committed Oct 13, 2022
1 parent 718629f commit 8c31e4d
Show file tree
Hide file tree
Showing 24 changed files with 54 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-ark</artifactId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-ark</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-parent/assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>sofa-ark-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
</parent>

<artifactId>sofa-ark-all</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-parent/core-impl/archive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>sofa-ark-core-impl</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
</parent>

<artifactId>sofa-ark-archive</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-parent/core-impl/container/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>sofa-ark-core-impl</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
</parent>

<artifactId>sofa-ark-container</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-parent/core-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>sofa-ark-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
</parent>

<artifactId>sofa-ark-core-impl</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-parent/core/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-ark-core</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-parent/core/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>sofa-ark-core</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
</parent>

<artifactId>sofa-ark-common</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-parent/core/exception/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>sofa-ark-core</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
</parent>

<artifactId>sofa-ark-exception</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-parent/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>sofa-ark-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
</parent>

<artifactId>sofa-ark-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-parent/core/spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>sofa-ark-core</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
</parent>

<artifactId>sofa-ark-spi</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-ark-bom</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
<relativePath>../sofa-ark-bom</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-parent/support/ark-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-ark-support</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>maven-plugin</packaging>
Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-parent/support/ark-plugin-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-ark-support</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-ark-support</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-ark-support</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-ark-support</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-ark-support</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-parent/support/ark-support-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-ark-support</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-parent/support/ark-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>sofa-ark-support</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
</parent>

<artifactId>sofa-ark-tools</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
*/
package com.alipay.sofa.ark.tools.git;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.ListBranchCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.lib.*;
import org.eclipse.jgit.revwalk.RevCommit;
Expand All @@ -26,8 +30,12 @@
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import static com.alipay.sofa.ark.spi.constant.Constants.DATE_FORMAT;
import static org.eclipse.jgit.lib.Constants.MASTER;

public class JGitParser {

Expand Down Expand Up @@ -59,6 +67,11 @@ public static GitInfo parse(File gitDirectory) {
gitInfo.setLastCommitEmail(lastCommitEmail);
gitInfo.setLastCommitTime(lastCommitTime);
gitInfo.setLastCommitDateTime(commitDateTime);

if (lastCommitId.equals(branchName)) {
gitInfo.setBranchName(StringUtils.join(
getBranchsFromCommit(repository, lastCommitId), ","));
}
}

return gitInfo;
Expand All @@ -67,6 +80,24 @@ public static GitInfo parse(File gitDirectory) {
}
}

private static List<String> getBranchsFromCommit(FileRepository repository, String lastCommitId) throws GitAPIException {
Git git = new Git(repository);
List<Ref> refs = Git.wrap(repository).branchList()
.setListMode(ListBranchCommand.ListMode.REMOTE)
.setContains(lastCommitId)
.call();
return refs.stream()
.filter(ref -> !ref.isSymbolic())
.map(Ref::getName)
.map(repository::shortenRemoteBranchName)
.filter(StringUtils::isNotBlank)
.distinct()
.sorted(MASTER_FIRST_COMPARATOR)
.collect(Collectors.toList());
}

public static final Comparator<String> MASTER_FIRST_COMPARATOR = (o1, o2) -> MASTER.equals(o1) ? -1 : 1;

private static RevCommit getLastCommit(Repository repository) throws Exception {
RevWalk revWalk = new RevWalk(repository);
Ref headCommitReference = repository.getRefDatabase().findRef("HEAD");
Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-parent/support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-ark-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-plugin/config-ark-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-ark-bom</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
<relativePath>../../sofa-ark-bom</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion sofa-ark-plugin/web-ark-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-ark-bom</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>2.0.6</version>
<version>2.0.7-SNAPSHOT</version>
<relativePath>../../sofa-ark-bom</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down

0 comments on commit 8c31e4d

Please sign in to comment.