Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove JGIT from source code #600

Merged
merged 2 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package org.jfrog.build.extractor.clientConfiguration.util;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.jfrog.build.api.util.Log;
import org.jfrog.build.extractor.ci.Vcs;
import org.jfrog.build.extractor.executor.CommandExecutor;
import org.jfrog.build.extractor.executor.CommandResults;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static org.jfrog.build.api.IssuesCollectionConfig.ISSUES_COLLECTION_ERROR_PREFIX;

public class GitUtils {
private static final String GIT_LOG_LIMIT = "100";

private static File getDotGit(File file) {
if (file == null) {
Expand Down Expand Up @@ -191,21 +193,18 @@ private static String extractVcsBranch(File dotGit, Log log) throws IOException
return "";
}

private static String extractVcsMessage(File dotGit, Log log) throws IOException {
FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder();
Repository repository = repositoryBuilder.setGitDir(dotGit)
.readEnvironment()
.findGitDir()
.build();
RevCommit latestCommit;
private static String extractVcsMessage(File dotGit, Log log) {
String warnMessage = "Failed fetching commit message from git directory: " + dotGit + "\nWith the following error: ";
try {
latestCommit = new Git(repository).log().setMaxCount(1).call().iterator().next();
} catch (GitAPIException e) {
log.warn("Failed fetching commit message from git directory: " + dotGit + "\nWith the following error: " + e.getMessage());
return "";
CommandResults res = getGitLog(dotGit, log, 1);
if (res.isOk()) {
return res.getRes().trim();
}
log.warn(warnMessage + res.getErr());
} catch (InterruptedException | IOException e) {
log.warn(warnMessage + e.getMessage());
}

return latestCommit.getFullMessage().trim();
return "";
}

/**
Expand All @@ -215,4 +214,24 @@ private static class RevisionOrRef {
private String revision;
private String ref;
}

public static CommandResults getGitLog(File execDir, Log logger, String previousVcsRevision) throws InterruptedException, IOException {
return getGitLog(execDir, logger, previousVcsRevision, 0);
}

public static CommandResults getGitLog(File execDir, Log logger, int limit) throws InterruptedException, IOException {
return getGitLog(execDir, logger, "", limit);
}

public static CommandResults getGitLog(File execDir, Log logger, String previousVcsRevision, int limit) throws InterruptedException, IOException {
List<String> args = new ArrayList<>();
args.add("log");
args.add("--pretty=format:%s");
args.add("-" + (limit == 0 ? GIT_LOG_LIMIT : limit));
if (!previousVcsRevision.isEmpty()) {
args.add(previousVcsRevision + "..");
}
CommandExecutor commandExecutor = new CommandExecutor("git", null);
return commandExecutor.exeCommand(execDir, args, null, logger);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.jfrog.build.api.util.Log;
import org.jfrog.build.extractor.clientConfiguration.ArtifactoryManagerBuilder;
import org.jfrog.build.extractor.clientConfiguration.client.artifactory.ArtifactoryManager;
import org.jfrog.build.extractor.executor.CommandExecutor;
import org.jfrog.build.extractor.clientConfiguration.util.GitUtils;
import org.jfrog.build.extractor.executor.CommandResults;

import java.io.File;
Expand All @@ -35,7 +35,6 @@ public class IssuesCollector implements Serializable {
private static final long serialVersionUID = 1L;

private static final String LATEST = "LATEST";
private static final String GIT_LOG_LIMIT = "100";

public static Pattern REVISION_NOT_EXIST;

Expand Down Expand Up @@ -145,15 +144,7 @@ private Issue getMatchingIssue(int keyIndex, int summaryIndex, Matcher matcher,
}

private String getGitLog(File execDir, Log logger, String previousVcsRevision) throws InterruptedException, IOException {
List<String> args = new ArrayList<>();
args.add("log");
args.add("--pretty=format:%s");
args.add("-" + GIT_LOG_LIMIT);
if (!previousVcsRevision.isEmpty()) {
args.add(previousVcsRevision + "..");
}
CommandExecutor commandExecutor = new CommandExecutor("git", null);
CommandResults res = commandExecutor.exeCommand(execDir, args, null, logger);
CommandResults res = GitUtils.getGitLog(execDir, logger, previousVcsRevision);
if (!res.isOk()) {
if (getRevisionNotExistPattern().matcher(res.getErr()).find()) {
logger.info("Revision: " + previousVcsRevision + " that was fetched from latest build info does not exist in the git revision range. No new issues are added.");
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ project('build-info-extractor') {
apply plugin: 'java-test-fixtures'
description = 'JFrog Build-Info Extractor'
dependencies {
implementation 'org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r'
implementation project(':build-info-client')
implementation project(':build-info-api')

Expand Down