Skip to content

Commit

Permalink
Try to fix github action
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Sep 18, 2024
1 parent fe15460 commit 4b5866e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
12 changes: 6 additions & 6 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: 'pear-reviewer'
description: 'Run pear-reviewer'
name: pear-reviewer
description: Run pear-reviewer
runs:
using: "composite"
using: composite
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Run pear-reviewer
id: run-pear-reviewer
uses: docker://ghcr.io/sapcc/pear-reviewer:latest
run:
pear-reviewer > $GITHUB_OUTPUT
uses: docker://ghcr.io/sapcc/pear-reviewer:edge
with:
args: repo

- name: Find Comment
uses: peter-evans/find-comment@v3
Expand Down
30 changes: 22 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ mod helm_config;
mod remote;
mod repo;

use std::str;
use std::fs::File;
use std::io::Write;
use std::sync::LazyLock;
use std::{env, str};

use anyhow::{anyhow, Context};
use api_clients::{ClientSet, RealClient};
Expand Down Expand Up @@ -186,14 +188,26 @@ fn find_values_yaml(
Ok(changes)
}

fn println_or_redirect(line: String) -> Result<(), anyhow::Error> {
if env::var("GITHUB_ACTIONS").is_ok() {
let path = env::var("GITHUB_OUTPUT").context("cannot find GITHUB_OUTPUT")?;
let mut file = File::create(path.clone()).with_context(|| format!("cannot write to $GITHUB_OUTPUT {path}"))?;
file.write_all((line + "\n").as_bytes())?;
} else {
println!("{line}");
}

Ok(())
}

fn print_changes(repo_changeset: &[RepoChangeset<RealClient>]) -> Result<(), anyhow::Error> {
for change in repo_changeset {
println!(
println_or_redirect(format!(
"Name {} from {} moved from {} to {}",
change.name, change.remote.original, change.base_commit, change.head_commit
);
println!("| Commit link | Pull Request link | Approvals | Reviewer's verdict |");
println!("|-------------|-------------------|-----------|--------------------|");
change.name, change.remote.original, change.base_commit, change.head_commit,
))?;
println_or_redirect("| Commit link | Pull Request link | Approvals | Reviewer's verdict |".to_string())?;
println_or_redirect("|-------------|-------------------|-----------|--------------------|".to_string())?;
for commit_change in &change.changes {
let mut commit_links: Vec<String> = vec![];
for commit in &commit_change.commits {
Expand All @@ -208,7 +222,7 @@ fn print_changes(repo_changeset: &[RepoChangeset<RealClient>]) -> Result<(), any
}

let pr_link = commit_change.pr_link.clone();
println!(
println_or_redirect(format!(
"| {} | {} | {} | <enter your decision> |",
commit_links.join(" ,<br>"),
match pr_link {
Expand All @@ -226,7 +240,7 @@ fn print_changes(repo_changeset: &[RepoChangeset<RealClient>]) -> Result<(), any
None => String::new(),
},
commit_change.approvals.join(", "),
);
))?;
}
}

Expand Down

0 comments on commit 4b5866e

Please sign in to comment.