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

Add ability to select goal based on push in DSL #642

Merged
merged 2 commits into from
Dec 24, 2018
Merged

Conversation

johnsonr
Copy link
Contributor

@johnsonr johnsonr commented Dec 24, 2018

Adds a setGoalsWhen method to GoalSetter that allows choosing goals based on the push invocation. This combines with the recent introduction of stateful push invocations to allow previously computed state to be used in both goal choice and goal selection.

The following example precomputes phases, attaches them as state to the invocation, and then chooses them on goal setting:

interface Analyzed {
    interpretation: Interpretation;
    phases: CiPhases;
}

sdm.withPushRules(
        // Attach facts to the invocation
        attachFacts<Analyzed>(async pu => {
            const interpretation = await analyzer.interpret(pu.project);
            const phases = createPhases(interpretation);
            return { interpretation, phases };
        }),
       // Choose and set goals based on introduced state
        onAnyPush<StatefulPushListenerInvocation<Analyzed>>()
            .setGoalsWhen(pu => pu.facts.phases.checkGoals),
        whenPushSatisfies<StatefulPushListenerInvocation<Analyzed>>(
            async pu => !!pu.facts.phases.buildGoals)
            .setGoalsWhen(pu => pu.facts.phases.buildGoals),
        whenPushSatisfies<StatefulPushListenerInvocation<Analyzed>>(
            async pu => !!pu.facts.phases.testGoals)
            .setGoalsWhen(pu => pu.facts.phases.testGoals),
    );

This change is backward compatible.

In this case the GoalSetter does not work as a StaticPushMapping, making it impossible to predict all goals that will be set.

@cdupuis cdupuis added changelog:added Add this issue or pull request to added changelog section auto-merge:on-approve Auto-merge on review approvals auto-merge-method:squash Auto-merge with squash and merge labels Dec 24, 2018
@cdupuis cdupuis self-requested a review December 24, 2018 08:24
Copy link
Member

@cdupuis cdupuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@atomist-bot
Copy link
Contributor

Pull request auto merged by Atomist.

  • 1 approved review by @cdupuis
  • 2 successful checks

[atomist:generated] [auto-merge:on-approve]

@atomist-bot atomist-bot merged commit f8afe23 into master Dec 24, 2018
@atomist-bot atomist-bot deleted the setGoalsWhen branch December 24, 2018 08:25
atomist-bot added a commit that referenced this pull request Dec 24, 2018
[atomist:generated]
olvesh pushed a commit to olvesh/sdm that referenced this pull request Jan 11, 2019
* master: (104 commits)
  Autofix: tslint
  Autofix: TypeScript header
  Fix misplaced comment
  Changelog: add release 1.2.0
  Version: increment after 1.2.0 release
  Autofix: Third party licenses
  Update client to 1.2.0
  Autofix: Third party licenses
  Update all dependencies
  Changelog: atomist#639 to fixed
  Correct typo
  Changelog: atomist#642 to added
  Auto merge pull request atomist#642 from atomist/sdm
  Changelog: 7fd6fab to fixed
  Fix issues when pushTest is missing on project listener
  Update doc on goal execution listener
  Autofix: Third party licenses
  Changelog: 87a5514 to changed
  Changelog: 1a3e3e2 to changed
  Delint
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge:on-approve Auto-merge on review approvals auto-merge-method:squash Auto-merge with squash and merge changelog:added Add this issue or pull request to added changelog section
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants