Skip to content

Commit 182cb82

Browse files
Fixed process runner to call from branch folders
1 parent 464b769 commit 182cb82

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

src/main/java/io/micrometer/release/common/ProcessRunner.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ProcessRunner {
3737
private final Map<String, String> envVars = new HashMap<>();
3838

3939
public ProcessRunner() {
40-
this(null, null);
40+
this((String) null, null);
4141
}
4242

4343
public ProcessRunner(String repo) {
@@ -49,6 +49,17 @@ public ProcessRunner(String repo, File directory) {
4949
this.directory = directory;
5050
}
5151

52+
public ProcessRunner(File directory) {
53+
this.repo = null;
54+
this.directory = directory;
55+
}
56+
57+
// E.g. Same repo, different branch
58+
public ProcessRunner(ProcessRunner processRunner, File directory) {
59+
this.repo = processRunner.repo;
60+
this.directory = directory;
61+
}
62+
5263
public ProcessRunner withEnvVars(Map<String, String> envVars) {
5364
this.envVars.putAll(envVars);
5465
return this;

src/main/java/io/micrometer/release/train/DependencyVerifier.java

+14-9
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void verifyDependencies(String branch, String orgRepository) {
7171
log.info("Fetching all dependencies before dependabot...");
7272
Set<Dependency> dependenciesBeforeDependabot = micrometerOnly(gradleParser.fetchAllDependencies());
7373
Status status = dependabotUpdateStatus(clonedRepo, orgRepository);
74-
pullTheLatestRepoChanges();
74+
pullTheLatestRepoChanges(clonedRepo);
7575
Set<Dependency> dependenciesAfterDependabot = micrometerOnly(gradleParser.fetchAllDependencies());
7676
Set<Dependency> diff = new HashSet<>(dependenciesAfterDependabot);
7777
diff.removeAll(dependenciesBeforeDependabot);
@@ -111,7 +111,7 @@ private Status dependabotUpdateStatus(File clonedRepo, String orgRepository) {
111111
}
112112

113113
private GradleParser getGradleParser(File branch) {
114-
ProcessRunner branchProcessRunner = new ProcessRunner(null, branch);
114+
ProcessRunner branchProcessRunner = new ProcessRunner(branch);
115115
return gradleParser(branchProcessRunner);
116116
}
117117

@@ -130,9 +130,9 @@ File clonedDir(String branch) {
130130
return new File(branch);
131131
}
132132

133-
private void pullTheLatestRepoChanges() {
133+
private void pullTheLatestRepoChanges(File clonedRepo) {
134134
log.info("Pulling the latest repo changes");
135-
processRunner.run("git", "pull");
135+
processRunnerForBranch(clonedRepo).run("git", "pull");
136136
}
137137

138138
private void sleep(int timeoutToSleep) {
@@ -180,12 +180,13 @@ private void triggerDependabotCheck(File clonedRepo) {
180180
log.info("Added trigger comment to dependabot.yml");
181181
}
182182
Files.writeString(path, fileContent);
183-
processRunner.run("git", "config", "user.name", "GitHub Action");
184-
processRunner.run("git", "config", "user.email", "[email protected]");
185-
processRunner.run("git", "add", filePath);
186-
processRunner.run("git", "commit", "-m",
183+
ProcessRunner branchProcessRunner = processRunnerForBranch(clonedRepo);
184+
branchProcessRunner.run("git", "config", "user.name", "GitHub Action");
185+
branchProcessRunner.run("git", "config", "user.email", "[email protected]");
186+
branchProcessRunner.run("git", "add", filePath);
187+
branchProcessRunner.run("git", "commit", "-m",
187188
"ci: " + (hasComment ? "Remove" : "Add") + " dependabot trigger comment");
188-
processRunner.run("git", "push");
189+
branchProcessRunner.run("git", "push");
189190
}
190191
catch (Exception e) {
191192
log.error("Failed to modify dependabot.yml", e);
@@ -194,6 +195,10 @@ private void triggerDependabotCheck(File clonedRepo) {
194195
log.info("Triggered Dependabot check");
195196
}
196197

198+
ProcessRunner processRunnerForBranch(File clonedRepo) {
199+
return new ProcessRunner(this.processRunner, clonedRepo);
200+
}
201+
197202
private void waitForDependabotJobsToFinish(String orgRepository, String githubServerTime) {
198203
log.info("Waiting {} {} for Dependabot jobs to be created...", initialWait, timeUnit);
199204
sleep(initialWait);

src/test/java/io/micrometer/release/train/DependencyVerifierTests.java

+5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ File clonedDir(String branch) {
7373
throw new RuntimeException(e);
7474
}
7575
}
76+
77+
@Override
78+
ProcessRunner processRunnerForBranch(File clonedRepo) {
79+
return processRunner;
80+
}
7681
};
7782

7883
DependencyVerifierTests() throws URISyntaxException {

0 commit comments

Comments
 (0)