Skip to content

Commit

Permalink
chore: Improve GitLab/GitHub contributor output
Browse files Browse the repository at this point in the history
  • Loading branch information
rsenden committed Mar 27, 2023
1 parent 81d0985 commit aedce75
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@
import com.fortify.cli.scm.github.cli.util.GitHubPagingHelper;
import com.fortify.cli.scm.github.helper.GitHubRepoDescriptor;

import io.micronaut.core.annotation.ReflectiveAccess;
import kong.unirest.GetRequest;
import kong.unirest.HttpRequest;
import kong.unirest.UnirestInstance;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import picocli.CommandLine.Command;
import picocli.CommandLine.Mixin;
Expand Down Expand Up @@ -82,7 +80,7 @@ private static final class GitHubContributorProcessor extends AbstractGitHubRepo

@Override
protected void processRepo(UnirestInstance unirest, ProgressHelperMixin progressHelper, JsonNode repoNode) {
ExtendedGitHubRepoDescriptor repoDescriptor = JsonHelper.treeToValue(repoNode, ExtendedGitHubRepoDescriptor.class);
GitHubRepoDescriptor repoDescriptor = JsonHelper.treeToValue(repoNode, GitHubRepoDescriptor.class);
progressHelper.writeI18nProgress("loading.repository", repoDescriptor.getFullName());
String since = PERIOD_HELPER.getCurrentOffsetDateTimeMinusPeriod(lastPeriod)
.format(DateTimeFormatter.ISO_INSTANT);
Expand All @@ -104,18 +102,18 @@ protected void processRepo(UnirestInstance unirest, ProgressHelperMixin progress
}

private GetRequest getCommitsRequest(UnirestInstance unirest, GitHubRepoDescriptor descriptor) {
return unirest.get("/repos/{org}/{repo}/commits")
.routeParam("org", descriptor.getOwnerName())
return unirest.get("/repos/{owner}/{repo}/commits")
.routeParam("owner", descriptor.getOwnerName())
.routeParam("repo", descriptor.getRepoName());
}

private void handleRepoDataFailure(UnexpectedHttpResponseException e, ResultData resultData, ExtendedGitHubRepoDescriptor repoDescriptor) {
private void handleRepoDataFailure(UnexpectedHttpResponseException e, ResultData resultData, GitHubRepoDescriptor repoDescriptor) {
String msg = "Error loading commit data for repository: "+repoDescriptor.getFullName();
resultData.getWarnings().add(msg);
LOG.debug(msg, e);
}

private void collectDataForCommit(ResultData resultData, CollectedAuthors collectedAuthors, ExtendedGitHubRepoDescriptor repoDescriptor, JsonNode commit) {
private void collectDataForCommit(ResultData resultData, CollectedAuthors collectedAuthors, GitHubRepoDescriptor repoDescriptor, JsonNode commit) {
ObjectNode author = getAuthor(commit);
if ( !collectedAuthors.contains(author) ) {
collectedAuthors.add(author);
Expand Down Expand Up @@ -185,11 +183,4 @@ private static final class ResultData {
private ArrayNode results = JsonHelper.getObjectMapper().createArrayNode();
private List<String> warnings = new ArrayList<>();
}

@ReflectiveAccess
@Data @EqualsAndHashCode(callSuper = true)
private static final class ExtendedGitHubRepoDescriptor extends GitHubRepoDescriptor {
private int size;
private String html_url;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.fortify.cli.scm.github.helper;

import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fortify.cli.common.json.JsonNodeHolder;

import io.micronaut.core.annotation.ReflectiveAccess;
Expand All @@ -14,19 +15,21 @@

@ReflectiveAccess
@Data @EqualsAndHashCode(callSuper=true)
@JsonPropertyOrder({"owner_name","repo_name","full_name","visibility","fork"})
public class GitHubRepoDescriptor extends JsonNodeHolder {
@JsonProperty("owner_name")
private static final Logger LOG = LoggerFactory.getLogger(GitHubRepoDescriptor.class);
@Getter(onMethod_=@JsonProperty("owner_name"))
private String ownerName;
@Setter(onMethod_=@JsonProperty("name")) @Getter(onMethod_=@JsonProperty("repo_name"))
private String repoName;
@JsonProperty("full_name")
private String fullName;
private String html_url;
private String visibility;
private boolean fork;

@JsonProperty("owner")
private void unpackOwner(Map<String, String> owner) {
ownerName = owner.get("login");
public void setOwner(ObjectNode owner) {
LOG.debug("Unpacking owner: "+owner);
this.ownerName = owner.get("login").asText();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import kong.unirest.HttpRequest;
import kong.unirest.UnirestInstance;

public abstract class AbstractGitLabBaseRequestOutputCommand extends AbstractLabHubOutputCommand implements IBaseRequestSupplier {
public abstract class AbstractGitLabBaseRequestOutputCommand extends AbstractGitLabOutputCommand implements IBaseRequestSupplier {
@Override
public final HttpRequest<?> getBaseRequest() {
try ( var unirest = getProductHelper().createUnirestInstance() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import kong.unirest.UnirestInstance;

public abstract class AbstractGitLabJsonNodeOutputCommand extends AbstractLabHubOutputCommand implements IJsonNodeSupplier {
public abstract class AbstractGitLabJsonNodeOutputCommand extends AbstractGitLabOutputCommand implements IJsonNodeSupplier {
@Override
public final JsonNode getJsonNode() {
try ( var unirest = getProductHelper().createUnirestInstance() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import lombok.Getter;
import picocli.CommandLine.Mixin;

public abstract class AbstractLabHubOutputCommand extends AbstractOutputCommand
public abstract class AbstractGitLabOutputCommand extends AbstractOutputCommand
implements IProductHelperSupplier
{
@Getter @Mixin GitLabProductHelperMixin productHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@
import com.fortify.cli.scm.gitlab.cli.util.GitLabPagingHelper;
import com.fortify.cli.scm.gitlab.helper.GitLabProjectDescriptor;

import io.micronaut.core.annotation.ReflectiveAccess;
import kong.unirest.GetRequest;
import kong.unirest.HttpRequest;
import kong.unirest.UnirestInstance;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import picocli.CommandLine.Command;
import picocli.CommandLine.Mixin;
Expand Down Expand Up @@ -82,7 +80,7 @@ private static final class GitLabContributorProcessor extends AbstractGitLabProj

@Override
protected void processProject(UnirestInstance unirest, ProgressHelperMixin progressHelper, JsonNode projectNode) {
ExtendedGitLabProjectDescriptor projectDescriptor = JsonHelper.treeToValue(projectNode, ExtendedGitLabProjectDescriptor.class);
GitLabProjectDescriptor projectDescriptor = JsonHelper.treeToValue(projectNode, GitLabProjectDescriptor.class);
progressHelper.writeI18nProgress("loading.project", projectDescriptor.getProjectFullPath());
String since = PERIOD_HELPER.getCurrentOffsetDateTimeMinusPeriod(lastPeriod)
.format(DateTimeFormatter.ISO_INSTANT);
Expand All @@ -103,18 +101,18 @@ protected void processProject(UnirestInstance unirest, ProgressHelperMixin progr
}
}

private GetRequest getCommitsRequest(UnirestInstance unirest, ExtendedGitLabProjectDescriptor descriptor) {
private GetRequest getCommitsRequest(UnirestInstance unirest, GitLabProjectDescriptor descriptor) {
return unirest.get("/api/v4/projects/{id}/repository/commits")
.routeParam("id", descriptor.getProjectId());
}

private void handleRepoDataFailure(UnexpectedHttpResponseException e, ResultData resultData, ExtendedGitLabProjectDescriptor repoDescriptor) {
private void handleRepoDataFailure(UnexpectedHttpResponseException e, ResultData resultData, GitLabProjectDescriptor repoDescriptor) {
String msg = "Error loading commit data for project: "+repoDescriptor.getProjectFullPath();
resultData.getWarnings().add(msg);
LOG.debug(msg, e);
}

private void collectDataForCommit(ResultData resultData, CollectedAuthors collectedAuthors, ExtendedGitLabProjectDescriptor projectDescriptor, JsonNode commit) {
private void collectDataForCommit(ResultData resultData, CollectedAuthors collectedAuthors, GitLabProjectDescriptor projectDescriptor, JsonNode commit) {
ObjectNode author = getAuthor(commit);
if ( !collectedAuthors.contains(author) ) {
collectedAuthors.add(author);
Expand Down Expand Up @@ -180,10 +178,4 @@ private static final class ResultData {
private ArrayNode results = JsonHelper.getObjectMapper().createArrayNode();
private List<String> warnings = new ArrayList<>();
}

@ReflectiveAccess
@Data @EqualsAndHashCode(callSuper = true)
private static final class ExtendedGitLabProjectDescriptor extends GitLabProjectDescriptor {
private String web_url;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.fortify.cli.scm.gitlab.helper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.JsonNode;
import com.fortify.cli.common.json.JsonNodeHolder;

import io.micronaut.core.annotation.ReflectiveAccess;
Expand All @@ -12,13 +15,21 @@

@ReflectiveAccess
@Data @EqualsAndHashCode(callSuper=true)
@JsonPropertyOrder({"project_id","full_path","project_name", "visibility"})
public class GitLabProjectDescriptor extends JsonNodeHolder {
private static final Logger LOG = LoggerFactory.getLogger(GitLabProjectDescriptor.class);
@Setter(onMethod_={@JsonProperty("id")}) @Getter(onMethod_={@JsonProperty("project_id")})
private String projectId;
@Setter(onMethod_={@JsonProperty("name")}) @Getter(onMethod_={@JsonProperty("project_name")})
private String projectName;
@Setter(onMethod_={@JsonProperty("path_with_namespace")}) @Getter(onMethod_={@JsonProperty("project_full_path")})
private String projectFullPath;
private String web_url;
private String visibility;
private boolean fork = false;

@JsonProperty("forked_from_project")
public void setForkedFromProject(JsonNode fork) {
LOG.debug("Unpacking fork: "+fork);
this.fork = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ fcli.scm.github-contributor.list.search.1 = --search 'org:myOrg topic:scanned-by
fcli.scm.github-contributor.list.loading.organizations = Loading organizations
fcli.scm.github-contributor.list.loading.repositories = Loading repositories for organization %s
fcli.scm.github-contributor.list.loading.repository = Loading data for repository %s
fcli.scm.github-contributor.list.output.header.htmlUrl = Repository


# GitLab
fcli.scm.gitlab.gitlab-url = GitLab URL, i.e. https://gitlab.com or the URL to your private GitLab instance.
Expand All @@ -39,11 +41,12 @@ fcli.scm.gitlab-contributor.list.topic = Load data for the repositories matching
fcli.scm.gitlab-contributor.list.loading.groups = Loading groups
fcli.scm.gitlab-contributor.list.loading.projects = Loading projects for group %s
fcli.scm.gitlab-contributor.list.loading.project = Loading data for project %s
fcli.scm.gitlab-contributor.list.output.header.webUrl = Repository

#################################################################################################################
# The following are technical properties that shouldn't be internationalized ####################################
#################################################################################################################

# Table output columns configuration
fcli.scm.github-contributor.output.table.options = full_name,visibility,fork,author.name,lastCommit
fcli.scm.gitlab-contributor.output.table.options = web_url,visibility,author.name,lastCommit
fcli.scm.github-contributor.output.table.options = html_url,visibility,fork,author.name,lastCommit
fcli.scm.gitlab-contributor.output.table.options = web_url,visibility,fork,author.name,lastCommit
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class SSCAppVersionDescriptor extends JsonNodeHolder {
@JsonProperty("name") private String versionName;

@JsonProperty("project")
private void unpackProject(Map<String, String> project) {
public void unpackProject(Map<String, String> project) {
applicationId = project.get("id");
applicationName = project.get("name");
}
Expand Down

0 comments on commit aedce75

Please sign in to comment.