flowey_lib_common/
gh_latest_completed_workflow_id.rs1use flowey::node::prelude::*;
6
7flowey_request! {
8 pub struct Request {
9 pub repo: String,
10 pub pipeline_name: String,
11 pub branch: ReadVar<String>,
12 pub gh_workflow_id: WriteVar<String>,
13 }
14}
15new_simple_flow_node!(struct Node);
16
17impl SimpleFlowNode for Node {
18 type Request = Request;
19
20 fn imports(ctx: &mut ImportCtx<'_>) {
21 ctx.import::<crate::use_gh_cli::Node>();
22 }
23
24 fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
25 let Request {
26 repo,
27 gh_workflow_id,
28 pipeline_name,
29 branch,
30 } = request;
31
32 let pipeline_name = pipeline_name.clone();
33
34 let gh_cli = ctx.reqv(crate::use_gh_cli::Request::Get);
35
36 ctx.emit_rust_step("get latest completed action id", |ctx| {
37 let pipeline_name = pipeline_name.clone();
38 let gh_cli = gh_cli.claim(ctx);
39 let gh_workflow_id = gh_workflow_id.claim(ctx);
40 let branch = branch.claim(ctx);
41
42 move |rt| {
43 let gh_cli = rt.read(gh_cli);
44 let branch = rt.read(branch);
45
46 let id = flowey::shell_cmd!(
47 rt,
48 "{gh_cli} run list -R {repo} -b {branch} -w {pipeline_name} -s success --limit 1 --json databaseId -q .[0].databaseId"
49 )
50 .read()?;
51
52 log::info!("Got action id {id}");
53 rt.write(gh_workflow_id, &id);
54
55 Ok(())
56 }
57 });
58
59 Ok(())
60 }
61}