Skip to content

Instantly share code, notes, and snippets.

@Graham42
Last active June 3, 2020 15:32
Show Gist options
  • Save Graham42/207af63c96c9d16c69e90f4813edc996 to your computer and use it in GitHub Desktop.
Save Graham42/207af63c96c9d16c69e90f4813edc996 to your computer and use it in GitHub Desktop.
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
// this would be set based on some event data
const isDraft = (context, event) => true;
const buildStates = {
initial: "building",
states: {
building: {
on: {
SUCCESS: "passing",
FAILURE: "failing",
},
},
failing: {
on: {
REBUILD: "building",
},
},
passing: {
type: "final",
},
},
};
const reviewStates = {
initial: "development",
states: {
development: {
on: {
FINISHED: "review",
},
},
review: {
on: {
REQUEST_CHANGES: "development",
APPROVE: "passed",
},
},
passed: {
type: "final",
},
},
};
const prMachine = Machine({
id: "pr",
initial: "unknown",
context: {
checks: {},
},
states: {
unknown: {
on: {
"": [
//
{ target: "draft", cond: isDraft },
{ target: "open" },
],
},
},
draft: {
on: {
OPEN: "open",
},
},
open: {
type: "parallel",
on: {
CLOSE: "closed",
},
states: {
build: {
...buildStates,
on: {
// this acts like a reset
BRANCH_UPDATED: "build",
},
}, // end build
review: {
...reviewStates,
on: {
BRANCH_UPDATED: "review.review",
},
}, // end review
// TODO do we need check for merge conflict?
},
onDone: "merging",
}, // end open
merging: {
on: {
MERGE_AND_CLOSE: "closed",
},
},
closed: {
on: {
REOPEN: "open",
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment