Skip to content

Commit

Permalink
fix #304 scm import perform should include deletedJobs in request
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Aug 11, 2020
1 parent f036bf4 commit ebbe161
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ScmActionPerform {
private List<String> jobs;
private List<String> items;
private List<String> deleted;
private List<String> deletedJobs;

public Map<String, String> getInput() {
return input;
Expand Down Expand Up @@ -66,4 +67,12 @@ public List<String> getDeleted() {
public void setDeleted(List<String> deleted) {
this.deleted = deleted;
}

public List<String> getDeletedJobs() {
return deletedJobs;
}

public void setDeletedJobs(List<String> deletedJobs) {
this.deletedJobs = deletedJobs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
public class ScmImportItem implements DataOutput {
public String itemId;
public Boolean tracked;
public Boolean deleted;
public boolean deleted;
public ScmJobItem job;
public String status;

public Map asMap() {
HashMap<String, Object> map = new HashMap<>();
map.put("itemId", itemId);
map.put("tracked", tracked);
map.put("deleted", deleted != null ? deleted : false);
map.put("deleted", deleted);
map.put("status", status);
if(null!=job) {
map.put("job", job.toMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,28 @@ public boolean perform(ActionPerformOptions options, CommandOutput output) throw
}
} else {
List<ScmImportItem> importItems = inputs.importItems;
perform.setItems(importItems.stream()
.filter(a -> options.isAllItems() ||
options.isAllTrackedItems() && a.tracked ||
options.isAllUntrackedItems() && !a.tracked)
.map(a -> a.itemId)
.collect(Collectors.toList()));
perform.setItems(
importItems.stream()
.filter(a -> !a.deleted && (
options.isAllItems() ||
options.isAllTrackedItems() && a.tracked ||
options.isAllUntrackedItems() && !a.tracked
)
)
.map(a -> a.itemId)
.collect(Collectors.toList())
);
perform.setDeletedJobs(
importItems.stream()
.filter(a -> a.deleted && a.job != null && (
options.isAllItems() ||
options.isAllTrackedItems() && a.tracked ||
options.isAllUntrackedItems() && !a.tracked
)
)
.map(a -> a.job.jobId)
.collect(Collectors.toList())
);
}
}
ServiceClient.WithErrorResponse<ScmActionResult> response = apiWithErrorResponse(api -> api.performScmAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import retrofit2.Retrofit
import retrofit2.converter.jackson.JacksonConverterFactory
import retrofit2.mock.Calls
import spock.lang.Specification
import spock.lang.Unroll

/**
* @author greg
Expand Down Expand Up @@ -83,6 +84,7 @@ class SCMSpec extends Specification {
1 * out.output([message: 'required'])
}

@Unroll
def "perform import with include flags"() {
given:
def api = Mock(RundeckApi)
Expand Down Expand Up @@ -112,6 +114,8 @@ class SCMSpec extends Specification {
def items = [
new ScmImportItem(itemId: 'a', tracked: true),
new ScmImportItem(itemId: 'b', tracked: false),
new ScmImportItem(itemId: 'c', tracked: true, deleted: true, job: new ScmJobItem(jobId: 'ajob')),
new ScmImportItem(itemId: 'd', tracked: false, deleted: true, job: new ScmJobItem(jobId: 'xjob')),
]
when:
def result = scm.perform(opts, out)
Expand All @@ -123,7 +127,8 @@ class SCMSpec extends Specification {
)

1 * api.performScmAction('aproject', 'import', 'import-all', { ScmActionPerform arg ->
arg.items == expected
arg.items == expectedItems
arg.deletedJobs==expectedDeletedJobs
}
) >>
Calls.response(
Expand All @@ -132,10 +137,10 @@ class SCMSpec extends Specification {

0 * api._(*_)
where:
all | tracked | untracked | expected
true | false | false | ['a', 'b']
false | true | false | ['a']
false | false | true | ['b']
all | tracked | untracked | expectedItems | expectedDeletedJobs
true | false | false | ['a', 'b'] | ['ajob','xjob']
false | true | false | ['a'] | ['ajob']
false | false | true | ['b'] | ['xjob']
}

def "perform export with include flags"() {
Expand Down

0 comments on commit ebbe161

Please sign in to comment.