-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e338af3
commit 45f7c56
Showing
2 changed files
with
16 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
package org.apache.camel.karavan.git; | ||
|
||
import io.fabric8.kubernetes.api.model.Secret; | ||
import io.quarkus.oidc.UserInfo; | ||
import io.quarkus.security.identity.SecurityIdentity; | ||
import io.smallrye.mutiny.tuples.Tuple2; | ||
import io.vertx.core.Vertx; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
@@ -34,6 +36,7 @@ | |
import org.eclipse.jgit.api.errors.TransportException; | ||
import org.eclipse.jgit.diff.DiffEntry; | ||
import org.eclipse.jgit.lib.ObjectId; | ||
import org.eclipse.jgit.lib.PersonIdent; | ||
import org.eclipse.jgit.revwalk.RevCommit; | ||
import org.eclipse.jgit.transport.*; | ||
import org.eclipse.jgit.treewalk.TreeWalk; | ||
|
@@ -59,6 +62,9 @@ public class GitService { | |
@Inject | ||
KubernetesService kubernetesService; | ||
|
||
@Inject | ||
SecurityIdentity securityIdentity; | ||
|
||
private Git gitForImport; | ||
|
||
private static final Logger LOGGER = Logger.getLogger(GitService.class.getName()); | ||
|
@@ -305,13 +311,21 @@ private void addDeletedFilesToIndex(Git git, String folder, Project project, Lis | |
public RevCommit commitAddedAndPush(Git git, String branch, CredentialsProvider cred, String message) throws GitAPIException { | ||
LOGGER.info("Commit and push changes"); | ||
LOGGER.info("Git add: " + git.add().addFilepattern(".").call()); | ||
RevCommit commit = git.commit().setMessage(message).call(); | ||
RevCommit commit = git.commit().setMessage(message).setAuthor(getPersonIdent()).call(); | ||
LOGGER.info("Git commit: " + commit); | ||
Iterable<PushResult> result = git.push().add(branch).setRemote("origin").setCredentialsProvider(cred).call(); | ||
LOGGER.info("Git push: " + result); | ||
return commit; | ||
} | ||
|
||
private PersonIdent getPersonIdent() { | ||
if (securityIdentity != null && securityIdentity.getAttributes().get("userinfo") != null) { | ||
UserInfo userInfo = (UserInfo) securityIdentity.getAttributes().get("userinfo"); | ||
return new PersonIdent(securityIdentity.getPrincipal().getName(), userInfo.getEmail()); | ||
} | ||
return new PersonIdent("karavan", "[email protected]"); | ||
} | ||
|
||
public Git init(String dir, String uri, String branch) throws GitAPIException, IOException, URISyntaxException { | ||
Git git = Git.init().setInitialBranch(branch).setDirectory(Path.of(dir).toFile()).call(); | ||
// git.branchCreate().setName(branch).call(); | ||
|