Skip to content

Commit 507c0dc

Browse files
Fighting with git, creds and gh actions
1 parent f5e1e4c commit 507c0dc

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private void assertDependencyDiff(Status status, Set<Dependency> diff) {
105105

106106
private Status dependabotUpdateStatus(File clonedRepo, String orgRepository) {
107107
String githubServerTime = getGitHubServerTime();
108-
triggerDependabotCheck(clonedRepo);
108+
triggerDependabotCheck(orgRepository, clonedRepo);
109109
waitForDependabotJobsToFinish(orgRepository, githubServerTime);
110110
return waitForDependabotPrsToFinish(githubServerTime);
111111
}
@@ -162,7 +162,7 @@ private String getGitHubServerTime() {
162162
return serverTime;
163163
}
164164

165-
private void triggerDependabotCheck(File clonedRepo) {
165+
private void triggerDependabotCheck(String orgRepository, File clonedRepo) {
166166
log.info("Will trigger a Dependabot check...");
167167
try {
168168
String filePath = ".github/dependabot.yml";
@@ -179,7 +179,10 @@ private void triggerDependabotCheck(File clonedRepo) {
179179
log.info("Added trigger comment to dependabot.yml");
180180
}
181181
Files.writeString(path, fileContent);
182+
String githubToken = ghToken();
182183
ProcessRunner branchProcessRunner = processRunnerForBranch(clonedRepo);
184+
branchProcessRunner.run("git", "remote", "set-url", "origin",
185+
"https://x-access-token:" + githubToken + "@github.com/" + orgRepository + ".git");
183186
branchProcessRunner.run("git", "config", "user.name", "GitHub Action");
184187
branchProcessRunner.run("git", "config", "user.email", "[email protected]");
185188
branchProcessRunner.run("git", "add", filePath);
@@ -194,6 +197,10 @@ private void triggerDependabotCheck(File clonedRepo) {
194197
log.info("Triggered Dependabot check");
195198
}
196199

200+
String ghToken() {
201+
return System.getenv("GH_TOKEN");
202+
}
203+
197204
ProcessRunner processRunnerForBranch(File clonedRepo) {
198205
return new ProcessRunner(this.processRunner, clonedRepo);
199206
}

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

+8
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ File clonedDir(String branch) {
7474
}
7575
}
7676

77+
@Override
78+
String ghToken() {
79+
return "1234567890";
80+
}
81+
7782
@Override
7883
ProcessRunner processRunnerForBranch(File clonedRepo) {
7984
return processRunner;
@@ -103,6 +108,9 @@ void should_receive_updated_dependabot_status() throws IOException {
103108

104109
InOrder inOrder = Mockito.inOrder(processRunner);
105110
inOrder.verify(processRunner).run("gh", "api", "/", "--include");
111+
inOrder.verify(processRunner)
112+
.run("git", "remote", "set-url", "origin",
113+
"https://x-access-token:[email protected]/micrometer-metrics/micrometer.git");
106114
inOrder.verify(processRunner).run("git", "config", "user.name", "GitHub Action");
107115
inOrder.verify(processRunner).run("git", "config", "user.email", "[email protected]");
108116
inOrder.verify(processRunner).run("git", "add", ".github/dependabot.yml");

0 commit comments

Comments
 (0)