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

feat(context): Adds trigger contents to stage context #1659

Merged
merged 1 commit into from
Oct 3, 2017
Merged
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 @@ -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 @@ -74,6 +83,11 @@ public List<Object> getAll(Object key) {
result.add(0, delegate.get(key));
}

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

return result;
}
}