Skip to content

Commit

Permalink
get git data
Browse files Browse the repository at this point in the history
  • Loading branch information
spacey-sooty committed Dec 7, 2023
1 parent 780d66e commit b28d3b5
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions src/main/java/edu/wpi/first/gradlerio/deploy/DeployData.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
import java.util.Map;

import org.gradle.api.GradleException;
import org.gradle.internal.impldep.software.amazon.ion.IonException;

import java.util.HashMap;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.io.File;
import java.io.FileWriter;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.lang.Runtime;

class DeployLogFile {
public String deployHost;
Expand All @@ -43,15 +41,47 @@ class DeployLogFile {
Map<String, String> data = new HashMap<String, String>();
String jsonDeploy;
FileArtifact deployArtifact;
boolean inGitRepo;

DeployLogFile(RoboRIO target) {
String[] command = {"git", "rev-parse", "--is-inside-work-tree"};

try {
Runtime.getRuntime().exec(command);
} catch(IOException e) {
inGitRepo = false;
}

data.put(deployItems[0], deployHost);
data.put(deployItems[1], deployUser);
data.put(deployItems[2], deployDate);
data.put(deployItems[3], codePath);
data.put(deployItems[4], gitHash);
data.put(deployItems[5], gitBranch);
data.put(deployItems[6], gitDesc);

if (inGitRepo) {
String[] command2 = {"git", "rev-parse", "HEAD"};
try {
gitHash = Runtime.getRuntime().exec(command2).getOutputStream().toString().strip();
data.put(deployItems[4], gitHash);
} catch (IOException e) {
throw new GradleException("Couldn't get git hash", e);
}

String[] command3 = {"git", "rev-parse", "--abbrev-ref" ,"HEAD"};
try {
gitBranch = Runtime.getRuntime().exec(command3).getOutputStream().toString().strip();
data.put(deployItems[5], gitBranch);
} catch (IOException e) {
throw new GradleException("Couldn't get git branch", e);
}

try {
String[] command4 = {"git", "describe", "--dirty=-dirty", "--always"};
gitDesc = Runtime.getRuntime().exec(command4).getOutputStream().toString().strip();
data.put(deployItems[6], gitDesc);
} catch (IOException e) {
throw new GradleException("Couldn't get git description", e);
}
}

jsonDeploy = builder.toJson(data);

Expand Down

0 comments on commit b28d3b5

Please sign in to comment.