Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
bbende committed Sep 16, 2024
1 parent 2d03ceb commit f4e1cff
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public Optional<String> getLatestVersion(final FlowRegistryClientConfigurationCo
final String filePath = getSnapshotFilePath(flowLocation);

final List<GitCommit> commits = repositoryClient.getCommits(filePath, branch);
final String latestVersion = commits.isEmpty() ? null : commits.getFirst().getId();
final String latestVersion = commits.isEmpty() ? null : commits.getFirst().id();
return Optional.ofNullable(latestVersion);
}

Expand Down Expand Up @@ -431,10 +431,10 @@ private RegisteredFlowSnapshotMetadata createSnapshotMetadata(final GitCommit co
snapshotMetadata.setBranch(flowLocation.getBranch());
snapshotMetadata.setBucketIdentifier(flowLocation.getBucketId());
snapshotMetadata.setFlowIdentifier(flowLocation.getFlowId());
snapshotMetadata.setVersion(commit.getId());
snapshotMetadata.setAuthor(commit.getAuthor());
snapshotMetadata.setComments(commit.getMessage());
snapshotMetadata.setTimestamp(commit.getCommitDate().getTime());
snapshotMetadata.setVersion(commit.id());
snapshotMetadata.setAuthor(commit.author());
snapshotMetadata.setComments(commit.message());
snapshotMetadata.setTimestamp(commit.commitDate().toEpochMilli());
return snapshotMetadata;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,71 +17,16 @@

package org.apache.nifi.registry.flow.git.client;

import java.util.Date;
import java.time.Instant;
import java.util.Objects;

public class GitCommit {

private final String id;
private final String author;
private final String message;
private final Date commitDate;

private GitCommit(final Builder builder) {
this.id = Objects.requireNonNull(builder.id, "Id is required");
this.author = Objects.requireNonNull(builder.author, "Author is required");
this.commitDate = Objects.requireNonNull(builder.commitDate, "Commit Date is required");
this.message = builder.message;
}

public String getId() {
return id;
}

public String getAuthor() {
return author;
}

public String getMessage() {
return message;
}

public Date getCommitDate() {
return commitDate;
}

public static Builder builder() {
return new Builder();
}

public static final class Builder {
private String id;
private String author;
private String message;
private Date commitDate;

public Builder id(final String id) {
this.id = id;
return this;
}

public Builder author(final String author) {
this.author = author;
return this;
}

public Builder message(final String message) {
this.message = message;
return this;
}

public Builder commitDate(final Date commitDate) {
this.commitDate = commitDate;
return this;
}

public GitCommit build() {
return new GitCommit(this);
}
/**
* Info for a git commit.
*/
public record GitCommit(String id, String author, String message, Instant commitDate) {
public GitCommit {
Objects.requireNonNull(id, "Id is required");
Objects.requireNonNull(author, "Author is required");
Objects.requireNonNull(commitDate, "Commit Date is required");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.security.PrivateKey;
import java.time.Instant;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -407,12 +408,12 @@ private void throwPathOrBranchNotFound(final FileNotFoundException fileNotFoundE

private GitCommit toGitCommit(final GHCommit ghCommit) throws IOException {
final GHCommit.ShortInfo shortInfo = ghCommit.getCommitShortInfo();
return GitCommit.builder()
.id(ghCommit.getSHA1())
.author(ghCommit.getAuthor().getLogin())
.message(shortInfo.getMessage())
.commitDate(shortInfo.getCommitDate())
.build();
return new GitCommit(
ghCommit.getSHA1(),
ghCommit.getAuthor().getLogin(),
shortInfo.getMessage(),
Instant.ofEpochMilli(shortInfo.getCommitDate().getTime())
);
}

private <T> T execute(final GHRequest<T> action) throws FlowRegistryException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,31 @@

package org.apache.nifi.gitlab;

public enum GitLabAuthenticationType {
ACCESS_TOKEN
import org.apache.nifi.components.DescribedValue;

public enum GitLabAuthenticationType implements DescribedValue {
ACCESS_TOKEN("Access Token", "Group, Project, or Personal Access Token");

private final String displayName;
private final String description;

GitLabAuthenticationType(final String displayName, final String description) {
this.displayName = displayName;
this.description = description;
}

@Override
public String getValue() {
return name();
}

@Override
public String getDisplayName() {
return displayName;
}

@Override
public String getDescription() {
return description;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class GitLabFlowRegistryClient extends AbstractGitFlowRegistryClient {
.name("Authentication Type")
.description("The type of authentication to use for accessing GitLan")
.allowableValues(GitLabAuthenticationType.class)
.defaultValue(GitLabAuthenticationType.ACCESS_TOKEN.name())
.defaultValue(GitLabAuthenticationType.ACCESS_TOKEN)
.required(true)
.build();

Expand All @@ -78,7 +78,7 @@ public class GitLabFlowRegistryClient extends AbstractGitFlowRegistryClient {
.addValidator(StandardValidators.NON_BLANK_VALIDATOR)
.required(true)
.sensitive(true)
.dependsOn(AUTHENTICATION_TYPE, GitLabAuthenticationType.ACCESS_TOKEN.name())
.dependsOn(AUTHENTICATION_TYPE, GitLabAuthenticationType.ACCESS_TOKEN)
.build();

static final PropertyDescriptor CONNECT_TIMEOUT = new PropertyDescriptor.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -377,12 +378,12 @@ private boolean isFile(final TreeItem item) {
}

private GitCommit toGitCommit(final Commit commit) {
return GitCommit.builder()
.id(commit.getId())
.author(commit.getAuthorName())
.message(commit.getMessage())
.commitDate(commit.getCommittedDate())
.build();
return new GitCommit(
commit.getId(),
commit.getAuthorName(),
commit.getMessage(),
Instant.ofEpochMilli(commit.getCommittedDate().getTime())
);
}

/**
Expand Down

0 comments on commit f4e1cff

Please sign in to comment.