Skip to content

Commit

Permalink
feat(context): Adds trigger contents to stage context
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Wander committed Oct 2, 2017
1 parent c4d53c3 commit 9c5e7f6
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.google.common.collect.ForwardingMap;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -39,6 +39,15 @@ public StageContext(Stage<?> stage) {
return delegate;
}

private Map<String, Object> getTrigger() {
Execution execution = stage.getExecution();
if (execution instanceof Pipeline) {
return ((Pipeline) execution).getTrigger();
} else {
return Collections.emptyMap();
}
}

@Override public Object get(@Nullable Object key) {
if (delegate().containsKey(key)) {
return super.get(key);
Expand All @@ -53,7 +62,7 @@ public StageContext(Stage<?> stage) {
Optional
.ofNullable(stage.getExecution())
.map(execution -> execution.getContext().get(key))
.orElse(null)
.orElse(getTrigger().get(key))
);
}
}
Expand All @@ -73,6 +82,11 @@ public List<Object> getAll(Object key) {
if (delegate.containsKey(key)) {
result.add(0, delegate.get(key));
}

Map<String, Object> trigger = getTrigger();
if (trigger.containsKey(key)) {
result.add(key);
}

return result;
}
Expand Down

0 comments on commit 9c5e7f6

Please sign in to comment.