Skip to content

Commit

Permalink
fix dry-run option and actions
Browse files Browse the repository at this point in the history
  • Loading branch information
n01e0 committed Dec 29, 2023
1 parent fa80b13 commit 63d2a21
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
24 changes: 22 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,27 @@ inputs:
annotation_labels:
description: 'annotation comment labels'
required: false
default: 'TODO,FIXME'
default: 'TODO:* ,FIXME:* , BUG:* ,HACK:* '
title_format:
description: 'issue title format'
required: false
default: '[Postpone] {label} {line}'
body_format:
description: 'issue body format'
required: false
default: |
This issue was created by Postpone Bot
\{label\}
\{file\}:\{line_number\}
```
\{line\}
```
runs:
using: 'docker'
image: 'ghcr.io/n01e0/ppb:latest'
image: 'docker://ghcr.io/n01e0/ppb:latest'
args:
[
'--organization',
Expand All @@ -29,4 +45,8 @@ runs:
'${{ inputs.token }}',
'--annotation-labels',
'${{ inputs.annotation_labels }}',
'--title-format',
'${{ inputs.title_format }}',
'--body-format',
'${{ inputs.body_format }}',
]
10 changes: 6 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ mod postpone;

use config::{Args, Config};
use postpone::Postpone;
use anyhow::Result;
use anyhow::{Result, Context};
use clap::Parser;

#[tokio::main]
async fn main() -> Result<()> {
let args = Args::parse();
let config = Config::new(&args)?;
let pattern = format!("({})", config.annotation_labels.join("|"));

if args.listup {
let pattern = format!("({})", args.annotation_labels.with_context(|| "listup needs annotation labels")?.join("|"));
let postpones = Postpone::search(&pattern)?;
for postpone in postpones {
println!("{}:{} {}\n\t{}", postpone.file, postpone.line_number, postpone.label, postpone.line);
}
return Ok(());
}
if args.dry_run {
let pattern = format!("({})", args.annotation_labels.with_context(|| "listup needs annotation labels")?.join("|"));
let postpones = Postpone::search(&pattern)?
.into_iter()
.map(|postpone| postpone.to_issue(&config.title_format, &config.body_format))
.map(|postpone| postpone.to_issue(&args.title_format.clone().with_context(|| "dry_run needs title format")?, &args.body_format.clone().with_context(|| "dry_run needs body format")?))
.filter_map(|issue| issue.ok())
.collect::<Vec<(String, String)>>();

Expand All @@ -33,6 +33,8 @@ async fn main() -> Result<()> {
return Ok(());
}

let config = Config::new(&args)?;
let pattern = format!("({})", config.annotation_labels.join("|"));
let client = github::GitHub::new(&config)?;
// Created by ppb, existing Issue
let issues = client.get_issues().await?.into_iter().filter(|issue| {
Expand Down

0 comments on commit 63d2a21

Please sign in to comment.