2024-09-15 20:14:49 +02:00
|
|
|
//
|
|
|
|
// A labeled switch in zig allows the usage of continue and break
|
|
|
|
// just like loops, these allow you to create very concise
|
|
|
|
// Finite State Automata to represent state transitions
|
|
|
|
//
|
|
|
|
// foo: switch (state) {
|
|
|
|
// 1 => continue :foo 2,
|
|
|
|
// 2 => continue :foo 3,
|
2024-09-16 18:38:43 +02:00
|
|
|
// 3 => break :foo,
|
2024-09-15 20:14:49 +02:00
|
|
|
// 4 => {},
|
|
|
|
// ...
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
const std = @import("std");
|
|
|
|
|
2024-09-16 18:38:43 +02:00
|
|
|
const PullRequestState = enum(u8) {
|
2024-09-15 20:14:49 +02:00
|
|
|
Draft,
|
|
|
|
InReview,
|
|
|
|
Approved,
|
|
|
|
Rejected,
|
|
|
|
Merged,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn main() void {
|
2024-09-16 18:38:43 +02:00
|
|
|
// Oh no, your pull request keeps being rejected,
|
|
|
|
// how would you fix it?
|
2024-09-15 20:14:49 +02:00
|
|
|
pr: switch (@as(PullRequestState, PullRequestState.Draft)) {
|
|
|
|
PullRequestState.Draft => continue :pr PullRequestState.InReview,
|
|
|
|
PullRequestState.InReview => continue :pr PullRequestState.Rejected,
|
|
|
|
PullRequestState.Approved => continue :pr PullRequestState.Merged,
|
2024-09-16 18:38:43 +02:00
|
|
|
PullRequestState.Rejected => {
|
|
|
|
std.debug.print("The pull request has been rejected", .{});
|
|
|
|
return;
|
|
|
|
},
|
|
|
|
PullRequestState.Merged => break, // Would you know where to break to?
|
2024-09-15 20:14:49 +02:00
|
|
|
}
|
2024-09-16 18:38:43 +02:00
|
|
|
std.debug.print("The pull request has been merged", .{});
|
2024-09-15 20:14:49 +02:00
|
|
|
}
|