Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

G2-1617 Use flags for condition creation #6

Merged
merged 5 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,16 @@ protected static class LinkType {

protected static Changes computeChanges(CreateConfig config) {
final Changes.ChangesBuilder retVal = Changes.builder();
for (CreateIssue raw : config.getIssues()) {
final Set<String> disabledSummaries = config.getDisabledIssues().stream().map(CreateIssue::getSummary).collect(Collectors.toSet());
for (CreateIssue raw : config.getEnabledIssues()) {
// Integrate the configuration into the issue & record it
final CreateIssue issue = raw.fallback(config);
retVal.issue(issue);

// Record all the links
for (String relationship : issue.getRelationships().keySet()) {
for (String target : issue.getRelationships().get(relationship)) {
retVal.link(new LinkIssuesInput(issue.getSummary(), target, relationship, null));
if (!disabledSummaries.contains(target)) retVal.link(new LinkIssuesInput(issue.getSummary(), target, relationship, null));
}
}
}
Expand Down Expand Up @@ -201,8 +202,10 @@ public List<String> createIssues(InputStream stream) throws JsonParseException,
final CreateConfig config = load(stream);
if ((config.getIssues() == null) || config.getIssues().isEmpty()) return Collections.emptyList();

config.validateFlags();
final Changes changes = computeChanges(config);
verifyChanges(changes);
//return changes.getIssues().stream().map(CreateIssue::getSummary).collect(Collectors.toList());
return implementChanges(changes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.g2forge.alexandria.java.core.helpers.HCollection;
import com.g2forge.alexandria.java.core.helpers.HCollector;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.Singular;

@Data
Expand Down Expand Up @@ -34,4 +41,31 @@ public class CreateConfig implements ICreateConfig {

@Singular
protected final Map<String, Set<String>> relationships;

@Singular
protected final Map<String, Boolean> flags;

@Getter(lazy = true)
@JsonIgnore
private final Map<String, Boolean> specifiedFlags = getFlags().entrySet().stream().filter(entry -> entry.getValue() != null).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

@Getter(lazy = true)
@JsonIgnore
private final Set<String> disabledFlags = getSpecifiedFlags().entrySet().stream().filter(entry -> !entry.getValue()).map(Map.Entry::getKey).collect(Collectors.toSet());

@JsonIgnore
public List<CreateIssue> getEnabledIssues() {
return getIssues().stream().filter(issue -> issue.isEnabled(this)).collect(Collectors.toList());
}

@JsonIgnore
public List<CreateIssue> getDisabledIssues() {
return getIssues().stream().filter(issue -> !issue.isEnabled(this)).collect(Collectors.toList());
}

public void validateFlags() {
final Set<String> referencedFlags = getIssues().stream().flatMap(issue -> issue.getFlags() == null ? Stream.empty() : issue.getFlags().stream()).collect(Collectors.toSet());
final Set<String> unknownFlags = HCollection.difference(referencedFlags, getSpecifiedFlags().keySet());
if (!unknownFlags.isEmpty()) throw new IllegalArgumentException("The following flags are refenced by issues, but are neither enabled nor disabled: " + unknownFlags.stream().collect(HCollector.joining(", ", ", & ")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.g2forge.alexandria.java.function.IFunction1;

import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -41,14 +43,20 @@ public class CreateIssue implements ICreateConfig {
@Singular
protected final Map<String, Set<String>> relationships;

@Singular
protected final Set<String> flags;

public CreateIssue fallback(CreateConfig config) {
final CreateIssueBuilder retVal = builder();

// Configurable fields
retVal.project(IFunction1.create(ICreateConfig::getProject).applyWithFallback(this, config));
retVal.type(IFunction1.create(ICreateConfig::getType).applyWithFallback(this, config));
retVal.epic(IFunction1.create(ICreateConfig::getEpic).applyWithFallback(this, config));
retVal.components(Stream.of(this, config).map(ICreateConfig::getComponents).flatMap(l -> l == null ? Stream.empty() : l.stream()).collect(Collectors.toSet()));

// Only add the components from the config if it's the same project (or we have no project)
retVal.components(Stream.of(this, (getProject() == null) || getProject().equals(config.getProject()) ? config : null).filter(Objects::nonNull).map(ICreateConfig::getComponents).flatMap(l -> l == null ? Stream.empty() : l.stream()).collect(Collectors.toSet()));

retVal.labels(Stream.of(this, config).map(ICreateConfig::getLabels).flatMap(l -> l == null ? Stream.empty() : l.stream()).collect(Collectors.toSet()));
retVal.securityLevel(IFunction1.create(ICreateConfig::getSecurityLevel).applyWithFallback(this, config));
retVal.assignee(IFunction1.create(ICreateConfig::getAssignee).applyWithFallback(this, config));
Expand All @@ -69,4 +77,9 @@ public CreateIssue fallback(CreateConfig config) {

return retVal.build();
}

@JsonIgnore
public boolean isEnabled(CreateConfig config) {
return (getFlags() == null) || !getFlags().stream().anyMatch(config.getDisabledFlags()::contains);
}
}
Loading