Skip to content

Commit

Permalink
Fixed #1006
Browse files Browse the repository at this point in the history
  • Loading branch information
mgubaidullin committed Nov 29, 2023
1 parent e338af3 commit 45f7c56
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.camel.karavan.api;

import io.quarkus.oidc.UserInfo;
import io.quarkus.security.identity.SecurityIdentity;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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());
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 45f7c56

Please sign in to comment.